public Iterator < Operator < String > > validOperators ( boolean reverse ) { // Used to hold a list of valid moves List < Operator < String >> moves = new ArrayList < Operator < String > > ( 4 ) ; // Check if the up move is valid if ( emptyY != 0 ) { moves . add ( new OperatorImpl < String > ( "U" ) ) ; } // Check if the down move is valid if ( emptyY != 2 ) { moves . add ( new OperatorImpl < String > ( "D" ) ) ; } // Check if the left move is valid if ( emptyX != 0 ) { moves . add ( new OperatorImpl < String > ( "L" ) ) ; } // Check if the right move is valid if ( emptyX != 2 ) { moves . add ( new OperatorImpl < String > ( "R" ) ) ; } return moves . iterator ( ) ; }
Supplies the valid moves for a board position .