The computer plays with minmax and detects the end of games
No known bugs
This commit is contained in:
2006-01-27 23:34:09 +00:00
parent 5266b582bb
commit 213b1e3bf0
8 changed files with 225 additions and 193 deletions

View File

@ -65,6 +65,23 @@ public class SuicideChess {
}
}
/**
* Test and display if the board is in a winning state.
* @param bitboard A Board
* @return True or False
*/
private static boolean testWinningPosition (Board bitboard) {
if (bitboard.getBoardValue()==Board.BLACK_WINS) {
System.out.println("0-1 {Black mates}");
return true;
} else if (bitboard.getBoardValue()==Board.WHITE_WINS) {
System.out.println("1-0 {White mates}");
return true;
}
return false;
}
/**
* If feature usermove has not been accepted by XBoard then consider all unknown commands
* as moves
@ -95,7 +112,6 @@ public class SuicideChess {
System.out.println("White: ");
}
ComputerPlayer computer = new ComputerPlayer();
boolean computerPlaying = true; //the computer does not play in foce mode.
boolean playing = true;
@ -132,7 +148,7 @@ public class SuicideChess {
System.out.println("variant suicide");
break;
case XBoardProtocol.HINT:
System.out.println("Hint: "+computer.doRandomMove(bitboard,currentPlayerColor));
System.out.println("Hint: "+ComputerPlayer.doRandomMove(bitboard,currentPlayerColor));
break;
case XBoardProtocol.FORCE:
computerPlaying = false;
@ -193,6 +209,10 @@ public class SuicideChess {
System.out.println("Illegal move: "+theMove.toString());
}
if (testWinningPosition(bitboard)) {
computerPlaying=false;
}
if (!playedALegalMove) {
break;
}
@ -205,7 +225,7 @@ public class SuicideChess {
if (xBoardCommand==XBoardProtocol.GO)
computerPlaying = true;
if (computerPlaying) {
Move computerMove = computer.doMinMaxMove(bitboard,currentPlayerColor);
Move computerMove = ComputerPlayer.doMinMaxMove(bitboard,currentPlayerColor);
bitboard.doMove(computerMove);
XBoardProtocol.doMove(computerMove);
if (ASCII_GAME) {
@ -215,8 +235,11 @@ public class SuicideChess {
}
changeCurrentPlayerColor();
}
if (testWinningPosition(bitboard)) {
computerPlaying=false;
}
break;
}
// if (whatMove.startsWith("hint")) {
@ -255,9 +278,8 @@ public class SuicideChess {
} catch (NotAValidSquare err) {
System.out.println(err);
continue;
} catch (Exception err) {
System.out.println(err);
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}