Browse Source

Version 5.2

===========
Corrected another bug in alpha-beta.
master
djib 16 years ago
parent
commit
95deacff45
  1. 11
      src/suicideChess/Board.java
  2. 46
      src/suicideChess/ComputerPlayer.java
  3. 6
      src/suicideChess/SuicideChess.java

11
src/suicideChess/Board.java

@ -44,10 +44,21 @@ public class Board {
*/
public static final int WHITE_WINS = 99999;
/**
* Value representing the maximum value possible for the evaluation function
*/
public static final int MAX_VALUE = WHITE_WINS+1;
/**
* Value returned by the evaluation function when Black wins
*/
public static final int BLACK_WINS = -99999;
/**
* Value representing the minimum value possible for the evaluation function
*/
public static final int MIN_VALUE = BLACK_WINS-1;
/*======*

46
src/suicideChess/ComputerPlayer.java

@ -172,7 +172,7 @@ public class ComputerPlayer {
};
private static ReturnWrapper AlphaBeta(Board bitboard, int currentDepth, int alpha, int beta) throws NotAValidSquare, NoPieceOnSquare {
if (currentDepth >= SuicideChess.PLY_DEPTH) {
System.out.println("Evaluate :" + bitboard.getBoardValue());
//System.out.println("'-> Evaluate: "+bitboard.getBoardValue());
return new ReturnWrapper(bitboard.getBoardValue(),bitboard.getBoardValue());
}
nodesSearched++;
@ -184,31 +184,37 @@ public class ComputerPlayer {
}
if (allLegalMoves.size()==0) {
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
System.out.println("Evaluate :" + bitboard.getBoardValue());
//System.out.println("'-> Evaluate *BLACK WINS*: "+Board.BLACK_WINS);
return new ReturnWrapper(Board.BLACK_WINS,Board.BLACK_WINS);
} else {
System.out.println("Evaluate :" + bitboard.getBoardValue());
return new ReturnWrapper(Board.WHITE_WINS,Board.BLACK_WINS);
//System.out.println("'-> Evaluate *WHITE WINS* : "+Board.WHITE_WINS);
return new ReturnWrapper(Board.WHITE_WINS,Board.WHITE_WINS);
}
} else {
int currentScore;
int bestScoreSoFar;
int currentAlphaBeta;
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
bestScoreSoFar=Board.WHITE_WINS+1; //any move even a WHITE_WINS will be better than that
bestScoreSoFar=Board.MAX_VALUE; //black tries to minimise
for (int i=0; i<allLegalMoves.size(); i++) {
Board boardCopy = new Board(bitboard);
System.out.println(currentDepth + ": " + allLegalMoves.get(i));
boardCopy.doMove(allLegalMoves.get(i));
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,beta);
currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta();
System.out.println(currentScore + " " + currentAlphaBeta);
//System.out.println("| CurrentScore, BestScore:" + currentScore + ", " + bestScoreSoFar);
//System.out.println("| CurrentBeta, beta:" + currentAlphaBeta + ", " + beta);
//calculating new value of beta
if (currentAlphaBeta<beta) {
beta = currentAlphaBeta;
if (currentDepth==0) {
bestMoves.clear();
//System.out.println("*** Clear ");
}
}
//calculating branch value
@ -217,32 +223,39 @@ public class ComputerPlayer {
bestScoreSoFar=currentScore;
}
if(currentDepth==0) {
System.out.println("Adding move");
bestMoves.add(allLegalMoves.get(i));
//System.out.println("*** Adding "+allLegalMoves.get(i));
}
}
if(beta<=alpha) {
System.out.println("pruning");
if(beta<alpha) {
if(currentDepth != 3)
System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
return new ReturnWrapper(alpha,bestScoreSoFar); //pruning
}
}
return new ReturnWrapper(beta,bestScoreSoFar);
} else { //white piece
bestScoreSoFar=Board.BLACK_WINS-1; //any move even a BLACK_WINS will be better than that
bestScoreSoFar=Board.MIN_VALUE; //white tries to maximise
for (int i=0; i<allLegalMoves.size(); i++) {
Board boardCopy = new Board(bitboard);
boardCopy.doMove(allLegalMoves.get(i));
System.out.println(currentDepth + ": " + allLegalMoves.get(i));
//System.out.println("Analysing "+currentDepth+":"+allLegalMoves.get(i));
ReturnWrapper returnValue = AlphaBeta(boardCopy,currentDepth+1,alpha,beta);
currentScore = returnValue.getBranchValue();
currentAlphaBeta = returnValue.getAlphaBeta();
System.out.println(currentScore + " " + currentAlphaBeta);
//System.out.println("| CurrentScore, BestScore:" + currentScore + ", " + bestScoreSoFar);
//System.out.println("| CurrentAlpha, alpha:" + currentAlphaBeta + ", " + alpha);
//calculating new value of beta
if (currentAlphaBeta>alpha) {
alpha = currentAlphaBeta;
if (currentDepth==0) {
bestMoves.clear();
//System.out.println("*** Clear ");
}
}
//calculating branch value
@ -251,13 +264,14 @@ public class ComputerPlayer {
bestScoreSoFar=currentScore;
}
if(currentDepth==0) {
System.out.println("Adding move");
bestMoves.add(allLegalMoves.get(i));
//System.out.println("*** Adding "+allLegalMoves.get(i));
}
}
if(alpha>=beta) {
System.out.println("pruning");
if(alpha>beta) {
if(currentDepth != 3)
System.out.println("Pruning "+Integer.toString(allLegalMoves.size()-i)+" alternatives at depth "+ currentDepth);
return new ReturnWrapper(beta,bestScoreSoFar); //pruning
}
}

6
src/suicideChess/SuicideChess.java

@ -33,17 +33,17 @@ public class SuicideChess {
/**
* The name to be displayed
*/
public static final String NAME = "djib's SuShi (Suicide Chess) v0.5";
public static final String NAME = "djib's SuShi v0.5.2";
/**
* Displays informations in the console.
*/
public static final boolean ASCII_GAME = true;
public static final boolean ASCII_GAME = false;
/**
* Number of Plies the computes searches to
*/
public static final int PLY_DEPTH = 2;
public static final int PLY_DEPTH = 4;
/**
* Test and display if the board is in a winning state.

Loading…
Cancel
Save