Perfecting comments to be able to create a javadoc.

This commit is contained in:
2006-01-10 15:39:55 +00:00
parent 5373eaf0aa
commit d2c08d60c5
5 changed files with 186 additions and 80 deletions

View File

@ -3,25 +3,23 @@ package suicideChess;
import suicideChess.Square.NotAValidSquare; import suicideChess.Square.NotAValidSquare;
/** /**
* @author djib * This class contains the board representation.
*
* This file contains the board representation.
* The board is represented using bitboards. * The board is represented using bitboards.
* a1 is square 0 * <ul><li>a1 is square 0</li>
* h8 is square 7 * <li>h8 is square 7</li>
* a2 is square 8 * <li>a2 is square 8</li>
* ... and so on * <li>... and so on</li>
*
* @author Jean-Baptiste H&eacute;tier
* @version $LastChangedRevision$, $LastChangedDate$
* *
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/ */
public class Board { public class Board {
/************* /*===========*
* CONSTANTS * * CONSTANTS *
*************/ *===========*/
//Some constants to make code more readable //Some constants to make code more readable
public static final int NB_OF_RANKS = 8; public static final int NB_OF_RANKS = 8;
@ -31,7 +29,7 @@ public class Board {
private static final int NB_OF_BITBOARDS = 14; private static final int NB_OF_BITBOARDS = 14;
public class NoPieceOnSquare extends Exception { public class NoPieceOnSquare extends Exception {
/** /*
* Added by Eclipse * Added by Eclipse
*/ */
private static final long serialVersionUID = -2750943856086117656L; private static final long serialVersionUID = -2750943856086117656L;
@ -40,9 +38,9 @@ public class Board {
} }
/******** /*======*
* DATA * * DATA *
********/ *======*/
//The following table is used to map squares to bits //The following table is used to map squares to bits
protected static long mapSquaresToBits[]; protected static long mapSquaresToBits[];
@ -58,10 +56,17 @@ public class Board {
//The following table contains all the bit boards //The following table contains all the bit boards
protected long bitBoards[]; protected long bitBoards[];
/***************
/*=============*
* CONSTRUCTOR * * CONSTRUCTOR *
* @throws NotAValidSquare *=============*/
***************/
/**
* Constructor of the class Board
* @throws NotAValidSquare
*/
public Board() throws NotAValidSquare { public Board() throws NotAValidSquare {
bitBoards = new long[NB_OF_BITBOARDS]; bitBoards = new long[NB_OF_BITBOARDS];
@ -104,9 +109,16 @@ public class Board {
} }
/****************** /*================*
* PUBLIC METHODS * * PUBLIC METHODS *
******************/ *================*/
/**
* This methods takes a {@link Move} and applies it (updating the bitboard)
* @param move The move that is to be done
* @throws NoPieceOnSquare If a piece is trying to be moved from a square that does not exist.
* @see Move
*/
public void doMove(Move move) throws NoPieceOnSquare { public void doMove(Move move) throws NoPieceOnSquare {
if (move.isCaptureMove()) { if (move.isCaptureMove()) {
@ -120,7 +132,13 @@ public class Board {
} }
} }
//this function searchs for what piece is on a square /**
* This function searchs for what piece is on a square.
* @param onSquare The Square on which we will look for a piece.
* @return a {@link Piece}
* @see Square
* @see Piece
*/
public Piece getPiece(Square onSquare) { public Piece getPiece(Square onSquare) {
//if there is a corresponding white piece. //if there is a corresponding white piece.
if (!isEmpty(onSquare, new Piece(Piece.WHITE_PIECES))) { if (!isEmpty(onSquare, new Piece(Piece.WHITE_PIECES))) {
@ -143,7 +161,10 @@ public class Board {
} }
//this function can be used to display the board /**
* This function can be used to display the board
* Black pieces are displayed in uppercase letters.
*/
public void display(){ public void display(){
for (int file = NB_OF_FILES; file >= 1; file--) { for (int file = NB_OF_FILES; file >= 1; file--) {
System.out.println("+---+---+---+---+---+---+---+---+"); System.out.println("+---+---+---+---+---+---+---+---+");
@ -209,9 +230,9 @@ public class Board {
} }
/******************* /*=================*
* PRIVATE METHODS * * PRIVATE METHODS *
*******************/ *=================*/
/* private long getBitBoard(int bitboard_number) { /* private long getBitBoard(int bitboard_number) {

View File

@ -3,20 +3,17 @@ package suicideChess;
import suicideChess.Square.NotAValidSquare; import suicideChess.Square.NotAValidSquare;
/** /**
* @author djib * This class is used for moves representation.
* *
* This file contains the moves representation. * @author Jean-Baptiste H&eacute;tier
* * @version $LastChangedRevision$, $LastChangedDate$
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/ */
public class Move { public class Move {
/******** /*======*
* DATA * * DATA *
********/ *======*/
//integers //integers
private Piece movingPiece; private Piece movingPiece;
@ -38,11 +35,20 @@ public class Move {
NotAValidMoveException(String s) { super(s); }; NotAValidMoveException(String s) { super(s); };
} }
/*************** /*=============*
* CONSTRUCTOR * * CONSTRUCTOR *
***************/ *=============*/
//The string is of type e2e4 (4 chars), b7b8q (5 chars) for promotions /**
* This is the constructor of the class.
*
* @param move A String containing of type "e2e4" (4 chars), "b7b8q" (5 chars) for promotions.
* It is the standard algebraic notation used for chess.
* @param board A {@link Board} to be able to locate the pieces.
* @throws NotAValidMoveException When the String is not legal (too long or too short).
* @throws NotAValidSquare It the String is not legal (not standard algebraic notation).
* @see Board
*/
public Move(String move, Board board) throws NotAValidMoveException, NotAValidSquare { public Move(String move, Board board) throws NotAValidMoveException, NotAValidSquare {
isPromotion = false; isPromotion = false;
@ -73,9 +79,9 @@ public class Move {
} }
/********************************************* /*===========================================*
* Those two constructors are no longer used * * Those two constructors are no longer used *
*********************************************/ *===========================================*/
/* /*
//non capture move //non capture move
public Move(String move, Piece pieceToMove) throws NotAValidMoveException, NotAValidSquare { public Move(String move, Piece pieceToMove) throws NotAValidMoveException, NotAValidSquare {
@ -121,19 +127,41 @@ public class Move {
*/ */
/*********** /*=========*
* METHODS * * METHODS *
***********/ *=========*/
/**
* Returns the {@link Square} to move from in a Move
* @return Square
* @see Square
*/
public Square fromSquare() { public Square fromSquare() {
return fromSquare; return fromSquare;
} }
/**
* Returns the {@link Square} to move to in a Move
* @return Square
* @see Square
*/
public Square toSquare() { public Square toSquare() {
return toSquare; return toSquare;
} }
/**
* Returns a boolean saying if a Move is a promotion or not.
* @return boolean
*/
public boolean isPromotionMove() { public boolean isPromotionMove() {
return isPromotion; return isPromotion;
} }
/**
* Returns the promotion {@link Piece} of a Move
* @return Piece
* @see Piece
*/
public Piece getPromotionPiece() { public Piece getPromotionPiece() {
if (isPromotion) { if (isPromotion) {
return promotionPiece; return promotionPiece;
@ -142,23 +170,42 @@ public class Move {
} }
} }
/**
* Returns the moving {@link piece} of a Move.
* @return Piece
* @see Piece
*/
public Piece getMovingPiece() { public Piece getMovingPiece() {
return movingPiece; return movingPiece;
} }
/**
* Returns a boolean saying if a Move is a capture move
* @return boolean
*/
public boolean isCaptureMove() { public boolean isCaptureMove() {
return isCapture; return isCapture;
} }
/**
* Returns the {@link Piece} to be captured in a Move
* @return Piece
*/
public Piece getCapturedPiece() { public Piece getCapturedPiece() {
return capturePiece; return capturePiece;
} }
/**
* Converts a Move into a String.
* @return String
*/
public String toString() { public String toString() {
return fromSquare.toString()+toSquare+promotionPiece; return fromSquare.toString()+toSquare+promotionPiece;
} }
//Used for debugging mainly /**
* Displays a move in great details.
*/
public void display() { public void display() {
System.out.println(" "); System.out.println(" ");
System.out.println("==== Move ===="); System.out.println("==== Move ====");
@ -173,9 +220,9 @@ public class Move {
} }
/**************************************** /*======================================*
* I do not use those functions anymore * * I do not use those functions anymore *
**************************************** *======================================*
public void setFromSquare(Square square) { public void setFromSquare(Square square) {
fromSquare = square; fromSquare = square;

View File

@ -4,22 +4,19 @@
package suicideChess; package suicideChess;
/** /**
* @author djib * This class is used for piece representation.
* *
* This file contains the moves representation. * @author Jean-Baptiste H&eacute;tier
* * @version $LastChangedRevision$, $LastChangedDate$
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/ */
public class Piece { public class Piece {
/************* /*===========*
* CONSTANTS * * CONSTANTS *
*************/ *===========*/
/** /*
* Take really good care if you want to change those values * Take really good care if you want to change those values
* Class BitBoard makes intensive use of those * Class BitBoard makes intensive use of those
*/ */
@ -59,20 +56,31 @@ public class Piece {
//may be useful //may be useful
public static final char PAWN_CHAR='p'; public static final char PAWN_CHAR='p';
/**************** /*==============*
* PRIVATE DATA * * PRIVATE DATA *
****************/ *==============*/
private int pieceNumber; private int pieceNumber;
/*************** /*=============*
* CONSTRUCTOR * * CONSTRUCTOR *
***************/ *=============*/
/**
* Construcs a Piece given a piece number. You should use the constants
* declared in this class.
* @param piece An integer corresponding to a Piece code.
*/
public Piece(int piece) { public Piece(int piece) {
pieceNumber = piece; pieceNumber = piece;
} }
/**
* Construcs a Piece given its color and its standard algebaic name
* (declared as constants in this file)
* @param piece A character used to represent the Piece.
* @param color The color of the piece. (See declared constants)
*/
public Piece(char piece, int color) { public Piece(char piece, int color) {
pieceNumber = NONE; pieceNumber = NONE;
switch (piece) { switch (piece) {
@ -97,14 +105,22 @@ public class Piece {
} }
} }
/*********** /*=========*
* METHODS * * METHODS *
***********/ *=========*/
/**
* Returns an integer representing the color of the Piece.
* @return An integer.
*/
public int getColor() { public int getColor() {
return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above. return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above.
} }
/**
* Returns an integer representing the Piece
* @return An integer.
*/
public int getPieceNumber() { public int getPieceNumber() {
return pieceNumber; return pieceNumber;
} }

View File

@ -1,13 +1,10 @@
package suicideChess; package suicideChess;
/** /**
* @author djib * This class is used for square representation
* *
* This class avoids the use of strings for squares * @author Jean-Baptiste H&eacute;tier
* * @version $LastChangedRevision$, $LastChangedDate$
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/ */
@ -25,6 +22,11 @@ public class Square {
NotAValidSquare(String s) { super(s); }; NotAValidSquare(String s) { super(s); };
} }
/**
* Construcs a Square given a String ("a1", "b7", "g5", ...)
* @param square A string representing the Square.
*/
public Square(String square) throws NotAValidSquare { public Square(String square) throws NotAValidSquare {
if (square.length()!=2 || !(Character.isLetter(square.toCharArray()[0])) || if (square.length()!=2 || !(Character.isLetter(square.toCharArray()[0])) ||
!(Character.isDigit(square.toCharArray()[1]))) { !(Character.isDigit(square.toCharArray()[1]))) {
@ -45,16 +47,35 @@ public class Square {
} }
} }
/**
* Returns the file of a Square.
* @return char representing the file
*/
public char getFile() { public char getFile() {
return file; return file;
} }
/**
* Returns the number of the Rank
* @return int representing the rank
*/
public int getRank() { public int getRank() {
return rank; return rank;
} }
/**
* Returns the number of the File
* @return int representing the file
*/
public int getFileNb() { public int getFileNb() {
return fileNb; return fileNb;
} }
/**
* Converts a Square back to a String
* @return String
*/
public String toString() { public String toString() {
return String.valueOf(file)+String.valueOf(rank); return String.valueOf(file)+String.valueOf(rank);
} }

View File

@ -7,33 +7,34 @@ import suicideChess.Move.NotAValidMoveException;
import suicideChess.Square.NotAValidSquare; import suicideChess.Square.NotAValidSquare;
/** /**
* @author djib * Main file (the game in itself)
* * @author Jean-Baptiste H&eacute;tier
* Main File * @version $LastChangedRevision$, $LastChangedDate$
*
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/ */
public class SuicideChess { public class SuicideChess {
/** /*
* Those flags are used to perform extra checks during the debugging of the * Those flags are used to perform extra checks during the debugging of the
* program. They may be safely all set to false once the program is stable. * program. They may be safely all set to false once the program is stable.
* It should improve performance a lot. * It should improve performance a lot.
*/ */
//does BitBoard.class removePiece function checks if removing piece is legal ? /**
* does BitBoard.class removePiece function checks if removing piece is legal ?
*/
public static final boolean BITBOARD_REMOVEPIECE_CHECK_REMOVE = true; public static final boolean BITBOARD_REMOVEPIECE_CHECK_REMOVE = true;
//does Square.class checks if the strings are valid (is "z9" a valid square ? /**
* does Square.class checks if the strings are valid (is "z9" a valid square ?
*/
public static final boolean SQUARE_CHECK_INVALID = true; public static final boolean SQUARE_CHECK_INVALID = true;
private static final int MAIN_VERSION_NUMBER = 0;
private static final int REVISION_NUMBER = 15;
public static final int MAIN_VERSION_NUMBER = 0; /**
public static final int REVISION_NUMBER = 15; * The main function
* @param args No parameters should be transmitted to this function.
/***************** */
* MAIN FUNCTION *
*****************/
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Welcome to SuicideChess v"+MAIN_VERSION_NUMBER+"."+REVISION_NUMBER+"!"); System.out.println("Welcome to SuicideChess v"+MAIN_VERSION_NUMBER+"."+REVISION_NUMBER+"!");
BufferedReader moveInput = new BufferedReader(new InputStreamReader(System.in)); BufferedReader moveInput = new BufferedReader(new InputStreamReader(System.in));