简体   繁体   English

A *具有敌人意识

[英]A* with enemy awareness

I'm currently dabbling in Java AI programming, and trying an AI challenge. 我目前正在涉足Java AI编程,并尝试AI挑战。 In the challenge, my AI is given 2 seconds to respond to the new game state. 在挑战中,我的AI有2秒的时间来响应新的游戏状态。 If these two seconds are exceeded without producing a response, my AI forfeits. 如果超过这两秒钟而未产生响应,则我的AI会被判罚。 The game consists of a grid with goals and enemies, each enemy being an independent AI generated by the game. 游戏由具有目标和敌人的网格组成,每个敌人都是由游戏生成的独立AI。 I have implemented a standard A* to find the nearest available goal. 我已经实施了标准A *来找到最接近的目标。

I would like my A* algorithm to increase the cost of squares near an enemy that could potentially prove dangerous, thus avoiding dangerous paths. 我希望我的A *算法增加可能被证明具有危险性的敌人附近方格的费用,从而避免出现危险的道路。 I am considering a two-dimensional array containing the estimated loss of health for each square, limited to calculating within ~2 squares of each enemy (~5x5). 我正在考虑一个二维数组,其中包含每个方格的估计健康损失,仅限于在每个敌人的2个方格之内(〜5x5)进行计算。 Each turn, for each enemy this array would have a 5x5 square set to 0 and recalculated. 每回合,对于每个敌人,此阵列将有一个5x5的正方形,设置为0,然后重新计算。

Assuming I write code that only does what it must and moves on... Will a two dimensional array of between 20x20 and 100x100 elements significantly effect execution time? 假设我编写的代码只能执行它必须做的事情并继续前进... 20x20到100x100元素之间的二维数组会明显影响执行时间吗? Is a two dimensional array of estimated threat per square a good method of calculating cost in an A* algorithm so as to avoid enemies? 为避免敌人而采用A *算法计算成本的二维数组是计算成本的一种好方法吗?

UPDATE: I got it working absolutely perfectly. 更新:我绝对可以完美地工作。 The cost function I used: 我使用的成本函数:

For each enemy
    Calculate manhattan distance
    If 0 or 1, cost += absolute(enemy health - health) / 5
    Else if 2, cost += absolute(enemy heath - health) / 10
    Else cost += 0

Using it, I saw some really impressive pathfinding and moves; 使用它,我看到了一些非常令人印象深刻的寻路和动作。 the bot would often take calculated risks where there were no other moves to get to a goal, but basically avoided enemies otherwise. 在没有其他举动达到目标的情况下,机器人通常会冒着一定的风险,但从根本上避免了敌人的攻击。 I was thoroughly impressed with how insignificant the performance cost was of adding the heuristic. 添加启发式算法对性能成本的影响微不足道,这给我留下了深刻的印象。 It's not a perfect solution for the game, but it showed me how robust A* can be. 这不是游戏的完美解决方案,但它向我展示了A *的强大程度。

A* is generally used for pathfinding, but I'm going to modify it for the purpose of a game state lookahead. A *通常用于寻路,但是我将修改它的目的是为了提前了解游戏状态。 I'm pretty sure that turns it into a minimax algorithm. 我很确定这会将其变成minimax算法。

If you are only calculating the content of your array once and the calculation for each cell is something simple like checking a few adjacent cells for enemies then a 100x100 array is no work at all relative to your time constraints. 如果您只计算一次数组的内容,并且每个单元格的计算很简单,例如检查几个相邻的单元格是否有敌人,那么相对于您的时间限制,一个100x100的数组根本没有用。

Given the information in your post it sounds like a good idea to me. 鉴于您发布的信息,对我来说这似乎是个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM