Marque los campos donde la unidad puede ir usando A*

I'm using A* algorithm for finding the shortest way on a hexagon map. But before I implemented the A* algorithm I used esta versión. (click on the unit)

To finding the shortest place I'm already using A* and now I want to use A* for marking the fields where the unit may go. Now I use for it this function: Here (line 58).

And my question is what is the best way how to use A* for this problem? Must I find the shortest way to each field and get the way length and then compare the length with the unit's movement? This solution isn't nice and it is very slow...

Have you any idea for some better solution?

preguntado el 22 de mayo de 12 a las 19:05

1 Respuestas

I have a similar problem for a battletech-like game.

What I've done is to perform an A*, but I stop only when the 'open' list is empty (all hex have been reached), or when the lowest value in this list is infinity (ie hex are unreacheables). This is like not having a 'destination' hex. With this solution, you pass on each hex only one time (when its the lowest value in the open map).

Then you can do two things with the calculeted hex (closed list)

  • remove all hex whose value (in your case, length) is greater than movement. This leave only hex where your unit can go

  • keep these hex, but display the hexes with different color, depending on the length. fort example a color depending on the number of turn to get there (this number of turn beeing (length-1)%movement). This is useful for the player, as he can now see the fastest path to any (reachable) hex on the map for the current unit

Another possibility is to stop searching the open list when the minimal value is greater than the movement (ie you can not go there in one turn). This will limit the number of hex you use in the search.

saludos

Respondido 30 ago 12, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.