Target areas reached by 2d network

Say I have a 2d grid. Pathfinding is a secondary step in my problem.

My thing, say, I have a unit in the middle of the grid. I want to tell the user, "These are all your available destinations."

Depending on how many squares the device can walk, I want to show the user: "These are all the squares that you can reach." and then pathfind the destination that the user selects.

What is the best way to do your first search to show available destinations?

Och bonuses may also be limited in terrain depending on the terrain.

I don’t know what it's called, pointers to where to look or what to do with Google would be greatly appreciated.

Hooray!:)

/ E

+3
source share
3 answers

For each grid point, store:

  • The minimum distance from the device to this point.
  • The next step to the device in the shortest way.

To calculate this, do a width search:

  • Set the unit price of the unit of measurement to 0 and its "path indicator" is not / null.
  • Create a queue and place the starting point in it.
  • While the queue is not empty:
    • Take the next point and distribute it (look at all the neighbors. If it’s profitable to go to them through the current point, set their distance / path and add them to the end of the queue)

Remember to pay to stop the search after the right number of steps if you have a limit.

, , , , ( "" )


! , . ( , A * - , )

+2

, , (http://en.wikipedia.org/wiki/Depth_first_search) , .

+4

Mark the connected cells with the same numbers and are not associated with different ones. You can find a two-pass algorithm for marking cells at http://en.wikipedia.org/wiki/Connected_Component_Labeling . If the cells have a different number, the player cannot reach this location.

+1
source

Source: https://habr.com/ru/post/1790089/


All Articles