private static EightPuzzleState charListToState ( List < Character > charList ) { // Create a new empty puzzle state EightPuzzleState newState = new EightPuzzleState ( ) ; // Loop over the board inserting the characters into it from the character list Iterator < Character > k = charList . iterator ( ) ; for ( int j = 0 ; j < 3 ; j ++ ) { for ( int i = 0 ; i < 3 ; i ++ ) { char nextChar = k . next ( ) ; // Check if this is the empty tile and if so then take note of its position if ( nextChar == ' ' ) { newState . emptyX = i ; newState . emptyY = j ; } newState . board [ j ] [ i ] = nextChar ; } } return newState ; }
Turns a list of characters representation of the board into a proper state .