HTML and CSS Reference
In-Depth Information
A* Taking Diagonal Moves into Account
For Example 8-15 , we will be making changes to Example 8-14 to add in diagonal movement
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
var result = astar . search ( graph . nodes , start , end , true
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
Search WWH ::




Custom Search