Version 0.9.4

=============
Corrected undo bug
Added iterative deepening
This commit is contained in:
2006-07-04 19:30:25 +00:00
parent 7dc781c25e
commit 1eee874d6b
2 changed files with 35 additions and 24 deletions

View File

@ -142,10 +142,13 @@ public class ComputerPlayer {
nodesSearched = 0; nodesSearched = 0;
thinkingBeginingTime = new Date(); thinkingBeginingTime = new Date();
quiescenceSearch = false;
//iterative deepening //iterative deepening
for(maxDepth=2; maxDepth<=SuicideChess.getPlyDepth(); maxDepth++) { for(maxDepth=2; maxDepth<=SuicideChess.getPlyDepth(); maxDepth++) {
ReturnWrapper bestScore = AlphaBeta(bitboard, 0, Board.MIN_VALUE, Board.MAX_VALUE); if(SuicideChess.QUIESCENCE_SEARCH && maxDepth==SuicideChess.getPlyDepth()) {
quiescenceSearch = true; //don't do quiescence search till the last level iterative deepening
}
ReturnWrapper bestScore = AlphaBeta(bitboard, 0, maxDepth, Board.MIN_VALUE, Board.MAX_VALUE);
Date thinkingEndTime = new Date(); Date thinkingEndTime = new Date();
//select one of the best moves randomly //select one of the best moves randomly
@ -174,6 +177,7 @@ public class ComputerPlayer {
return bestMove; return bestMove;
} }
private static boolean quiescenceSearch; //this will be used to determine is quiescence search is needed.
private static Date thinkingBeginingTime; private static Date thinkingBeginingTime;
private static int maxDepth; private static int maxDepth;
private static ArrayList<Move> bestMoves=new ArrayList<Move>(); private static ArrayList<Move> bestMoves=new ArrayList<Move>();
@ -194,33 +198,33 @@ public class ComputerPlayer {
public int getBranchValue() {return this.branchValue;} public int getBranchValue() {return this.branchValue;}
public String getPrincipalVariation() {return this.principalVariation;} public String getPrincipalVariation() {return this.principalVariation;}
}; };
private static ReturnWrapper AlphaBeta(Board bitboard, int currentDepth, int alpha, int beta) throws NotAValidSquare, NoPieceOnSquare { private static ReturnWrapper AlphaBeta(Board bitboard, int currentDepth, int currentMaxDepth, int alpha, int beta) throws NotAValidSquare, NoPieceOnSquare {
nodesSearched++; nodesSearched++;
int currentMaxDepth = maxDepth; //this is when intelligent depth is on, the computer may search one step further
if(!SuicideChess.QUIESCENCE_SEARCH || currentMaxDepth>=SuicideChess.MAX_PLY_DEPTH) { //stop if we are getting to deep
if(bitboard.isADraw()) { if(bitboard.isADraw()) {
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,""); return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,"");
} }
if (currentDepth >= currentMaxDepth) {
if((!quiescenceSearch)&& (currentDepth >= currentMaxDepth)) { //stop if we are getting to deep
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue()); //System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),""); return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
} }
}
Rules.legalMovesForPlayer(bitboard); Rules.legalMovesForPlayer(bitboard);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture(); ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) { if (allLegalMoves.size()==0) {
if(SuicideChess.QUIESCENCE_SEARCH) { if((quiescenceSearch) && (currentDepth >= currentMaxDepth)) {
if(bitboard.isADraw()) {
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,"");
}
if (currentDepth >= currentMaxDepth) {
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue()); //System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),""); return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
} }
}
allLegalMoves = Rules.getLegalMovesNonCapture(); allLegalMoves = Rules.getLegalMovesNonCapture();
} else { //if there are captures, see if we can just abandon search here } else { //if there are captures, see if we can just abandon search here
if((quiescenceSearch) && (currentDepth >= currentMaxDepth)) {
if((currentMaxDepth<SuicideChess.MAX_PLY_DEPTH) && (allLegalMoves.size()<=SuicideChess.QUIESCENCE_LIMIT)) {
currentMaxDepth++;
} else {
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
}
}
if (SuicideChess.INTELLIGENT_DEPTH) { if (SuicideChess.INTELLIGENT_DEPTH) {
currentMaxDepth++; //go one step further in depth currentMaxDepth++; //go one step further in depth
if(currentDepth==0 && allLegalMoves.size()==1) { if(currentDepth==0 && allLegalMoves.size()==1) {
@ -256,7 +260,7 @@ public class ComputerPlayer {
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i)); //System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,Board.MIN_VALUE,beta); ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,currentMaxDepth,Board.MIN_VALUE,beta);
currentScore = returnValue.getBranchValue(); currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta(); currentAlphaBeta = returnValue.getAlphaBeta();
@ -307,7 +311,7 @@ public class ComputerPlayer {
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i)); //System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,Board.MAX_VALUE); ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,currentMaxDepth,alpha,Board.MAX_VALUE);
currentScore = returnValue.getBranchValue(); currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta(); currentAlphaBeta = returnValue.getAlphaBeta();

View File

@ -47,7 +47,7 @@ public class SuicideChess {
/** /**
* Quiescence search -> don't evaluate if captures are possible. * Quiescence search -> don't evaluate if captures are possible.
*/ */
public static final boolean QUIESCENCE_SEARCH = false; public static final boolean QUIESCENCE_SEARCH = true;
/** /**
* The name to be displayed * The name to be displayed
@ -82,6 +82,10 @@ public class SuicideChess {
* Maximum number of Plies the computer will ever go to * Maximum number of Plies the computer will ever go to
*/ */
public static final int MAX_PLY_DEPTH = 8; public static final int MAX_PLY_DEPTH = 8;
/**
* Quiescence limit (ie. if more than that many possibilities of capturing, don't analyse further.
*/
public static final int QUIESCENCE_LIMIT = 5;
/** /**
* Test and display if the board is in a winning state. * Test and display if the board is in a winning state.
@ -127,6 +131,7 @@ public class SuicideChess {
* This function is used to undo the last position played * This function is used to undo the last position played
*/ */
private static Board removePlayedPosition () { private static Board removePlayedPosition () {
if(allPlayedPositions.size()>1)
allPlayedPositions.remove(0); allPlayedPositions.remove(0);
return allPlayedPositions.get(0); return allPlayedPositions.get(0);
} }
@ -204,6 +209,7 @@ public class SuicideChess {
System.out.println("remove\t\t\tundoes a full move"); System.out.println("remove\t\t\tundoes a full move");
System.out.println("force\t\t\tthe computer will check moves but not play"); System.out.println("force\t\t\tthe computer will check moves but not play");
System.out.println(); System.out.println();
System.out.println("board\t\t\tdisplays the current status of the board");
System.out.println("setboard FEN\t\tsets the board according to the FEN position"); System.out.println("setboard FEN\t\tsets the board according to the FEN position");
System.out.println("sd N\t\t\tsets the search depth to n"); System.out.println("sd N\t\t\tsets the search depth to n");
System.out.println("bk\t\t\tdisplays available openbook moves for current position"); System.out.println("bk\t\t\tdisplays available openbook moves for current position");
@ -396,6 +402,7 @@ public class SuicideChess {
//allLegalMoves.get(foundMoveIndex).display(); //allLegalMoves.get(foundMoveIndex).display();
//System.out.println("Board value: "+bitboard.getBoardValue()); //System.out.println("Board value: "+bitboard.getBoardValue());
bitboard.display(); bitboard.display();
displayPlayer(bitboard);
} }
playedALegalMove=true; playedALegalMove=true;
} }