class Move { private final Game fGame; private final RobotArm fArm; private final Square fSource; private final Square fTarget; Move(Game game, RobotArm arm, String source, String target) { fGame = game; fArm = arm; fSource = fGame.square(source); fTarget = fGame.square(target); } void run() { // If this is a capture, then the target square may already have a // piece. If so, get that piece out of the way. if (fTarget.fOccupied) { fTarget.pickUp(fArm); fArm.move(fGame.fDiscard); fArm.grip(Game.GRIP_OPEN); } // Make the move. fSource.pickUp(fArm); fTarget.putDown(fArm); // Take care of castling if (fSource.equals("e1")) { if (fTarget.equals("g1")) { // white kingside castle fGame.square("h1").pickUp(fArm); fGame.square("f1").putDown(fArm); } else if(fTarget.equals("c1")) { // white queenside castle fGame.square("a1").pickUp(fArm); fGame.square("d1").putDown(fArm); } } else if (fSource.equals("e8")) { if (fTarget.equals("g8")) { // black kingside castle fGame.square("h8").pickUp(fArm); fGame.square("f8").putDown(fArm); } else if(fTarget.equals("c8")) { // black queenside castle fGame.square("a8").pickUp(fArm); fGame.square("d8").putDown(fArm); } } // Leave the arm in the home position. fArm.move(fGame.fHome); } public String toString() { return ""+fSource+fTarget; } }