Skip to content

Instantly share code, notes, and snippets.

@sofoklis
Created February 21, 2013 21:38
Show Gist options
  • Save sofoklis/5008493 to your computer and use it in GitHub Desktop.
Save sofoklis/5008493 to your computer and use it in GitHub Desktop.
astar
@tailrec
final def aStarSearch(queue: PriorityQueue[(State, List[Move])], explored: Set[State]): Option[List[Move]] =
if (queue.length == 0) return None
else {
val (state, history) = queue.dequeue
if (state == goalState) Some(history)
else {
if (!explored(state)) {
val children = Move.availableStates(state, moves, history, explored)
queue ++= children
aStarSearch(queue, explored + state)
} else
aStarSearch(queue, explored)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment