Version 6.9

===========
Now detects draw (50 moves only)
Displays time to find move
Can read a library of problems from a file
Each problem can be selected independently or all can be
  played in succession and then the result is displayed.
This commit is contained in:
2006-07-01 15:06:24 +00:00
parent 74206376a7
commit 1b500b4421
5 changed files with 369 additions and 161 deletions

View File

@ -1,6 +1,7 @@
package suicideChess;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import suicideChess.Board.NoPieceOnSquare;
@ -138,9 +139,11 @@ public class ComputerPlayer {
public static Move doAlphaBetaMove(Board bitboard) throws NotAValidSquare, NoPieceOnSquare {
bestMove = null;
nodesSearched = 0;
ReturnWrapper bestScore = AlphaBeta(bitboard, 0, Board.BLACK_WINS-1, Board.WHITE_WINS+1);
Date thinkingBeginingTime = new Date();
ReturnWrapper bestScore = AlphaBeta(bitboard, 0, Board.BLACK_WINS-1, Board.WHITE_WINS+1);
Date thinkingEndTime = new Date();
//select one of the best moves randomly
Random generator = new Random();
//if (currentDepth == 0) { System.out.println(bestMoveIndex.size()); }
@ -149,7 +152,9 @@ public class ComputerPlayer {
System.out.println("Found "+bestMoves.size()+" good moves.");
if (SuicideChess.postThinkingOutput()) {
System.out.println(SuicideChess.PLY_DEPTH+" "+bestScore.getAlphaBeta()*100+" 0 "+nodesSearched+" "+bestMove);
System.out.println(SuicideChess.PLY_DEPTH+" "+bestScore.getAlphaBeta()*100+
" "+((int)(thinkingEndTime.getTime()-thinkingBeginingTime.getTime())/10)+ //search time in centiseconds
" "+nodesSearched+" "+bestMove);
}
return bestMove;
@ -172,6 +177,10 @@ public class ComputerPlayer {
};
private static ReturnWrapper AlphaBeta(Board bitboard, int currentDepth, int alpha, int beta) throws NotAValidSquare, NoPieceOnSquare {
nodesSearched++;
if(bitboard.isADraw()) {
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD);
}
if (currentDepth >= SuicideChess.PLY_DEPTH) {
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue());
@ -202,7 +211,7 @@ public class ComputerPlayer {
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,beta);
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,Board.MIN_VALUE,beta);
currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta();
@ -229,7 +238,7 @@ public class ComputerPlayer {
}
if(beta<alpha) {
//System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
//if(currentDepth!=SuicideChess.PLY_DEPTH-1) System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
return new ReturnWrapper(alpha,bestScoreSoFar); //pruning
}
}
@ -242,7 +251,7 @@ public class ComputerPlayer {
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,beta);
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,Board.MAX_VALUE);
currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta();
@ -269,7 +278,7 @@ public class ComputerPlayer {
}
if(alpha>beta) {
//System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
//if(currentDepth!=SuicideChess.PLY_DEPTH-1) System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
return new ReturnWrapper(beta,bestScoreSoFar); //pruning
}
}