before big code modification (moving player color in Board)
This commit is contained in:
@ -53,7 +53,7 @@ public class SuicideChess {
|
||||
/**
|
||||
* Change the color of the current player
|
||||
*/
|
||||
private static void changeCurrentPlayerColor() {
|
||||
public static void changeCurrentPlayerColor() {
|
||||
if(currentPlayerColor==Piece.WHITE) {
|
||||
currentPlayerColor=Piece.BLACK;
|
||||
if (ASCII_GAME)
|
||||
@ -88,7 +88,41 @@ public class SuicideChess {
|
||||
*/
|
||||
private static boolean acceptedUsermove = false;
|
||||
|
||||
/**
|
||||
* This array is used for undo purposes. Positions are sorted from last to first.
|
||||
*/
|
||||
private static ArrayList<Board> allPlayedPositions = new ArrayList<Board>();
|
||||
|
||||
/**
|
||||
* This function is used to add a new position to the list of all positions
|
||||
* @param position A {@link Board}
|
||||
* @see Board
|
||||
*/
|
||||
private static void addPlayedPosition (Board position) {
|
||||
allPlayedPositions.add(0,new Board(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to undo the last position played
|
||||
*/
|
||||
private static Board removePlayedPosition () {
|
||||
changeCurrentPlayerColor();
|
||||
allPlayedPositions.remove(0);
|
||||
return allPlayedPositions.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This variable says whether the computer should display a "thinking output"
|
||||
*/
|
||||
private static boolean post = true;
|
||||
|
||||
/**
|
||||
* Should computer display thinking output or not ?
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean postThinkingOutput() {
|
||||
return post;
|
||||
}
|
||||
/**
|
||||
* The main function
|
||||
* @param args No parameters should be transmitted to this function.
|
||||
@ -106,6 +140,7 @@ public class SuicideChess {
|
||||
|
||||
BufferedReader moveInput = new BufferedReader(new InputStreamReader(System.in));
|
||||
Board bitboard = new Board();
|
||||
addPlayedPosition(bitboard);
|
||||
|
||||
if (ASCII_GAME) {
|
||||
bitboard.display();
|
||||
@ -145,7 +180,7 @@ public class SuicideChess {
|
||||
playing=false;
|
||||
break;
|
||||
case XBoardProtocol.NEW:
|
||||
System.out.println("variant suicide");
|
||||
//System.out.println("variant suicide");
|
||||
break;
|
||||
case XBoardProtocol.HINT:
|
||||
System.out.println("Hint: "+ComputerPlayer.doRandomMove(bitboard,currentPlayerColor));
|
||||
@ -153,6 +188,24 @@ public class SuicideChess {
|
||||
case XBoardProtocol.FORCE:
|
||||
computerPlaying = false;
|
||||
break;
|
||||
case XBoardProtocol.PING:
|
||||
System.out.println("pong "+whatMove.substring(5));
|
||||
break;
|
||||
case XBoardProtocol.REMOVE:
|
||||
removePlayedPosition();
|
||||
//no break here
|
||||
case XBoardProtocol.UNDO:
|
||||
bitboard=new Board(removePlayedPosition());
|
||||
if (ASCII_GAME) {
|
||||
bitboard.display();
|
||||
}
|
||||
break;
|
||||
case XBoardProtocol.POST:
|
||||
post=true;
|
||||
break;
|
||||
case XBoardProtocol.NOPOST:
|
||||
post=false;
|
||||
break;
|
||||
case XBoardProtocol.UNKNOWN:
|
||||
if (acceptedUsermove) {
|
||||
System.out.println("Error (unknown command): "+whatMove);
|
||||
@ -196,6 +249,8 @@ 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();
|
||||
System.out.println("Board value: "+bitboard.getBoardValue());
|
||||
@ -216,7 +271,6 @@ public class SuicideChess {
|
||||
if (!playedALegalMove) {
|
||||
break;
|
||||
}
|
||||
changeCurrentPlayerColor();
|
||||
//No break statement here on purpose.
|
||||
case XBoardProtocol.GO:
|
||||
//this is not really nice but it avoids having to write twice the code
|
||||
@ -227,13 +281,14 @@ public class SuicideChess {
|
||||
if (computerPlaying) {
|
||||
Move computerMove = ComputerPlayer.doMinMaxMove(bitboard,currentPlayerColor);
|
||||
bitboard.doMove(computerMove);
|
||||
addPlayedPosition(bitboard);
|
||||
XBoardProtocol.doMove(computerMove);
|
||||
changeCurrentPlayerColor();
|
||||
if (ASCII_GAME) {
|
||||
computerMove.display();
|
||||
System.out.println("Board value: "+bitboard.getBoardValue());
|
||||
bitboard.display();
|
||||
}
|
||||
changeCurrentPlayerColor();
|
||||
}
|
||||
if (testWinningPosition(bitboard)) {
|
||||
computerPlaying=false;
|
||||
@ -280,6 +335,7 @@ public class SuicideChess {
|
||||
continue;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user