before big code modification (moving player color in Board)
This commit is contained in:
@ -9,7 +9,7 @@ import suicideChess.Square.NotAValidSquare;
|
||||
/**
|
||||
* This class will contain all the AI.
|
||||
* @author Jean-Baptiste Hétier
|
||||
* @version $LastChangedRevision: 33 $, $LastChangedDate: 2006-01-13 17:03:06 +0000 (Fri, 13 Jan 2006) $
|
||||
* @version $LastChangedRevision$, $LastChangedDate$
|
||||
*/
|
||||
|
||||
public class ComputerPlayer {
|
||||
@ -52,7 +52,11 @@ public class ComputerPlayer {
|
||||
*/
|
||||
public static Move doMinMaxMove(Board bitboard, int color) throws NotAValidSquare, NoPieceOnSquare {
|
||||
bestMove = null;
|
||||
MinMax(bitboard, color, 0);
|
||||
nodesSearched = 0;
|
||||
int bestScore = MinMax(bitboard, color, 0);
|
||||
if (SuicideChess.postThinkingOutput()) {
|
||||
System.out.println(SuicideChess.PLY_DEPTH+" "+bestScore*100+" 0 "+nodesSearched+" "+bestMove);
|
||||
}
|
||||
return bestMove;
|
||||
}
|
||||
|
||||
@ -61,6 +65,9 @@ public class ComputerPlayer {
|
||||
if (currentDepth >= SuicideChess.PLY_DEPTH) {
|
||||
return bitboard.getBoardValue();
|
||||
}
|
||||
|
||||
nodesSearched++;
|
||||
|
||||
Rules.legalMovesForPlayer(bitboard,color);
|
||||
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
|
||||
if (allLegalMoves.size()==0) {
|
||||
@ -105,4 +112,5 @@ public class ComputerPlayer {
|
||||
}
|
||||
|
||||
private static Move bestMove = null;
|
||||
private static int nodesSearched;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* Class used to communicate with XBoard.
|
||||
* @author Jean-Baptiste Hétier
|
||||
* @version $LastChangedRevision: 33 $, $LastChangedDate: 2006-01-13 17:03:06 +0000 (Fri, 13 Jan 2006) $
|
||||
* @version $LastChangedRevision$, $LastChangedDate$
|
||||
*/
|
||||
public class XBoardProtocol {
|
||||
|
||||
@ -62,6 +62,26 @@ public class XBoardProtocol {
|
||||
* XBoard did not accept variant suicide chess
|
||||
*/
|
||||
public static final int NOT_ACCEPTED_SUICIDE = 11;
|
||||
/**
|
||||
* XBoard sent a ping signal
|
||||
*/
|
||||
public static final int PING = 12;
|
||||
/**
|
||||
* XBoard sent an Undo signal
|
||||
*/
|
||||
public static final int UNDO = 13;
|
||||
/**
|
||||
* Xboard sent a remove signal (treated at two undos)
|
||||
*/
|
||||
public static final int REMOVE = 14;
|
||||
/**
|
||||
* Xboard asks to display thinking output
|
||||
*/
|
||||
public static final int POST = 15;
|
||||
/**
|
||||
* Xboard asks NOT to display thinking output
|
||||
*/
|
||||
public static final int NOPOST = 16;
|
||||
/**
|
||||
* Unknown command
|
||||
*/
|
||||
@ -74,10 +94,11 @@ public class XBoardProtocol {
|
||||
*/
|
||||
public static void initialise() throws IOException {
|
||||
//done=1 is here to tell that the program has finish requesting features
|
||||
System.out.println("feature myname=\"djib's Suicide Chess\"");
|
||||
System.out.println("feature sigint=0 sigterm=0");
|
||||
System.out.println("feature usermove=1"); //sends moves like 'usermove e2e4'
|
||||
System.out.println("feature myname=\"djib's Suicide Chess\"");
|
||||
System.out.println("feature sigint=0 sigterm=0"); //do not interrupt me
|
||||
System.out.println("feature variants=\"suicide\"");
|
||||
System.out.println("feature ping=1");
|
||||
System.out.println("feature time=0 draw=0 reuse=0 analyze=0 colors=0");
|
||||
System.out.println("feature done=1");
|
||||
if (SuicideChess.ASCII_GAME)
|
||||
@ -123,6 +144,16 @@ public class XBoardProtocol {
|
||||
return HINT;
|
||||
} else if (command.equals("force")) {
|
||||
return FORCE;
|
||||
} else if (command.startsWith("ping")) {
|
||||
return PING;
|
||||
} else if (command.equals("undo")) {
|
||||
return UNDO;
|
||||
} else if (command.equals("remove")) {
|
||||
return REMOVE;
|
||||
} else if (command.equals("post")) {
|
||||
return POST;
|
||||
} else if (command.equals("nopost")) {
|
||||
return NOPOST;
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
|
Reference in New Issue
Block a user