End of game detection now works fine but has made the game a lot slower.

I will imporve this with a : istherevalidmove function.
This commit is contained in:
2006-01-28 13:50:40 +00:00
parent 313cf91ef5
commit a3916eb445
4 changed files with 41 additions and 43 deletions

View File

@ -25,9 +25,9 @@ public class ComputerPlayer {
* @see Board
* @see Move
*/
public static Move doRandomMove(Board bitboard, int color) throws NotAValidSquare {
public static Move doRandomMove(Board bitboard) throws NotAValidSquare {
Random generator = new Random();
Rules.legalMovesForPlayer(bitboard,color);
Rules.legalMovesForPlayer(bitboard);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = Rules.getLegalMovesNonCapture();
@ -50,10 +50,10 @@ public class ComputerPlayer {
* @see Board
* @see Move
*/
public static Move doMinMaxMove(Board bitboard, int color) throws NotAValidSquare, NoPieceOnSquare {
public static Move doMinMaxMove(Board bitboard) throws NotAValidSquare, NoPieceOnSquare {
bestMove = null;
nodesSearched = 0;
int bestScore = MinMax(bitboard, color, 0);
int bestScore = MinMax(bitboard, 0);
if (SuicideChess.postThinkingOutput()) {
System.out.println(SuicideChess.PLY_DEPTH+" "+bestScore*100+" 0 "+nodesSearched+" "+bestMove);
}
@ -61,20 +61,20 @@ public class ComputerPlayer {
}
private static int MinMax(Board bitboard, int color, int currentDepth) throws NotAValidSquare, NoPieceOnSquare {
private static int MinMax(Board bitboard, int currentDepth) throws NotAValidSquare, NoPieceOnSquare {
if (currentDepth >= SuicideChess.PLY_DEPTH) {
return bitboard.getBoardValue();
}
nodesSearched++;
Rules.legalMovesForPlayer(bitboard,color);
Rules.legalMovesForPlayer(bitboard);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = Rules.getLegalMovesNonCapture();
}
if (allLegalMoves.size()==0) {
if (color==Piece.BLACK) {
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
return Board.BLACK_WINS;
} else {
return Board.WHITE_WINS;
@ -83,12 +83,12 @@ public class ComputerPlayer {
int bestMoveIndex=0;
int currentScore;
int bestScoreSoFar;
if (color==Piece.BLACK) {
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
bestScoreSoFar=Board.WHITE_WINS+1; //any move even a WHITE_WINS will be better than that
for (int i=0; i<allLegalMoves.size(); i++) {
Board boardCopy = new Board(bitboard);
boardCopy.doMove(allLegalMoves.get(i));
currentScore=MinMax(boardCopy,Piece.WHITE,currentDepth+1);
currentScore=MinMax(boardCopy,currentDepth+1);
if (currentScore < bestScoreSoFar) { //black tries to minimise his score
bestScoreSoFar = currentScore;
bestMoveIndex = i;
@ -99,7 +99,7 @@ public class ComputerPlayer {
for (int i=0; i<allLegalMoves.size(); i++) {
Board boardCopy = new Board(bitboard);
boardCopy.doMove(allLegalMoves.get(i));
currentScore=MinMax(boardCopy,Piece.BLACK,currentDepth+1);
currentScore=MinMax(boardCopy,currentDepth+1);
if (currentScore > bestScoreSoFar) { //white tries to maximise his score
bestScoreSoFar = currentScore;
bestMoveIndex = i;