public boolean move ( int pinA , int pinB ) { // Nothing to do if the pin number is invalid if ( pinA < 0 || pinA >= pins . length || pinB < 0 || pinB >= pins . length ) { Log . warn ( "Invalid board pin specified " + pinA + ". Should be between 0.." + ( pins . length - 1 ) + " (inclusive)." ) ; return false ; } else if ( pins [ pinA ] . isEmpty ( ) ) { Log . warn ( "No disc on pin" + pinA ) ; return false ; } else if ( pinA == pinB ) { Log . info ( "Moving disc from pin" + pinA + " on to itself (means the board will not change)" ) ; return true ; } int discOnA = pins [ pinA ] . get ( pins [ pinA ] . size ( ) - 1 ) ; int discOnB = ( pins [ pinB ] . isEmpty ( ) ) ? Integer . MAX_VALUE : pins [ pinB ] . get ( pins [ pinB ] . size ( ) - 1 ) ; if ( discOnB < discOnA ) { Log . warn ( "Cannot move disc" + discOnA + " (pin" + pinA + ") on to smaller disc" + discOnB + " (pin" + pinB + ")" ) ; return false ; } pins [ pinB ] . add ( pins [ pinA ] . remove ( pins [ pinA ] . size ( ) - 1 ) ) ; return true ; }
Move a disc from pin A to pin B .