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

@ -43,27 +43,7 @@ public class SuicideChess {
/**
* Number of Plies the computes searches to
*/
public static final int PLY_DEPTH = 5;
/**
* The color of the current player
*/
private static int currentPlayerColor = Piece.WHITE;
/**
* Change the color of the current player
*/
public static void changeCurrentPlayerColor() {
if(currentPlayerColor==Piece.WHITE) {
currentPlayerColor=Piece.BLACK;
if (ASCII_GAME)
System.out.println("Black: ");
} else {
currentPlayerColor=Piece.WHITE;
if (ASCII_GAME)
System.out.println("White: ");
}
}
public static final int PLY_DEPTH = 4;
/**
* Test and display if the board is in a winning state.
@ -106,7 +86,6 @@ public class SuicideChess {
* This function is used to undo the last position played
*/
private static Board removePlayedPosition () {
changeCurrentPlayerColor();
allPlayedPositions.remove(0);
return allPlayedPositions.get(0);
}
@ -183,7 +162,7 @@ public class SuicideChess {
//System.out.println("variant suicide");
break;
case XBoardProtocol.HINT:
System.out.println("Hint: "+ComputerPlayer.doRandomMove(bitboard,currentPlayerColor));
System.out.println("Hint: "+ComputerPlayer.doRandomMove(bitboard));
break;
case XBoardProtocol.FORCE:
computerPlaying = false;
@ -223,8 +202,8 @@ public class SuicideChess {
boolean needToCapture = false;
int foundMoveIndex = -1;
if(theMove.getMovingPiece().getColor() == currentPlayerColor) {
Rules.legalMovesForPlayer(bitboard,currentPlayerColor);
if(theMove.getMovingPiece().getColor() == bitboard.getCurrentPlayer()) {
Rules.legalMovesForPlayer(bitboard);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = Rules.getLegalMovesNonCapture();
@ -249,7 +228,6 @@ public class SuicideChess {
System.out.println("Illegal move: "+theMove.toString());
} else {
bitboard.doMove(allLegalMoves.get(foundMoveIndex));
changeCurrentPlayerColor();
addPlayedPosition(bitboard);
if (ASCII_GAME) {
allLegalMoves.get(foundMoveIndex).display();
@ -279,11 +257,10 @@ public class SuicideChess {
if (xBoardCommand==XBoardProtocol.GO)
computerPlaying = true;
if (computerPlaying) {
Move computerMove = ComputerPlayer.doMinMaxMove(bitboard,currentPlayerColor);
Move computerMove = ComputerPlayer.doMinMaxMove(bitboard);
bitboard.doMove(computerMove);
addPlayedPosition(bitboard);
XBoardProtocol.doMove(computerMove);
changeCurrentPlayerColor();
if (ASCII_GAME) {
computerMove.display();
System.out.println("Board value: "+bitboard.getBoardValue());