The computer plays with minmax and detects the end of games
No known bugs
This commit is contained in:
2006-01-27 23:34:09 +00:00
parent 5266b582bb
commit 213b1e3bf0
8 changed files with 225 additions and 193 deletions

View File

@ -31,12 +31,8 @@ public class Board {
private static final int NB_OF_BITBOARDS = 14;
@SuppressWarnings("serial")
public class NoPieceOnSquare extends Exception {
/*
* Added by Eclipse
*/
private static final long serialVersionUID = -2750943856086117656L;
NoPieceOnSquare(String s) { super(s); };
}
@ -88,6 +84,9 @@ public class Board {
*/
public Board() throws NotAValidSquare {
//the following line makes sure that enPassantSquare is defined at some point.
enPassantSquare = new Square("a1");
bitBoards = new long[NB_OF_BITBOARDS];
addPiece(new Square("a1"),new Piece(Piece.WHITE_ROOK));
addPiece(new Square("b1"),new Piece(Piece.WHITE_KNIGHT));
@ -141,7 +140,7 @@ public class Board {
this.bitBoards[i] = bitboard.bitBoards[i];
}
this.enPassant = bitboard.enPassant;
this.enPassantSquare = bitboard.enPassantSquare;
this.enPassantSquare = new Square(bitboard.enPassantSquare);
}
/*================*
@ -163,8 +162,6 @@ public class Board {
} else {
removePiece(move.toSquare(), move.getCapturedPiece());
}
//capture moves change the value of the board
evaluateNewBoardValue(move);
}
removePiece(move.fromSquare(), move.getMovingPiece());
if (move.isPromotionMove()) {
@ -178,8 +175,8 @@ public class Board {
enPassant=true;
enPassantSquare=move.getEnPassantSquare();
}
evaluateNewBoardValue(move);
}
/**
@ -421,6 +418,15 @@ public class Board {
boardValue = numberOfBlackPieces - numberOfWhitePieces;
}
}
if ((Rules.getLegalMovesCapture().size()==0)&&(Rules.getLegalMovesNonCapture().size()==0)) {
// The following line is NOT an error !!!
// After move from WHITE, if there is no moves for BLACK, BLACK won.
if (move.getMovingPiece().getColor()==Piece.WHITE) {
boardValue = BLACK_WINS;
} else {
boardValue = WHITE_WINS;
}
}
}
}