public static EightPuzzleState getRandomStartState ( ) { EightPuzzleState newState ; // Turn the goal string into a list of characters. List < Character > charList = stringToCharList ( GOAL_STRING ) ; // Generate random puzzles until a solvable one is found. do { // Shuffle the list. Collections . shuffle ( charList ) ; // Turn the shuffled list into a proper eight puzzle state object. newState = charListToState ( charList ) ; // Check that the puzzle is solvable and if not then repeat the shuffling process. } while ( ! isSolvable ( newState ) ) ; return newState ; }
Generates a random starting position .