用于在2D网格游戏板上找到移动攻击区域内攻击目标的空间的算法 [英] Algorithm for finding spaces to attack target within move-attack area on a 2D grid game board
问题描述
我正在寻找一个算法名称或实现,可以从我可以攻击给定目标的有效移动列表中给出有效位置。
我有一个2D瓦片地图和一个英雄可以移动一定数量的动作,并在范围内攻击敌人。由于地图上的障碍,英雄的移动区域各不相同,可能会有漏洞:
在这个问题中,我学到了
)如果(距离<=攻击范围)AND square在有效移动之内,Hero可以从该方块攻击目标。
在我特定的情况下,我允许近战英雄攻击他们周围的所有8个方格(连接8),所以他们的行为像国际象棋,而不是曼哈顿距离将计算 Chebushev距离
中查找要攻击目标的单元格
I'm looking for an algorithm name or implementation that can give me valid positions from a list of valid moves from which I can attack a given target.
I have a 2D tile map and a hero who can move a certain number of moves and attack enemy at range. Because of obstacles on the map, hero's move area varies and can have holes in it:
In this question I have learned how to combine this move area with attack area to get the total "threat" range that my hero exerts on the game board. In this case, 2 enemies are within threat range and can be attacked:
I'm looking for a name or info on a generalized algorithm that will take :
- Threat area (yellow)
- Valid moves (orange)
- Target position (green)
And return all cells within orange area from which I can attack a given target. Because enemies exert a threat area of their own, I do not necessarily need the closest square - I will examine possible moves and pick the one with the least threat for my hero to move to for attacking.
Here's how I think the problem can be solved:
1) Find Hero's threat (move+attack squares)
For each target within threat area do following:
2) For each square in valid moves, calculate Manhattan distance to a particular target
3) If the (distance <= attack range) AND square is within valid moves, Hero can attack target from that square
In my particular case, I allow melee heroes to attack all 8 squares around them (connexity 8), so they will behave like a king in chess and instead of manhattan distance will calculate Chebushev distance
这篇关于用于在2D网格游戏板上找到移动攻击区域内攻击目标的空间的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!