Skip to content

Instantly share code, notes, and snippets.

@sofoklis
Created February 21, 2013 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofoklis/5009001 to your computer and use it in GitHub Desktop.
Save sofoklis/5009001 to your computer and use it in GitHub Desktop.
breathFirstSearch
@tailrec
final def breathFirstSearch(queue: List[(State, List[Move])], explored: Set[State], sol: List[(State, List[Move])]): List[(State, List[Move])] =
queue match {
case Nil => sol
case (state, history) :: xs =>
if (!explored(state)) {
breathFirstSearch(xs ++ Move.availableStates(state, moves, history, explored), explored + state, (state, history) :: sol)
} else {
breathFirstSearch(xs, explored, sol)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment