Version 7.0

===========
Corrected a few bugs from 6.9, like the principal variation.
About to add opening book.
This commit is contained in:
2006-07-02 13:51:14 +00:00
parent 1b500b4421
commit b02755be4e
6 changed files with 183 additions and 80 deletions

View File

@ -36,17 +36,36 @@ public class SuicideChess {
/**
* The name to be displayed
*/
public static final String NAME = "djib's SuShi v0.6.9";
public static final String NAME = "djib's SuShi v0.7";
/**
* Displays informations in the console.
*/
public static final boolean ASCII_GAME = true;
private static boolean asciiGame = false;
/**
* Should the game be played in acsii
* @return boolean
*/
public static boolean playInACSII() {
return asciiGame;
}
/**
* Number of Plies the computes searches to
*/
public static final int PLY_DEPTH = 4;
private static int plyDepth = 4;
/**
* What is the current ply depth
* @return integer
*/
public static int getPlyDepth() { return plyDepth; }
/**
* Maximum number of Plies the computer will ever go to
*/
public static final int MAX_PLY_DEPTH = 8;
/**
* Test and display if the board is in a winning state.
@ -108,6 +127,15 @@ public class SuicideChess {
public static boolean postThinkingOutput() {
return post;
}
private static void displayPlayer(Board bitboard) {
if(bitboard.getCurrentPlayer()==Piece.BLACK) {
System.out.println("Black: ");
} else {
System.out.println("White: ");
}
}
/**
* The main function
* @param args No parameters should be transmitted to this function.
@ -116,10 +144,9 @@ public class SuicideChess {
public static void main(String[] args) throws NotAValidSquare {
System.out.println("Welcome to SuicideChess "+SuicideChess.NAME+"!");
if (!SuicideChess.ASCII_GAME) {
System.out.println("This game was not designed to be played in console. Please use it with XBoard, WinBoard or any compatible program.");
}
System.out.println("Welcome to SuicideChess "+SuicideChess.NAME+"!\n");
System.out.println("Type 'asciiplay' to be able to play in a terminal.");
System.out.println("If you want a graphical interface, you can use XBoard, WinBoard or any compatible program.");
System.out.println();
@ -127,11 +154,6 @@ public class SuicideChess {
Board bitboard = new Board();
addPlayedPosition(bitboard);
if (ASCII_GAME) {
bitboard.display();
System.out.println("White: ");
}
boolean computerPlaying = true; //the computer does not play in foce mode.
boolean playing = true;
@ -152,12 +174,20 @@ public class SuicideChess {
try {
int problemNb = Integer.parseInt(whatMove.substring(8));
bitboard=new Board(SuicideProblems.getProblemNumber(problemNb));
if(ASCII_GAME)
if(asciiGame)
bitboard.display();
} catch (NumberFormatException e) {
System.out.println("Not a valid number: "+ whatMove.substring(8));
}
}
} else if (whatMove.startsWith("asciiplay")) {
asciiGame=true;
bitboard.display();
displayPlayer(bitboard);
} else if (whatMove.startsWith("asciiplay")) {
asciiGame=false;
} else if ((whatMove.startsWith("board"))) {
bitboard.display();
} else {
int xBoardCommand = XBoardProtocol.getCommand(whatMove);
@ -183,6 +213,10 @@ public class SuicideChess {
playing=false;
break;
case XBoardProtocol.NEW:
bitboard=new Board();
addPlayedPosition(bitboard);
computerPlaying = true; //the computer does not play in foce mode.
bitboard.display();
//System.out.println("variant suicide");
break;
case XBoardProtocol.HINT:
@ -199,7 +233,7 @@ public class SuicideChess {
//no break here
case XBoardProtocol.UNDO:
bitboard=new Board(removePlayedPosition());
if (ASCII_GAME) {
if (asciiGame) {
bitboard.display();
}
break;
@ -211,9 +245,16 @@ public class SuicideChess {
break;
case XBoardProtocol.SETBOARD:
bitboard=new Board(whatMove.substring(9));
if(ASCII_GAME)
if(asciiGame)
bitboard.display();
break;
case XBoardProtocol.SETPLY:
try{
plyDepth = Integer.parseInt(whatMove.substring(3));
} catch (NumberFormatException e) {
System.out.println("Not a valid depth: "+ whatMove.substring(3));
}
break;
case XBoardProtocol.UNKNOWN:
if (acceptedUsermove) {
System.out.println("Error (unknown command): "+whatMove);
@ -258,22 +299,22 @@ public class SuicideChess {
}
if (foundMoveIndex == -1) {
if (needToCapture) {
if (ASCII_GAME)
if (asciiGame)
System.out.println("Capturing is mandatory.");
}
System.out.println("Illegal move: "+theMove.toString());
} else {
bitboard.doMove(allLegalMoves.get(foundMoveIndex));
addPlayedPosition(bitboard);
if (ASCII_GAME) {
allLegalMoves.get(foundMoveIndex).display();
System.out.println("Board value: "+bitboard.getBoardValue());
if (asciiGame) {
//allLegalMoves.get(foundMoveIndex).display();
//System.out.println("Board value: "+bitboard.getBoardValue());
bitboard.display();
}
playedALegalMove=true;
}
} else {
if (ASCII_GAME)
if (asciiGame)
System.out.println("Please play a piece of the right color.");
System.out.println("Illegal move: "+theMove.toString());
}
@ -304,13 +345,14 @@ public class SuicideChess {
bitboard.doMove(computerMove);
addPlayedPosition(bitboard);
XBoardProtocol.doMove(computerMove);
if (ASCII_GAME) {
computerMove.display();
System.out.println("Board value: "+bitboard.getBoardValue());
if (asciiGame) {
//computerMove.display();
//System.out.println("Board value: "+bitboard.getBoardValue());
bitboard.display();
displayPlayer(bitboard);
}
}
if (testAndDisplayIfWinningOrDrawPosition(bitboard)) {
computerPlaying=false;
}
@ -370,7 +412,7 @@ public class SuicideChess {
//in the end it says what games where lost by white.
private static void autoProblem() throws NotAValidSquare, UnableToParseFENStringException, NoPieceOnSquare, NoSuchSuicideProblem {
Board bitboard;
boolean[] result=new boolean[SuicideProblems.numberOfProblems()];
int[] result=new int[SuicideProblems.numberOfProblems()];
for(int i=1; i<=SuicideProblems.numberOfProblems(); i++) {
System.out.println("\n\nProblem "+i);
bitboard=new Board(SuicideProblems.getProblemNumber(i));
@ -379,16 +421,26 @@ public class SuicideChess {
bitboard.doMove(computerMove);
}
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
result[i-1]=false;
result[i-1]=Piece.BLACK;
} else if(bitboard.isADraw()){
result[i-1]=Piece.NONE;
} else {
result[i-1]=true;
result[i-1]=Piece.WHITE;
}
}
System.out.println("\n\nLost following games:\n========begin========");
int stats=SuicideProblems.numberOfProblems();
for(int i=1; i<=SuicideProblems.numberOfProblems(); i++) {
if (!result[i-1])
if (result[i-1]==Piece.BLACK) {
System.out.println("Problem "+i+" lost !");
stats--;
} else if (result[i-1]==Piece.NONE) {
System.out.println("Problem "+i+" drawn !");
stats--;
}
}
System.out.println("---------------------\n"+stats+" problems solved out of "+SuicideProblems.numberOfProblems());
System.out.println("=========end=========");
}
}