Destructible obstacles

I am currently planning a game, but it is difficult for me to determine the algorithm for finding the path, and I was wondering if a generous soul could help me with this.

Here is the scenario, I need an algorithm that calculates whether it would be better to bypass the obstacle or destroy them. I gave "difficulty" to every tile of my game. For example, the base tile is 1, and the obstacle may be between 5-100.

Here are some examples. I have to move from Red Square to Blue Square. If I put an obstacle in the way, I should get something like this:

http://i.imgur.com/UwIQ0IG.jpg

Explanation: The left or right path is only 3 difficulties, and the obstacle is 5. Therefore, it is better to walk.

Second example:

http://i.imgur.com/0is3in9.jpg

Explanation: The algorithm as the 3rd choice is to break an obstacle or walk left or right because it has the same difficulty level.

Last example:

i.imgur.com/sw13exL.jpg

Explanation: The algorithm must be able to find a "weak spot" and be able to go to it and destroy it.

I will continue to work on this. Hope you can give me some advice.

+4
source share
2 answers

You can use Dijkstra's algorithm. To use the algorithm, we define the following graph. Each square will be a node on the graph. Between two adjacent squares we define 2 directed edges. The edge weight will be the number written on the pointed node (for example, for the edge (a, b), the weight will be the number written on square b). Then, having executed Dijkstra’s algorithm on the graph defined above, we will get the shortest path.

+2
source

( , -, ) .

, "" , , (.. "" ).

, , A B,

1 1 A 1 1 1
1 1 1 1 1 1
2 5 5 5 2 1
1 1 B 1 1 1

2 1 A 1 2 3
3 2 1 2 3 4
5 7 6 7 5 5
6 7 B 7 6 6

.

+2

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


All Articles