diff --git a/src/suicideChess/Board.java b/src/suicideChess/Board.java index 9fcfabb..ab86047 100644 --- a/src/suicideChess/Board.java +++ b/src/suicideChess/Board.java @@ -32,12 +32,6 @@ public class Board { private static final int NB_OF_BITBOARDS = 14; - //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 = 6; - @SuppressWarnings("serial") public class NoPieceOnSquare extends Exception { NoPieceOnSquare(String s) { super(s); }; @@ -74,16 +68,34 @@ public class Board { /** * 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 = 10; + public static final int REAL_MOBILITY_VALUE = 1000; //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 = 5; - + public static final int RELATIVE_MOBILITY_VALUE = 1000; //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 + }; + + /*======* * DATA * *======*/ - + //The following table is used to map squares to bits protected static long mapSquaresToBits[]; @@ -421,8 +433,7 @@ public class Board { public Square getEnPassantSquare() { return enPassantSquare; } - - + /** * This function returns an integer representing the result of the static evaluation function * for the current board @@ -619,7 +630,13 @@ public class Board { } else { //System.out.println("Playing midgame"); for (int i = Piece.OFFSET; i<=Piece.MAX_PIECE_NUMBER; i++) { - boardValue += numberOfPieces[i]*Piece.PIECE_VALUE_MIDDLEGAME[i]; + //boardValue += numberOfPieces[i]*Piece.PIECE_VALUE_MIDDLEGAME[i]; + for(int squareNb = 0; squareNb book; //each arrayList is an array of one possible opening moves (index 0 is the first move). + static void load() { openingBookLoad("openbook"); reset();} //initialise with file 'problems' if found in current directory + + /** + * This function is used to load an openingbook file + * @param file + */ + public static void openingBookLoad(String file) { + //declared here only to make visible to finally clause + BufferedReader problemReader = null; + book = new ArrayList(); + try { + problemReader = new BufferedReader(new FileReader(file)); + 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 + } + } + } + catch (FileNotFoundException e) { + System.out.println("File '"+file+"' not found. Opening book won't be available."); + } + catch (IOException e){ + System.out.println("Error reading file '"+file+"'."); + } + finally { + try { + if (problemReader!= null) { + problemReader.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + System.out.println(book.size()+" opening variants loaded."); + } + + // this variable is the currentBook + private static boolean[] validMoves; + + /** + * This function should be called everytime a game is reset + */ + public static void reset() { + validMoves = new boolean[book.size()]; + for (int i=0; i=nbOfMovesThatHaveBeenPlayed)) { + if (!(book.get(i)[nbOfMovesThatHaveBeenPlayed].equals(move.toString()))) { + validMoves[i]=false; //this branch is not valid anymore + } + } + } + nbOfMovesThatHaveBeenPlayed++; + } + + + public static Move getMove(Board bitboard) throws NotAValidMoveException, NotAValidSquare, NoOpeningMovesLeft { + ArrayList possibleMoves = new ArrayList(); + for (int i=0; inbOfMovesThatHaveBeenPlayed)) { + possibleMoves.add(new Move(book.get(i)[nbOfMovesThatHaveBeenPlayed],bitboard)); + if (SuicideChess.postThinkingOutput()) { + String formatVariation = ""; + for(int j=nbOfMovesThatHaveBeenPlayed; j