Version 0.9.4
============= Corrected undo bug Added iterative deepening
This commit is contained in:
@ -142,10 +142,13 @@ public class ComputerPlayer {
|
||||
nodesSearched = 0;
|
||||
|
||||
thinkingBeginingTime = new Date();
|
||||
|
||||
quiescenceSearch = false;
|
||||
//iterative deepening
|
||||
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();
|
||||
|
||||
//select one of the best moves randomly
|
||||
@ -174,6 +177,7 @@ public class ComputerPlayer {
|
||||
return bestMove;
|
||||
}
|
||||
|
||||
private static boolean quiescenceSearch; //this will be used to determine is quiescence search is needed.
|
||||
private static Date thinkingBeginingTime;
|
||||
private static int maxDepth;
|
||||
private static ArrayList<Move> bestMoves=new ArrayList<Move>();
|
||||
@ -194,33 +198,33 @@ public class ComputerPlayer {
|
||||
public int getBranchValue() {return this.branchValue;}
|
||||
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++;
|
||||
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()) {
|
||||
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,"");
|
||||
}
|
||||
if (currentDepth >= currentMaxDepth) {
|
||||
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
|
||||
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
|
||||
}
|
||||
if(bitboard.isADraw()) {
|
||||
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,"");
|
||||
}
|
||||
|
||||
if((!quiescenceSearch)&& (currentDepth >= currentMaxDepth)) { //stop if we are getting to deep
|
||||
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
|
||||
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
|
||||
}
|
||||
Rules.legalMovesForPlayer(bitboard);
|
||||
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
|
||||
if (allLegalMoves.size()==0) {
|
||||
if(SuicideChess.QUIESCENCE_SEARCH) {
|
||||
if(bitboard.isADraw()) {
|
||||
return new ReturnWrapper(Board.DRAW_BOARD,Board.DRAW_BOARD,"");
|
||||
}
|
||||
if (currentDepth >= currentMaxDepth) {
|
||||
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
|
||||
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
|
||||
}
|
||||
if((quiescenceSearch) && (currentDepth >= currentMaxDepth)) {
|
||||
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
|
||||
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue(),"");
|
||||
}
|
||||
allLegalMoves = Rules.getLegalMovesNonCapture();
|
||||
} 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) {
|
||||
currentMaxDepth++; //go one step further in depth
|
||||
if(currentDepth==0 && allLegalMoves.size()==1) {
|
||||
@ -256,7 +260,7 @@ public class ComputerPlayer {
|
||||
|
||||
//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();
|
||||
currentAlphaBeta = returnValue.getAlphaBeta();
|
||||
|
||||
@ -307,7 +311,7 @@ public class ComputerPlayer {
|
||||
|
||||
//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();
|
||||
currentAlphaBeta = returnValue.getAlphaBeta();
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class SuicideChess {
|
||||
/**
|
||||
* 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
|
||||
@ -82,6 +82,10 @@ public class SuicideChess {
|
||||
* Maximum number of Plies the computer will ever go to
|
||||
*/
|
||||
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.
|
||||
@ -127,7 +131,8 @@ public class SuicideChess {
|
||||
* This function is used to undo the last position played
|
||||
*/
|
||||
private static Board removePlayedPosition () {
|
||||
allPlayedPositions.remove(0);
|
||||
if(allPlayedPositions.size()>1)
|
||||
allPlayedPositions.remove(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("force\t\t\tthe computer will check moves but not play");
|
||||
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("sd N\t\t\tsets the search depth to n");
|
||||
System.out.println("bk\t\t\tdisplays available openbook moves for current position");
|
||||
@ -396,6 +402,7 @@ public class SuicideChess {
|
||||
//allLegalMoves.get(foundMoveIndex).display();
|
||||
//System.out.println("Board value: "+bitboard.getBoardValue());
|
||||
bitboard.display();
|
||||
displayPlayer(bitboard);
|
||||
}
|
||||
playedALegalMove=true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user