Skip to content

Commit 422ff11

Browse files
committed
Make octile heuristic the default for diagonal movement
The same change as the last commit for BiAStar and IDAStart finders
1 parent 83d25e8 commit 422ff11

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/finders/BiAStarFinder.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ function BiAStarFinder(opt) {
3535
}
3636
}
3737
}
38+
39+
//When diagonal movement is allowed the manhattan heuristic is not admissible
40+
//It should be octile instead
41+
if (this.diagonalMovement === DiagonalMovement.Never) {
42+
this.heuristic = opt.heuristic || Heuristic.manhattan;
43+
} else {
44+
this.heuristic = opt.heuristic || Heuristic.octile;
45+
}
3846
}
3947

4048
/**

src/finders/IDAStarFinder.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ function IDAStarFinder(opt) {
5050
}
5151
}
5252
}
53+
54+
//When diagonal movement is allowed the manhattan heuristic is not admissible
55+
//It should be octile instead
56+
if (this.diagonalMovement === DiagonalMovement.Never) {
57+
this.heuristic = opt.heuristic || Heuristic.manhattan;
58+
} else {
59+
this.heuristic = opt.heuristic || Heuristic.octile;
60+
}
5361
}
5462

5563
/**

0 commit comments

Comments
 (0)