Browse Source

Version 1.0.3

=============
Corrected a bug in the principal variation first search
master
djib 15 years ago
parent
commit
f9ff33b2b3
  1. 53
      src/suicideChess/Board.java
  2. 12
      src/suicideChess/ComputerPlayer.java
  3. 34
      src/suicideChess/Move.java
  4. 2
      src/suicideChess/Rules.java
  5. 23
      src/suicideChess/SuicideChess.java

53
src/suicideChess/Board.java

@ -81,8 +81,7 @@ public class Board {
}
//The following table contains all the bit boards
protected long bitBoards[];
protected long bitBoards[];
private boolean enPassant=false; //is there an 'en passant pawn' on the board
private Square enPassantSquare;
@ -632,10 +631,16 @@ public class Board {
//update the board value : remove the value of the square the piece comes from and add the value
//of the square the piece goes to
pieceValue += (
ConfigFile.getSquareWeightMidgame()[squareToBitBoardSquare(move.toSquare())]
- ConfigFile.getSquareWeightMidgame()[squareToBitBoardSquare(move.fromSquare())]
)*ConfigFile.getPieceValuesMidgame()[move.getMovingPiece().getPieceNumber()];
if (move.isPromotionMove()){
pieceValue += ConfigFile.getSquareWeightMidgame()[squareToBitBoardSquare(move.toSquare())]
*ConfigFile.getPieceValuesMidgame()[move.getPromotionPiece().getPieceNumber()];
} else {
pieceValue += ConfigFile.getSquareWeightMidgame()[squareToBitBoardSquare(move.toSquare())]
*ConfigFile.getPieceValuesMidgame()[move.getMovingPiece().getPieceNumber()];
}
pieceValue -= ConfigFile.getSquareWeightMidgame()[squareToBitBoardSquare(move.fromSquare())]
*ConfigFile.getPieceValuesMidgame()[move.getMovingPiece().getPieceNumber()];
//if there is a capture also remove the value of the sqare the piece was captured
if (move.isCaptureMove()) {
if (move.isEnPassant()) {
@ -667,10 +672,15 @@ public class Board {
}
}*/
pieceValue += (
ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.toSquare())]
- ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.fromSquare())]
)*ConfigFile.getPieceValuesEndgame()[move.getMovingPiece().getPieceNumber()];
if (move.isPromotionMove()){
pieceValue += ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.toSquare())]
*ConfigFile.getPieceValuesEndgame()[move.getPromotionPiece().getPieceNumber()];
} else {
pieceValue += ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.toSquare())]
*ConfigFile.getPieceValuesEndgame()[move.getMovingPiece().getPieceNumber()];
}
pieceValue -= ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.fromSquare())]
*ConfigFile.getPieceValuesEndgame()[move.getMovingPiece().getPieceNumber()];
if (move.isCaptureMove()) {
if (move.isEnPassant()) {
pieceValue -= ConfigFile.getSquareWeightEndgame()[squareToBitBoardSquare(move.getEnPassantSquare())]
@ -694,4 +704,27 @@ public class Board {
}
}
}
/**
* displays debug information
*/
public void debug(){
for(int i = 0; i<NB_OF_BITBOARDS; i++) {
String result="";
for (int j=0; j<NB_OF_SQUARES; j++) {
if((mapSquaresToBits[j] & bitBoards[i]) != 0) {
result += "1";
} else {
result += "0";
}
if ((j+1)%8==0)
result+=" ";
}
System.out.println(i+"\t"+result);
}
if (enPassant)
System.out.println(enPassantSquare.toString());
}
}

12
src/suicideChess/ComputerPlayer.java

@ -175,8 +175,8 @@ public class ComputerPlayer {
}
}
thinkingBeginingTime = new Date();
nodesSearched=0;
//thinkingBeginingTime = new Date();
//nodesSearched=0;
//alpha beta pruning.
ReturnWrapper bestScore = AlphaBeta(bitboard, 0, SuicideChess.PRINCIPAL_VARIATION_FIRST
, maxDepth, Board.MIN_VALUE, Board.MAX_VALUE);
@ -222,6 +222,8 @@ public class ComputerPlayer {
System.out.println("Found "+bestMoves.size()+" good moves.");
}
//bestMove.display();
return bestMove;
}
@ -359,9 +361,11 @@ public class ComputerPlayer {
//System.out.println("| CurrentScore, BestScore:" + currentScore + ", " + bestScoreSoFar);
//System.out.println("| CurrentBeta, beta:" + currentAlphaBeta + ", " + beta);
//if(returnValue.alphaBeta!=returnValue.branchValue)
// System.out.println(returnValue.alphaBeta+"\t"+returnValue.branchValue);
//calculating new value of beta
if (currentAlphaBeta<=beta) {
if (currentAlphaBeta<beta) {
beta = currentAlphaBeta;
}
//calculating branch value
@ -442,7 +446,7 @@ public class ComputerPlayer {
//System.out.println("| CurrentAlpha, alpha:" + currentAlphaBeta + ", " + alpha);
//calculating new value of alpha
if (currentAlphaBeta>=alpha) {
if (currentAlphaBeta>alpha) {
alpha = currentAlphaBeta;
}
//calculating branch value

34
src/suicideChess/Move.java

@ -57,6 +57,7 @@ public class Move {
switch (move.length()) {
case 5:
isPromotion = true;
promotionPiece = new Piece(move.substring(4,5).toCharArray()[0],board.getCurrentPlayer());
//no break statement here on purpose
case 4:
fromSquare = new Square(move.substring(0,2));
@ -77,10 +78,30 @@ public class Move {
} else {
isCapture = false;
}
if (isPromotion) {
promotionPiece = new Piece(move.toCharArray()[4], movingPiece.getColor());
}
if(movingPiece.getPieceType()==Piece.PAWN) {
//check for enPassant capture
if(board.isEnPassant() && (toSquare.isEqual(board.getEnPassantSquare()))) {
isCapture = true;
isEnPassant = true;
if(movingPiece.getColor()==Piece.BLACK) {
enPassantSquare = new Square(board.getEnPassantSquare().getFileNb(),board.getEnPassantSquare().getRank()+1);
} else {
enPassantSquare = new Square(board.getEnPassantSquare().getFileNb(),board.getEnPassantSquare().getRank()-1);
}
capturePiece = board.getPiece(enPassantSquare);
}
//check for setting enPassant Square
if(movingPiece.getColor()==Piece.BLACK && toSquare.getRank()==fromSquare.getRank()-2) {
isEnPassant = true;
enPassantSquare = new Square(fromSquare.getFileNb(),fromSquare.getRank()-1);
}
if(movingPiece.getColor()==Piece.WHITE && toSquare.getRank()==fromSquare.getRank()+2) {
isEnPassant = true;
enPassantSquare = new Square(fromSquare.getFileNb(),fromSquare.getRank()+1);
}
}
}
/**
@ -121,7 +142,7 @@ public class Move {
/**
* This is the constructor of the class.
* It should be used only for moves that enable or are 'en passant' capture.
* It should be used only for moves that enable 'en passant' or are 'en passant' capture.
*
* @param fromSquare The {@link Square} to move from.
* @param toSquare The {@link Square} to move to.
@ -326,7 +347,8 @@ public class Move {
System.out.println("To square: "+toSquare());
System.out.println((isPromotionMove() ? "Promotion: "+getPromotionPiece().toString() : "No Promotion"));
System.out.println((isCaptureMove() ? "Capture: "+getCapturedPiece().toString() : "No Capture"));
System.out.println((enablesEnPassant() ? "Set en-pass.: "+getEnPassantSquare().getFile()+getEnPassantSquare().getRank() : "No en-pass. set"));
if (isEnPassant()) System.out.println("En passant: "+getEnPassantSquare().getFile()+getEnPassantSquare().getRank());
System.out.println((enablesEnPassant() ? "Set en-pass.: "+getEnPassantSquare().getFile()+getEnPassantSquare().getRank() : "No en-pass. set"));
System.out.println("================");
System.out.println(" ");
}

2
src/suicideChess/Rules.java

@ -190,7 +190,7 @@ public class Rules {
}
break;
default:
throw new RuntimeException("ERROR 01.");
throw new RuntimeException("Unexpected error: e01");
}
if (board.getPiece(toSquare).getPieceNumber()!=Piece.NONE) {
normalMove= false; //cannot move forward if there is a piece

23
src/suicideChess/SuicideChess.java

@ -28,16 +28,16 @@ public class SuicideChess {
/**
* 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 = false;
/**
* 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 = false;
/**
* Use mobility in evaluation function (slows the program down a lot)
*/
public static final boolean USE_MOBILITY = true;
public static final boolean USE_MOBILITY = false;
/**
* do move ordering in Alpha-Beta pruning ?
@ -94,12 +94,12 @@ public class SuicideChess {
/**
* Try the primary variation from the earliest iteration first
*/
public static final boolean PRINCIPAL_VARIATION_FIRST = false;
public static final boolean PRINCIPAL_VARIATION_FIRST = true;
/**
* The name to be displayed
*/
public static final String NAME = "djib's SuShi v1.0.2";
public static final String NAME = "djib's SuShi v1.0.3";
/**
* Displays informations in the console.
@ -178,11 +178,11 @@ public class SuicideChess {
private static void displayPlayer(Board bitboard) {
if(bitboard.getCurrentPlayer()==Piece.BLACK) {
System.out.println("Black: ");
System.out.println("-> Black: ");
} else {
System.out.println("White: ");
System.out.println("-> White: ");
}
//bitboard.debug();
}
//this variable is used to decide whether or not the computer should use it's opening book
@ -398,6 +398,8 @@ public class SuicideChess {
theMove = new Move(whatMove, bitboard);
}
//theMove.display();
if (testAndDisplayIfWinningOrDrawPosition(bitboard)) {
//if board was set in an illegal position
System.out.println("Illegal move: "+theMove.toString());
@ -430,6 +432,9 @@ public class SuicideChess {
if (asciiGame)
System.out.println("Capturing is mandatory.");
}
//bitboard.debug();
for (int moveIndex = 0; moveIndex < allLegalMoves.size(); moveIndex++)
System.out.println(allLegalMoves.get(moveIndex));
System.out.println("Illegal move: "+theMove.toString());
} else {
bitboard.doMove(allLegalMoves.get(foundMoveIndex));
@ -493,6 +498,8 @@ public class SuicideChess {
bitboard.display();
displayPlayer(bitboard);
}
computerMove.display();
bitboard.debug();
}
if (testAndDisplayIfWinningOrDrawPosition(bitboard)) {

Loading…
Cancel
Save