Skip to content

Commit

Permalink
[#69] Fix goal check in A*
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed May 29, 2020
1 parent 6858613 commit 8bf19f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/ai/pathfinding/AStar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class AStar<T> {
return GoalAlreadyReached
} else if (graph.isValid(goal)) {
isAnyGoalReachable = true
}

val goalNode = AStarNode(goal)
goalNode.costSoFar = 0
openNodes.add(goalNode)
list[goal] = goalNode
val goalNode = AStarNode(goal)
goalNode.costSoFar = 0
openNodes.add(goalNode)
list[goal] = goalNode
}
}

if (!isAnyGoalReachable) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/ai/pathfinding/AStarTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ class AStarTest {

@Test
fun `1 of 2 goals is an obstacle`() {
val values = listOf(f, f, o)
val graph = OccupancyMap(Chebyshev, values, Size(3, 1))
val values = listOf(f, f, f, o)
val graph = OccupancyMap(Chebyshev, values, Size(4, 1))

val aStar = AStar<Boolean>()

assertThat(aStar.find(graph, 1, setOf(0, 2), 3)).isEqualTo(
assertThat(aStar.find(graph, 2, setOf(0, 3), 3)).isEqualTo(
Path(
size = 3,
totalCost = 1,
indices = listOf(0)
totalCost = 2,
indices = listOf(1, 0)
)
)
}
Expand Down

0 comments on commit 8bf19f9

Please sign in to comment.