package suicideChess; import suicideChess.Square.NotAValidSquare; /** * @author djib * * This file contains the moves representation. * * $LastChangedDate$ * $LastChangedRevision$ * $LastChangedBy$ */ public class Move { /******** * DATA * ********/ //integers private Square fromSquare; private Square toSquare; private String promotionPiece; private boolean isPromotion; public class NotAValidMoveException extends Exception { /** * Generated by Eclipse */ private static final long serialVersionUID = 2194133427162274651L; NotAValidMoveException(String s) { super(s); }; } /*************** * CONSTRUCTOR * ***************/ //The string is of type e2e4 (4 chars), b7b8q (5 chars) for promotions public Move(String move) throws NotAValidMoveException, NotAValidSquare { isPromotion = false; promotionPiece = ""; switch (move.length()) { case 5: isPromotion = true; promotionPiece = move.substring(4,5); //no break statement here on purpose case 4: fromSquare = new Square(move.substring(0,2)); toSquare = new Square(move.substring(2,4)); break; default: throw new NotAValidMoveException("Invalid Move: "+move); } } /*********** * METHODS * ***********/ public Square fromSquare() { return fromSquare; } public Square toSquare() { return toSquare; } public boolean isPromotionMove() { return isPromotion; } public String getPromotionPiece() { return promotionPiece; } public void setFromSquare(Square square) { fromSquare = square; } public void setToSquare(Square square) { toSquare = square; } public void setIsPromotionMove(String piece) { if (promotionPiece.length()==0) { isPromotion=false; } else { isPromotion=true; promotionPiece=piece; } } public String toString() { return fromSquare.toString()+toSquare+promotionPiece; } }