Created
February 21, 2013 21:23
-
-
Save sofoklis/5008374 to your computer and use it in GitHub Desktop.
BFS loop 8-puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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