/** * */ package suicideChess; /** * @author djib * * This file contains the moves representation. * * $LastChangedDate$ * $LastChangedRevision$ * $LastChangedBy$ */ public class Piece { /************* * CONSTANTS * *************/ /** * Take really good care if you want to change those values * Class BitBoard makes intensive use of those */ public static final int NONE=-1; //Contants used to detect color public static final int WHITE=0; public static final int BLACK=1; //Constants used in the board representation public static final int WHITE_PIECE = WHITE; public static final int BLACK_PIECE = BLACK; public static final int PAWN = 2; public static final int WHITE_PAWN = PAWN + WHITE; public static final int BLACK_PAWN = PAWN + BLACK; public static final int KING = 4; public static final int WHITE_KING = KING + WHITE; public static final int BLACK_KING = KING + BLACK; public static final int QUEEN = 6; public static final int WHITE_QUEEN = QUEEN + WHITE; public static final int BLACK_QUEEN = QUEEN + BLACK; public static final int BISHOP = 8; public static final int WHITE_BISHOP = BISHOP + WHITE; public static final int BLACK_BISHOP = BISHOP + BLACK; public static final int KNIGHT = 10; public static final int WHITE_KNIGHT = KNIGHT + WHITE; public static final int BLACK_KNIGHT = KNIGHT + BLACK; public static final int ROOK = 12; public static final int WHITE_ROOK = ROOK + WHITE; public static final int BLACK_ROOK = ROOK + BLACK; //Constants used for promotion (as used in the xboard protocol) public static final char KING_CHAR='k'; public static final char QUEEN_CHAR='q'; public static final char BISHOP_CHAR='b'; public static final char KNIGHT_CHAR='n'; public static final char ROOK_CHAR='r'; //may be useful public static final char PAWN_CHAR='p'; /**************** * PRIVATE DATA * ****************/ private int pieceNumber; /*************** * CONSTRUCTOR * ***************/ public Piece(int piece) { pieceNumber = piece; } public Piece(char piece, int color) { pieceNumber = NONE; switch (piece) { case PAWN_CHAR: pieceNumber = PAWN + color; break; case KING_CHAR: pieceNumber = KING + color; break; case QUEEN_CHAR: pieceNumber = QUEEN + color; break; case BISHOP_CHAR: pieceNumber = BISHOP + color; break; case KNIGHT_CHAR: pieceNumber = KNIGHT + color; break; case ROOK_CHAR: pieceNumber = ROOK + color; break; } } /*********** * METHODS * ***********/ public int getColor() { return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above. } public int getPieceNumber() { return pieceNumber; } }