如何在网格中导航寻找最接近的位置?

发布于 2024-12-09 11:28:56 字数 550 浏览 1 评论 0原文

我有一个网格,其声明如下:

PlayerStatus enum
{
  OCCUPIED,
  VACANT
}

PlayerStatus[][] grid_ = new PlayerStatus[200][200];

网格设置为等于除玩家所在位置之外的所有空白网格。

我想要一种方法来告诉我一个玩家是否在另一个玩家的某个网格附近,例如:

boolean inRange(int x, int y, int range)
{
  //This method finds if a player is close to another one
}

所以如果我传入 inRange(10, 15, 5) 并在 10, 19 有一个玩家我希望该方法返回 true;其中 10, 21 将返回 false。

是否有任何算法可以进行此类搜索,我可以研究一下?或者有人有什么解决办法吗?我觉得计算对角线之类的会比较困难,我该怎么办?任何帮助表示赞赏。

I have a grid that is declared like:

PlayerStatus enum
{
  OCCUPIED,
  VACANT
}

PlayerStatus[][] grid_ = new PlayerStatus[200][200];

The grid is set equal to all vacant except where players located at.

I would like to have a method that tells me if a player is in a certain grid proximity of another player, something like:

boolean inRange(int x, int y, int range)
{
  //This method finds if a player is close to another one
}

So if I pass into inRange(10, 15, 5) and at 10, 19 there is a player I would like the method to return true; where as 10, 21 would return false.

Are there any algorithms that do this kind of searching that I could look into? Or does anyone have any solutions? I feel that calculating diagonals and such will be rather hard, what should I do for that? Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烧了回忆取暖 2024-12-16 11:28:56

数学.hypot() 是实现毕达哥拉斯理论的不错选择定理。这里有一个名为 norm() 的示例,在此 KineticModel

Math.hypot() is a good choice for implementing the Pythagorean theorem. There's an example here named norm(), which is used in this KineticModel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文