Testing and debugging of the rules :
by typing "hint a3" it is possible to know all the possible moves for the piece on a3. (Pawn and Queen not implemented yet)
This commit is contained in:
@ -160,6 +160,17 @@ public class Board {
|
||||
return new Piece(Piece.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function converts a {@link Square} to a number representing a bitboard square
|
||||
* @param square The Square to be converted
|
||||
* @return int
|
||||
* @see Square
|
||||
*/
|
||||
public static int squareToBitBoardSquare(Square square) {
|
||||
//converts a square ("e2") to a BitboardSquare (
|
||||
return square.getFileNb() -1 + (square.getRank()-1)*NB_OF_FILES;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function can be used to display the board
|
||||
@ -228,7 +239,7 @@ public class Board {
|
||||
}
|
||||
System.out.println("+---+---+---+---+---+---+---+---+");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*=================*
|
||||
* PRIVATE METHODS *
|
||||
@ -239,13 +250,7 @@ public class Board {
|
||||
return bitBoards[bitboard_number];
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
private int squareToBitBoardSquare(Square square) {
|
||||
//converts a square ("e2") to a BitboardSquare (
|
||||
return square.getFileNb() -1 + (square.getRank()-1)*NB_OF_FILES;
|
||||
}
|
||||
|
||||
|
||||
protected void addPiece(Square square, Piece piece) {
|
||||
//OR :
|
||||
// 0 OR a = a
|
||||
|
@ -78,6 +78,42 @@ public class Move {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the constructor of the class.
|
||||
*
|
||||
* @param fromSquare The {@link Square} to move from.
|
||||
* @param toSquare The {@link Square} to move to.
|
||||
* @param movingPiece The {@link Piece} to be moved.
|
||||
* @param capturePiece The {@link Piece} to be captured. Piece.NONE if none.
|
||||
* @param promotionPiece The {link Piece} to be promoted to. Piece.NONE if none.
|
||||
* @throws NotAValidSquare If Squares are not valid.
|
||||
* @see Square
|
||||
* @see Piece
|
||||
*/
|
||||
public Move(Square fromSquare, Square toSquare, Piece movingPiece, Piece capturePiece, Piece promotionPiece)
|
||||
throws NotAValidSquare {
|
||||
|
||||
this.fromSquare = fromSquare;
|
||||
this.toSquare = toSquare;
|
||||
|
||||
this.movingPiece = movingPiece;
|
||||
|
||||
this.capturePiece = capturePiece;
|
||||
if (capturePiece.getPieceNumber()!=Piece.NONE) {
|
||||
isCapture = true;
|
||||
} else {
|
||||
isCapture = false;
|
||||
}
|
||||
|
||||
this.promotionPiece = promotionPiece;
|
||||
if (promotionPiece.getPieceNumber()!=Piece.NONE) {
|
||||
isPromotion = true;
|
||||
} else {
|
||||
isPromotion = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*===========================================*
|
||||
* Those two constructors are no longer used *
|
||||
|
@ -21,6 +21,7 @@ public class Piece {
|
||||
* Class BitBoard makes intensive use of those
|
||||
*/
|
||||
public static final int NONE=-1;
|
||||
public static final int NO_COLOR = -1;
|
||||
//Contants used to detect color
|
||||
public static final int WHITE=0;
|
||||
public static final int BLACK=1;
|
||||
@ -116,14 +117,25 @@ public class Piece {
|
||||
* @return An integer.
|
||||
*/
|
||||
public int getColor() {
|
||||
return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above.
|
||||
if (pieceNumber!=Piece.NONE) {
|
||||
return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above.
|
||||
} else {
|
||||
return Piece.NO_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an integer representing the Piece
|
||||
* Returns an integer representing the Piece (Piece.BLACK_PAWN or Piece.WHITE_QUEEN)
|
||||
* @return An integer.
|
||||
*/
|
||||
public int getPieceNumber() {
|
||||
return pieceNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an integer representing the Piece type (Piece.QUEEN or Piece.PAWN)
|
||||
*/
|
||||
public int getPieceType() {
|
||||
return ((pieceNumber/2)-1);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -47,6 +47,20 @@ public class Square {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construcs a Square given a bitboard square (number from 0 to 63)
|
||||
* @param bitboardSquare An integer representing the bitboard square
|
||||
* @see Board
|
||||
*/
|
||||
public Square(int bitboardSquare) throws NotAValidSquare {
|
||||
if ((bitboardSquare < 0) || (bitboardSquare >= Board.NB_OF_SQUARES)) {
|
||||
throw new NotAValidSquare(Integer.toString(bitboardSquare));
|
||||
}
|
||||
fileNb = bitboardSquare%Board.NB_OF_FILES + 1;
|
||||
file = (char)(fileNb + ((int)'a') - 1);
|
||||
rank = bitboardSquare/Board.NB_OF_FILES + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file of a Square.
|
||||
* @return char representing the file
|
||||
|
@ -2,6 +2,7 @@ package suicideChess;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import suicideChess.Move.NotAValidMoveException;
|
||||
import suicideChess.Square.NotAValidSquare;
|
||||
@ -46,6 +47,7 @@ public class SuicideChess {
|
||||
/*int playerColor = Piece.WHITE;
|
||||
System.out.println("White: ");*/
|
||||
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
String whatMove= moveInput.readLine();
|
||||
@ -55,6 +57,23 @@ public class SuicideChess {
|
||||
break;
|
||||
}
|
||||
|
||||
if (whatMove.startsWith("move")) {
|
||||
Move move = new Move(new Square(0), new Square(1), new Piece(2), new Piece(3), new Piece(Piece.NONE));
|
||||
move.display();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (whatMove.startsWith("hint")) {
|
||||
Rules rules = new Rules();
|
||||
ArrayList<Move> allLegalMoves =
|
||||
rules.legalMovesFromSquare(new Square(whatMove.substring(5,7)),bitboard);
|
||||
for(int i = 0; i<allLegalMoves.size(); i++) {
|
||||
allLegalMoves.get(i).display();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Move theMove = new Move(whatMove, bitboard);
|
||||
|
||||
theMove.display();
|
||||
|
Reference in New Issue
Block a user