# Dijkstra's Algorithm and Turn Based Strategy

Get help using Construct 2

### » Tue Apr 30, 2013 10:50 am

Hi all,

I've been playing around with c2 for a few weeks now and would like to attempt making a turn based strategy.

Thats a bit broad so let me narrow it down. A turn based strategy similar to Advance Wars takes into account immovable terrain and terrian with varying cost.

I've been told in order to workout how far a unit/character can move on a square grid based map with terrain penalties I would need to use Dijkstra's Algorithm.

I'm scratching my head at how to implement this as I'm finding it difficult to understand the psuedo code.

http://www.cprogramming.com/tutorial/computersciencetheory/dijkstra.html

Can someone help explain this to me or point me at a simpler psuedo code for Dijkstra's Algorithm.
B
6
S
1
Posts: 19
Reputation: 544

### » Tue Apr 30, 2013 12:10 pm

You could use built-in pathfinding behavior, I recall they added features to support movement cost.
B
24
S
9
G
7
Posts: 756
Reputation: 7,352

### » Tue Apr 30, 2013 12:55 pm

[QUOTE=vee41] You could use built-in pathfinding behavior, I recall they added features to support movement cost.[/QUOTE]

I've had a look at the pathfinding demo and it's not quite what I'm after. It seems that they create an event based on overlapping with an obstacle sprite and then reduce the maximum speed of the moving unit. The path cost feature seems to encourage a path to be avoided rather than making the path not possible. Also it seems to cut corners even with diagonals disabled.

Can I restrict the pathfinding movement to move in only 90 degree angles and not allow movement to a destination if the path cost value exceeds a threshold?Harlequin2013-04-30 12:59:44
B
6
S
1
Posts: 19
Reputation: 544

### » Thu Aug 20, 2015 10:05 pm

"Can I restrict the pathfinding movement to move in only 90 degree angles and not allow movement to a destination if the path cost value exceeds a threshold?" > Any answer for that? I am making a game like Shining Force 2 and my characters need to not cut corners. I also need straight angles.
B
13
S
7
G
1
Posts: 18
Reputation: 1,715

### » Fri Aug 21, 2015 1:20 am

@Harlequin

check out this thread from yesterday: https://www.scirra.com/forum/how-do-i-do-custom-pathfinder-for-hex-maps_t152368

R0J0hound wrote an outstanding example of how to implement the A* algorithm - which is similar to Dijkstra's Algorithm
B
99
S
35
G
20
Posts: 438
Reputation: 17,970

### » Fri Aug 21, 2015 6:24 am

This example here is applicable, although I forget if varying costs is implemented in it.
sequential-grid-span-class-posthilit-based-span-movement_p695580?#p695580
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520