HTML and CSS Reference
A* Taking Diagonal Moves into Account
to the A* path.
So far, each of our examples has used the astar.js functions, which ignore diagonal move-
ments between nodes. We can easily add this capability. Example 8-15 does this with one
simple change. We will be changing the false in the A* search function to true :
//For example 8-15 we will add true to the end of the search function
var result = astar . search ( graph . nodes , start , end , true
By simply changing false to true at the end of the call to the astar.search() , we can
change the result node path dramatically. Figure 8-15 shows the path difference.
Figure 8-15. A* applied to the 15x15 tile map with diagonals
Eachnodeonthemovabletileshasthesameweight( 1 ).WhenA*calculatestheshortestnode
path, it does so by taking these weights into account. Next we will add in some nodes with a
higher weight value.
Example 8-15. Larger A* example with diagonals