Browse Source

Version 0.8.9

=============
Added external config file -> the resulting program seems a lot faster !!!
Added help.
master
djib 16 years ago
parent
commit
f67d82d129
  1. 81
      src/suicideChess/Board.java
  2. 3
      src/suicideChess/ComputerPlayer.java
  3. 344
      src/suicideChess/ConfigFile.java
  4. 57
      src/suicideChess/Piece.java
  5. 38
      src/suicideChess/SuicideChess.java

81
src/suicideChess/Board.java

@ -65,41 +65,6 @@ public class Board {
*/
public static final int DRAW_BOARD = 0;
/**
* Importance of real mobility in position evaluation (ie. how many moves can one make compared to the other)
*/
public static final int REAL_MOBILITY_VALUE = 40; //10;
/**
* Importance of relative mobility (mobility of other pieces that may not be able to play because of a compulsory move)
*/
public static final int RELATIVE_MOBILITY_VALUE = 40; //5;
//with less than that many pawns on one side, the computer will enter endgame mode
public static final int ENDGAME_PAWNS = 3;
//with less than that many pieces on one side, the computer will enter endgame mode
public static final int ENDGAME_PIECES = 8;
public static final int[] SQUARE_WEIGHT = {
/* -20, -10, -10, -10, -10, -10, -10, -20,
-10, 0, 3, 5, 5, 3, 0, -10,
-10, 2, 15, 15, 15, 15, 2, -10,
-10, 7, 15, 25, 25, 15, 7, -10,
-10, 7, 15, 25, 25, 15, 7, -10,
-10, 2, 15, 15, 15, 15, 2, -10,
-10, 0, 3, 5, 5, 3, 0, -10,
-20, -10, -10, -10, -10, -10, -10, -20*/
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10
};
/*======*
* DATA *
*======*/
@ -605,18 +570,32 @@ public class Board {
}
}
//calculates player's mobility
public int mobility(int colour) throws NotAValidSquare {
//calculates player's mobility in the endgame
private int mobilityEnd(int colour) throws NotAValidSquare {
Board thisCopy = new Board(this);
thisCopy.currentPlayer=colour;
Rules.legalMovesForPlayer(thisCopy);
if (Rules.getLegalMovesCapture().size()!=0) {
return Rules.getLegalMovesCapture().size()*ConfigFile.getPrimaryMobilityValueEndgame()
+Rules.getLegalMovesNonCapture().size()*ConfigFile.getScondaryMobilityValueEndgame();
} else {
return Rules.getLegalMovesNonCapture().size()*ConfigFile.getPrimaryMobilityValueEndgame();
}
}
//calculates player's mobility in the midgame
public int mobilityMiddle(int colour) throws NotAValidSquare {
Board thisCopy = new Board(this);
thisCopy.currentPlayer=colour;
Rules.legalMovesForPlayer(thisCopy);
if (Rules.getLegalMovesCapture().size()!=0) {
return Rules.getLegalMovesCapture().size()*REAL_MOBILITY_VALUE
+Rules.getLegalMovesNonCapture().size()*RELATIVE_MOBILITY_VALUE;
return Rules.getLegalMovesCapture().size()*ConfigFile.getPrimaryMobilityValueMidgame()
+Rules.getLegalMovesNonCapture().size()*ConfigFile.getPrimaryMobilityValueMidgame();
} else {
return Rules.getLegalMovesNonCapture().size()*REAL_MOBILITY_VALUE;
return Rules.getLegalMovesNonCapture().size()*ConfigFile.getPrimaryMobilityValueMidgame();
}
}
private void evaluateNewBoardValue (Move move) throws NotAValidSquare {
@ -629,12 +608,21 @@ public class Board {
//this is a very very basic evaluation function that will be changed.
//boardValue = numberOfBlackPieces - numberOfWhitePieces;
boardValue = 0;
/*if((numberOfPieces[Piece.BLACK_PAWN] <= ENDGAME_PAWNS) || (numberOfPieces[Piece.WHITE_PAWN] <= ENDGAME_PAWNS)
|| (numberOfPieces[Piece.BLACK_PIECES] <= ENDGAME_PIECES) || (numberOfPieces[Piece.WHITE_PIECES] <= ENDGAME_PIECES) ) {
if((numberOfPieces[Piece.BLACK_PAWN] <= ConfigFile.getEndGamePawns()) || (numberOfPieces[Piece.WHITE_PAWN] <= ConfigFile.getEndGamePawns())
|| (numberOfPieces[Piece.BLACK_PIECES] <= ConfigFile.getEndGamePieces()) || (numberOfPieces[Piece.WHITE_PIECES] <= ConfigFile.getEndGamePieces()) ) {
//System.out.println("Playing endgame");
for (int i = Piece.OFFSET; i<=Piece.MAX_PIECE_NUMBER; i++) {
/*for (int i = Piece.OFFSET; i<=Piece.MAX_PIECE_NUMBER; i++) {
boardValue += numberOfPieces[i]*Piece.PIECE_VALUE_ENDGAME[i];
}*/
for(int squareNb = 0; squareNb<NB_OF_SQUARES; squareNb++) {
Piece pieceOnSquare = getPiece(new Square(squareNb));
if(pieceOnSquare.getPieceNumber()!=Piece.NONE) {
//System.out.println(SQUARE_WEIGHT[squareNb]);
boardValue += ConfigFile.getSquareWeightEndgame()[squareNb]*
ConfigFile.getPieceValuesEndgame()[pieceOnSquare.getPieceNumber()];
}
}
boardValue += ((mobilityEnd(Piece.WHITE)-mobilityEnd(Piece.BLACK)));
} else {
//System.out.println("Playing midgame");
/*for (int i = Piece.OFFSET; i<=Piece.MAX_PIECE_NUMBER; i++) {
@ -644,11 +632,12 @@ public class Board {
Piece pieceOnSquare = getPiece(new Square(squareNb));
if(pieceOnSquare.getPieceNumber()!=Piece.NONE) {
//System.out.println(SQUARE_WEIGHT[squareNb]);
boardValue += SQUARE_WEIGHT[squareNb]*Piece.PIECE_VALUE_MIDDLEGAME[pieceOnSquare.getPieceNumber()];
boardValue += ConfigFile.getSquareWeightMidgame()[squareNb]*
ConfigFile.getPieceValuesMidgame()[pieceOnSquare.getPieceNumber()];
}
}
//boardValue += ((mobility(Piece.WHITE)-mobility(Piece.BLACK)));
//}
boardValue += ((mobilityMiddle(Piece.WHITE)-mobilityMiddle(Piece.BLACK)));
}
}
}
if (!Rules.isThereALegalMovesForPlayer(this)) {

3
src/suicideChess/ComputerPlayer.java

@ -170,9 +170,6 @@ public class ComputerPlayer {
System.out.println("Found "+bestMoves.size()+" good moves.");
}
System.out.println(((bitboard.mobility(Piece.WHITE))));
System.out.println(((-bitboard.mobility(Piece.BLACK))));
return bestMove;
}

344
src/suicideChess/ConfigFile.java

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
/**
* This class is used to read configuration settings for the AI
@ -15,95 +14,169 @@ import java.util.ArrayList;
*/
public class ConfigFile {
private static int[] pieceValuesMiddle;
private static int[] pieceValuesEnd;
private static int[] squareWeightMiddle;
private static int[] squareWeightEnd;
private static int primaryMobilityValueMiddle;
private static int primaryMobilityValueEnd;
private static int secondaryMobilityValueMiddle;
private static int secondaryMobilityValueEnd;
private static int[] pieceValuesMidgame;
private static int[] pieceValuesEndgame;
private static int[] squareWeightMidgame;
private static int[] squareWeightEndgame;
private static int primaryMobilityValueMidgame;
private static int primaryMobilityValueEndgame;
private static int secondaryMobilityValueMidgame;
private static int secondaryMobilityValueEndgame;
private static int endGamePawns;
private static int endGamePieces;
/**
* The pieces value in the middlegame
*/
public static int[] getPieceValuesMiddle() {
return pieceValuesMiddle;
public static int[] getPieceValuesMidgame() {
return pieceValuesMidgame;
}
/**
* The pieces value in the end
*/
public static int[] getPieceValuesEnd() {
return pieceValuesEnd;
}
/**
* The weight of each square in the middle game
*/
public static int[] getSquareWeightMiddle() {
return squareWeightMiddle;
}
/**
* The weight of each square in the endgame
*/
public static int[] getSquareWeightEnd() {
return squareWeightEnd;
}
/**
* The primary mobility value (nb of possible legal moves) in the midgame
*/
public static int getPrimaryMobilityValueMiddle() {
return primaryMobilityValueMiddle;
}
/**
* The primary mobility value (nb of possible legal moves) in the endgame
*/
public static int getPrimaryMobilityValueEnd() {
return primaryMobilityValueEnd;
}
/**
* The secondary mobility value (nb of possible but not legal moves) in the midgame
*/
public static int getSecondaryMobilityValueMiddle() {
return secondaryMobilityValueMiddle;
}
/**
* The secondary mobility value (nb of possible but not legal moves)
*/
public static int getScondaryMobilityValueEnd() {
return secondaryMobilityValueEnd;
}
/**
* Number of pawns on the opposite side before entering endgame
*/
public static int getEndGamePawns() {
return endGamePawns;
}
/**
* Number of pieces on the opposite site before entering endgame
*/
public static int getEndGamePieces() {
return endGamePieces;
}
public static int[] getPieceValuesEndgame() {
return pieceValuesEndgame;
}
/**
* The weight of each square in the middle game
*/
public static int[] getSquareWeightMidgame() {
return squareWeightMidgame;
}
/**
* The weight of each square in the endgame
*/
public static int[] getSquareWeightEndgame() {
return squareWeightEndgame;
}
/**
* The primary mobility value (nb of possible legal moves) in the midgame
*/
public static int getPrimaryMobilityValueMidgame() {
return primaryMobilityValueMidgame;
}
/**
* The primary mobility value (nb of possible legal moves) in the endgame
*/
public static int getPrimaryMobilityValueEndgame() {
return primaryMobilityValueEndgame;
}
/**
* The secondary mobility value (nb of possible but not legal moves) in the midgame
*/
public static int getSecondaryMobilityValueMidgame() {
return secondaryMobilityValueMidgame;
}
/**
* The secondary mobility value (nb of possible but not legal moves)
*/
public static int getScondaryMobilityValueEndgame() {
return secondaryMobilityValueEndgame;
}
/**
* Number of pawns on the opposite side before entering endgame
*/
public static int getEndGamePawns() {
return endGamePawns;
}
/**
* Number of pieces on the opposite site before entering endgame
*/
public static int getEndGamePieces() {
return endGamePieces;
}
/**
* Loads the default configfile
*/
public static void load() {
loadFile("config");
}
public static void load(String file) {
/**
* Loads a configuration file for the AI
* @param configFile
*/
public static void loadFile(String configFile) {
String configMessage = "Loaded custom : ";
// for displaying errors
String currentLine="";
int currentLineNumber=0;
//declared here only to make visible to finally clause
BufferedReader problemReader = null;
try {
problemReader = new BufferedReader(new FileReader(file));
problemReader = new BufferedReader(new FileReader(configFile));
String line = null; //not declared within while loop
while ((line = problemReader.readLine()) != null) {
if (!line.startsWith("#")) { //ignore lines starting with # (comments)
book.add(line.split("\\s")); //each space defines a new move
}
currentLine=line;
currentLineNumber++;
if(line.startsWith("pvm")) {
String[] result=line.split("\t");
//start from 1 not to include "pvm"
for(int i=1; i<result.length; i++) {
pieceValuesMidgame[2*i]=Integer.parseInt(result[i]); //white pieces
pieceValuesMidgame[2*i+1]=-Integer.parseInt(result[i]); //black pieces
}
configMessage += "pvm ";
} else if(line.startsWith("pve")) {
String[] result=line.split("\t");
//start from 1 not to include "pvm"
for(int i=1; i<result.length; i++) {
pieceValuesEndgame[2*i]=Integer.parseInt(result[i]); //white pieces
pieceValuesEndgame[2*i+1]=-Integer.parseInt(result[i]); //black pieces
}
configMessage += "pve ";
} else if(line.startsWith("swm")) {
for(int rank=0; rank<Board.NB_OF_RANKS; rank++) {
if ((line = problemReader.readLine()) != null) {
String [] result=line.split("\t");
for (int file=0; file<Board.NB_OF_FILES; file++) {
squareWeightMidgame[file+Board.NB_OF_FILES*rank]=Integer.parseInt(result[file]);
}
}
}
configMessage += "swm ";
} else if(line.startsWith("swe")) {
for(int rank=0; rank<Board.NB_OF_RANKS; rank++) {
if ((line = problemReader.readLine()) != null) {
String [] result=line.split("\t");
for (int file=0; file<Board.NB_OF_FILES; file++) {
squareWeightEndgame[file+Board.NB_OF_FILES*rank]=Integer.parseInt(result[file]);
}
}
}
configMessage += "swe ";
} else if(line.startsWith("mvm")) {
String [] result=line.split("\t");
primaryMobilityValueMidgame = Integer.parseInt(result[1]);
secondaryMobilityValueMidgame = Integer.parseInt(result[2]);
configMessage += "mvm ";
} else if(line.startsWith("mve")) {
String [] result=line.split("\t");
primaryMobilityValueEndgame = Integer.parseInt(result[1]);
secondaryMobilityValueEndgame = Integer.parseInt(result[2]);
configMessage += "mve ";
} else if(line.startsWith("npp")) {
String [] result=line.split("\t");
endGamePawns = Integer.parseInt(result[1]);
endGamePieces = Integer.parseInt(result[2]);
configMessage += "npp ";
}
}
System.out.println(configMessage);
}
catch (FileNotFoundException e) {
System.out.println("File '"+file+"' not found. Opening book won't be available.");
System.out.println("File '"+configFile+"' not found. Opening book won't be available.");
}
catch (IOException e){
System.out.println("Error reading file '"+file+"'.");
System.out.println("Error reading file '"+configFile+"'.");
}
catch (NumberFormatException e){
System.out.println("Error parsing the config file on line "+currentLineNumber+". Format error: "+currentLine+".");
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("Error parsing the config file on line "+currentLineNumber+". Not enough values: "+currentLine+".");
}
finally {
try {
@ -115,36 +188,115 @@ public class ConfigFile {
ex.printStackTrace();
}
}
System.out.println(book.size()+" opening variants loaded.");
}
static {
pieceValuesMiddle[Piece.WHITE_KING]=-100; //500
pieceValuesMiddle[Piece.WHITE_QUEEN]=-100; //900
pieceValuesMiddle[Piece.WHITE_ROOK]=-100; //350
pieceValuesMiddle[Piece.WHITE_KNIGHT]=-100; //300
pieceValuesMiddle[Piece.WHITE_BISHOP]= -100; //started with -100, -400, -200
pieceValuesMiddle[Piece.WHITE_PAWN]= -100; //started with 100
pieceValuesMiddle[Piece.BLACK_KING]=-pieceValuesMiddle[Piece.WHITE_KING];
pieceValuesMiddle[Piece.BLACK_QUEEN]=-pieceValuesMiddle[Piece.WHITE_QUEEN];
pieceValuesMiddle[Piece.BLACK_ROOK]=-pieceValuesMiddle[Piece.WHITE_ROOK];
pieceValuesMiddle[Piece.BLACK_KNIGHT]=-pieceValuesMiddle[Piece.WHITE_KNIGHT];
pieceValuesMiddle[Piece.BLACK_BISHOP]=-pieceValuesMiddle[Piece.WHITE_BISHOP];
pieceValuesMiddle[Piece.BLACK_PAWN]=-pieceValuesMiddle[Piece.WHITE_PAWN];
pieceValuesEnd[Piece.WHITE_KING]=-400;
pieceValuesEnd[Piece.WHITE_QUEEN]=-400;
pieceValuesEnd[Piece.WHITE_ROOK]=-100;
pieceValuesEnd[Piece.WHITE_KNIGHT]=-700;
pieceValuesEnd[Piece.WHITE_BISHOP]=-400;
pieceValuesEnd[Piece.WHITE_PAWN]=-900;
pieceValuesEnd[Piece.BLACK_KING]=-pieceValuesEnd[Piece.WHITE_KING];
pieceValuesEnd[Piece.BLACK_QUEEN]=-pieceValuesEnd[Piece.WHITE_QUEEN];
pieceValuesEnd[Piece.BLACK_ROOK]=-pieceValuesEnd[Piece.WHITE_ROOK];
pieceValuesEnd[Piece.BLACK_KNIGHT]=-pieceValuesEnd[Piece.WHITE_KNIGHT];
pieceValuesEnd[Piece.BLACK_BISHOP]=-pieceValuesEnd[Piece.WHITE_BISHOP];
pieceValuesEnd[Piece.BLACK_PAWN]=-pieceValuesEnd[Piece.WHITE_PAWN];
public static void display() {
String displayConfig;
System.out.println("==================== Current configuration ====================");
displayConfig="pvm\t";
for(int i=0; i<pieceValuesMidgame.length; i++) {
displayConfig+=pieceValuesMidgame[i]+"\t";
}
System.out.println(displayConfig);
displayConfig="pve\t";
for(int i=0; i<pieceValuesEndgame.length; i++) {
displayConfig+=pieceValuesEndgame[i]+"\t";
}
System.out.println(displayConfig);
System.out.println("swm");
for(int rank=0; rank<Board.NB_OF_RANKS; rank++) {
displayConfig = "";
for (int file=1; file<=Board.NB_OF_FILES; file++) {
displayConfig+=squareWeightMidgame[file+Board.NB_OF_FILES*rank-1]+"\t";
}
System.out.println(displayConfig);
}
System.out.println("swe");
for(int rank=0; rank<Board.NB_OF_RANKS; rank++) {
displayConfig = "";
for (int file=1; file<=Board.NB_OF_FILES; file++) {
displayConfig+=squareWeightEndgame[file+Board.NB_OF_FILES*rank-1]+"\t";
}
System.out.println(displayConfig);
}
displayConfig="mvm\t";
displayConfig+= primaryMobilityValueMidgame+"\t";
displayConfig+= secondaryMobilityValueMidgame+"\t";
System.out.println(displayConfig);
displayConfig="mve\t";
displayConfig+= primaryMobilityValueEndgame+"\t";
displayConfig+= secondaryMobilityValueEndgame+"\t";
System.out.println(displayConfig);
displayConfig="npp\t";
displayConfig+= endGamePawns+"\t";
displayConfig+= endGamePieces+"\t";
System.out.println(displayConfig);
System.out.println("===============================================================");
}
static { //default values for everything
pieceValuesMidgame = new int[Piece.MAX_PIECE_NUMBER+1];
pieceValuesEndgame = new int[Piece.MAX_PIECE_NUMBER+1];
pieceValuesMidgame[Piece.WHITE_KING]=-100; //500
pieceValuesMidgame[Piece.WHITE_QUEEN]=-100; //900
pieceValuesMidgame[Piece.WHITE_ROOK]=-100; //350
pieceValuesMidgame[Piece.WHITE_KNIGHT]=-100; //300
pieceValuesMidgame[Piece.WHITE_BISHOP]= -100; //started with -100, -400, -200
pieceValuesMidgame[Piece.WHITE_PAWN]= -100; //started with 100
pieceValuesMidgame[Piece.BLACK_KING]=-pieceValuesMidgame[Piece.WHITE_KING];
pieceValuesMidgame[Piece.BLACK_QUEEN]=-pieceValuesMidgame[Piece.WHITE_QUEEN];
pieceValuesMidgame[Piece.BLACK_ROOK]=-pieceValuesMidgame[Piece.WHITE_ROOK];
pieceValuesMidgame[Piece.BLACK_KNIGHT]=-pieceValuesMidgame[Piece.WHITE_KNIGHT];
pieceValuesMidgame[Piece.BLACK_BISHOP]=-pieceValuesMidgame[Piece.WHITE_BISHOP];
pieceValuesMidgame[Piece.BLACK_PAWN]=-pieceValuesMidgame[Piece.WHITE_PAWN];
pieceValuesEndgame[Piece.WHITE_KING]=-400;
pieceValuesEndgame[Piece.WHITE_QUEEN]=-400;
pieceValuesEndgame[Piece.WHITE_ROOK]=-100;
pieceValuesEndgame[Piece.WHITE_KNIGHT]=-700;
pieceValuesEndgame[Piece.WHITE_BISHOP]=-400;
pieceValuesEndgame[Piece.WHITE_PAWN]=-900;
pieceValuesEndgame[Piece.BLACK_KING]=-pieceValuesEndgame[Piece.WHITE_KING];
pieceValuesEndgame[Piece.BLACK_QUEEN]=-pieceValuesEndgame[Piece.WHITE_QUEEN];
pieceValuesEndgame[Piece.BLACK_ROOK]=-pieceValuesEndgame[Piece.WHITE_ROOK];
pieceValuesEndgame[Piece.BLACK_KNIGHT]=-pieceValuesEndgame[Piece.WHITE_KNIGHT];
pieceValuesEndgame[Piece.BLACK_BISHOP]=-pieceValuesEndgame[Piece.WHITE_BISHOP];
pieceValuesEndgame[Piece.BLACK_PAWN]=-pieceValuesEndgame[Piece.WHITE_PAWN];
squareWeightMidgame = new int[]{
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10
};
squareWeightEndgame = new int[]{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
primaryMobilityValueMidgame = 40;
primaryMobilityValueEndgame = 40;
secondaryMobilityValueMidgame = 40; //5;
secondaryMobilityValueEndgame = 40;
endGamePawns = 3;
endGamePieces = 8;
}
}

57
src/suicideChess/Piece.java

@ -72,62 +72,7 @@ public class Piece {
public static final char BLACK_BISHOP_CHAR='b';
public static final char BLACK_KNIGHT_CHAR='n';
public static final char BLACK_ROOK_CHAR='r';
public static final char BLACK_PAWN_CHAR='p';
public static final int[] PIECE_VALUE_MIDDLEGAME = new int[Piece.MAX_PIECE_NUMBER+1];
public static final int[] PIECE_VALUE_ENDGAME = new int[Piece.MAX_PIECE_NUMBER+1];
static {
/* PIECE_VALUE_MIDDLEGAME[WHITE_KING]=500;
PIECE_VALUE_MIDDLEGAME[WHITE_QUEEN]=900;
PIECE_VALUE_MIDDLEGAME[WHITE_ROOK]=350;
PIECE_VALUE_MIDDLEGAME[WHITE_KNIGHT]=300;
PIECE_VALUE_MIDDLEGAME[WHITE_BISHOP]= -100; //started with -100, -400, -200
PIECE_VALUE_MIDDLEGAME[WHITE_PAWN]= 300; //started with 100
PIECE_VALUE_MIDDLEGAME[BLACK_KING]=-PIECE_VALUE_MIDDLEGAME[WHITE_KING];
PIECE_VALUE_MIDDLEGAME[BLACK_QUEEN]=-PIECE_VALUE_MIDDLEGAME[WHITE_QUEEN];
PIECE_VALUE_MIDDLEGAME[BLACK_ROOK]=-PIECE_VALUE_MIDDLEGAME[WHITE_ROOK];
PIECE_VALUE_MIDDLEGAME[BLACK_KNIGHT]=-PIECE_VALUE_MIDDLEGAME[WHITE_KNIGHT];
PIECE_VALUE_MIDDLEGAME[BLACK_BISHOP]=-PIECE_VALUE_MIDDLEGAME[WHITE_BISHOP];
PIECE_VALUE_MIDDLEGAME[BLACK_PAWN]=-PIECE_VALUE_MIDDLEGAME[WHITE_PAWN];
PIECE_VALUE_ENDGAME[WHITE_KING]=-400;
PIECE_VALUE_ENDGAME[WHITE_QUEEN]=-400;
PIECE_VALUE_ENDGAME[WHITE_ROOK]=-100;
PIECE_VALUE_ENDGAME[WHITE_KNIGHT]=-700;
PIECE_VALUE_ENDGAME[WHITE_BISHOP]=-400;
PIECE_VALUE_ENDGAME[WHITE_PAWN]=-900;
PIECE_VALUE_ENDGAME[BLACK_KING]=-PIECE_VALUE_ENDGAME[WHITE_KING];
PIECE_VALUE_ENDGAME[BLACK_QUEEN]=-PIECE_VALUE_ENDGAME[WHITE_QUEEN];
PIECE_VALUE_ENDGAME[BLACK_ROOK]=-PIECE_VALUE_ENDGAME[WHITE_ROOK];
PIECE_VALUE_ENDGAME[BLACK_KNIGHT]=-PIECE_VALUE_ENDGAME[WHITE_KNIGHT];
PIECE_VALUE_ENDGAME[BLACK_BISHOP]=-PIECE_VALUE_ENDGAME[WHITE_BISHOP];
PIECE_VALUE_ENDGAME[BLACK_PAWN]=-PIECE_VALUE_ENDGAME[WHITE_PAWN]; */
PIECE_VALUE_MIDDLEGAME[WHITE_KING]=-100;
PIECE_VALUE_MIDDLEGAME[WHITE_QUEEN]=-100;
PIECE_VALUE_MIDDLEGAME[WHITE_ROOK]=-100;
PIECE_VALUE_MIDDLEGAME[WHITE_KNIGHT]=-100;
PIECE_VALUE_MIDDLEGAME[WHITE_BISHOP]= -100; //started with -100, -400, -200
PIECE_VALUE_MIDDLEGAME[WHITE_PAWN]= -100; //started with 100
PIECE_VALUE_MIDDLEGAME[BLACK_KING]=-PIECE_VALUE_MIDDLEGAME[WHITE_KING];
PIECE_VALUE_MIDDLEGAME[BLACK_QUEEN]=-PIECE_VALUE_MIDDLEGAME[WHITE_QUEEN];
PIECE_VALUE_MIDDLEGAME[BLACK_ROOK]=-PIECE_VALUE_MIDDLEGAME[WHITE_ROOK];
PIECE_VALUE_MIDDLEGAME[BLACK_KNIGHT]=-PIECE_VALUE_MIDDLEGAME[WHITE_KNIGHT];
PIECE_VALUE_MIDDLEGAME[BLACK_BISHOP]=-PIECE_VALUE_MIDDLEGAME[WHITE_BISHOP];
PIECE_VALUE_MIDDLEGAME[BLACK_PAWN]=-PIECE_VALUE_MIDDLEGAME[WHITE_PAWN];
PIECE_VALUE_ENDGAME[WHITE_KING]=-400;
PIECE_VALUE_ENDGAME[WHITE_QUEEN]=-400;
PIECE_VALUE_ENDGAME[WHITE_ROOK]=-100;
PIECE_VALUE_ENDGAME[WHITE_KNIGHT]=-700;
PIECE_VALUE_ENDGAME[WHITE_BISHOP]=-400;
PIECE_VALUE_ENDGAME[WHITE_PAWN]=-900;
PIECE_VALUE_ENDGAME[BLACK_KING]=-PIECE_VALUE_ENDGAME[WHITE_KING];
PIECE_VALUE_ENDGAME[BLACK_QUEEN]=-PIECE_VALUE_ENDGAME[WHITE_QUEEN];
PIECE_VALUE_ENDGAME[BLACK_ROOK]=-PIECE_VALUE_ENDGAME[WHITE_ROOK];
PIECE_VALUE_ENDGAME[BLACK_KNIGHT]=-PIECE_VALUE_ENDGAME[WHITE_KNIGHT];
PIECE_VALUE_ENDGAME[BLACK_BISHOP]=-PIECE_VALUE_ENDGAME[WHITE_BISHOP];
PIECE_VALUE_ENDGAME[BLACK_PAWN]=-PIECE_VALUE_ENDGAME[WHITE_PAWN];
}
public static final char BLACK_PAWN_CHAR='p';
/*==============*
* PRIVATE DATA *

38
src/suicideChess/SuicideChess.java

@ -37,7 +37,7 @@ public class SuicideChess {
/**
* The name to be displayed
*/
public static final String NAME = "djib's SuShi v0.8.0";
public static final String NAME = "djib's SuShi v0.8.9";
/**
* Displays informations in the console.
@ -153,11 +153,13 @@ public class SuicideChess {
System.out.println("Welcome to SuicideChess "+SuicideChess.NAME+"!\n");
System.out.println("Type 'help' for a quick help.");
System.out.println("If you want a graphical interface, you can use XBoard, WinBoard or any compatible program.");
System.out.println();
OpeningBook.load();
SuicideProblems.load();
ConfigFile.load();
System.out.println();
BufferedReader moveInput = new BufferedReader(new InputStreamReader(System.in));
@ -176,8 +178,32 @@ public class SuicideChess {
try {
String whatMove= moveInput.readLine();
boolean playedALegalMove = false;
if (whatMove.startsWith("problem")) { //special case for problems
if (whatMove.startsWith("help")) {
System.out.println("==================== Quick help ====================\nEnter moves in SAN notation : e2e3, e7e8r, ...\n");
System.out.println("new\t\t\tcreates a new game");
System.out.println("quit\t\t\tquits the game");
System.out.println("go\t\t\twill let the computer play the current player");
System.out.println("hint\t\t\treturns a legal move for current position");
System.out.println("undo\t\t\tundoes a half move (one side)");
System.out.println("remove\t\t\tundoes a full move");
System.out.println("force\t\t\tthe computer will check moves but not play");
System.out.println();
System.out.println("setboard FEN\t\tsets the board according to the FEN position");
System.out.println("sd N\t\t\tsets the search depth to n");
System.out.println("bk\t\t\tdisplays available openbook moves for current position");
System.out.println("post\t\t\tdisplays thinking output");
System.out.println("nopost\t\t\tdo not display thinking output");
System.out.println();
System.out.println("problem\t\t\tdisplays the number of available problems");
System.out.println("problem auto\t\tlets the computer play automatically on each problem");
System.out.println("problem N\t\tloads problem number N");
System.out.println("problem load FILENAME\tloads the problem file FILENAME");
System.out.println("config\t\t\t displays current configuration");
System.out.println("config FILENAME\t\tloads a configuration from FILENAME");
System.out.println();
}else if (whatMove.startsWith("problem")) { //special case for problems
if(whatMove.length()==7) {
System.out.println("There are "+SuicideProblems.numberOfProblems()+" problems.");
} else if (whatMove.substring(8).equals("auto")) {
@ -195,6 +221,12 @@ public class SuicideChess {
System.out.println("Not a valid number: "+ whatMove.substring(8));
}
}
} else if (whatMove.startsWith("config")) { //special case for loading other configuration files
if(whatMove.length()==6) {
ConfigFile.display();
} else if ((whatMove.length()>6)) {
ConfigFile.loadFile(whatMove.substring(7));
}
} else if (whatMove.startsWith("asciiplay")) {
asciiGame=true;
bitboard.display();

Loading…
Cancel
Save