加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 确定最远点远离其他Point

发布时间:2020-12-15 02:35:50 所属栏目:Java 来源:网络整理
导读:我正在创建一个简单的游戏,在一些游戏计算机引导的玩家上使用一些简单的AI实现. 我有一个Point列表,表示玩家可能的移动.我需要编写一种方法,将玩家移动到距离该列表中可能的敌人最远的点.我用图片说明了这个: 数字代表List中的Points poistion 我想要的是让
我正在创建一个简单的游戏,在一些游戏计算机引导的玩家上使用一些简单的AI实现.

我有一个Point列表,表示玩家可能的移动.我需要编写一种方法,将玩家移动到距离该列表中可能的敌人最远的点.我用图片说明了这个:

数字代表List中的Points poistion

我想要的是让玩家(4)移动到距离任何敌人最远的位置2或6的任一点.如果有一个敌人通过迭代列表并使用Point的distance()方法确定哪个点距离最远,我设法解决了这个问题.但即使网格中有几个敌人,代码也必须正常工作.

解决方法

嗯,你怎么样反过来:

1. Iterate over each point.
2. Find out how close it is to its closest enemy.
3. Choose the point that is furthest from its closest enemy.

提前退出有很多潜力:

Within the loop store the currently furthest point. 
If you are then inspecting another point and find out
it has a closer enemy,you can immediately skip to the
next point

[编辑]:如果你正在使用上面的网格,你也可以

1. Check if there's an enemy on the currently processed 
   point *before* iterating through other enemies. That way
   you can exclude it as early as possible.

2. If it's a densely populated grid,consider doing a breadth-first
   flood-fill starting at the current point. That might find the closest
   enemy much faster than iterating though all of them.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读