From a0ee66638d8dfed7df03c30857bf0d8d7468e447 Mon Sep 17 00:00:00 2001 From: djib Date: Tue, 4 Jul 2006 01:45:39 +0000 Subject: [PATCH] Version 0.8.0 ============= Just before creating the external config file --- src/suicideChess/Board.java | 37 ++++--- src/suicideChess/ComputerPlayer.java | 17 +++ src/suicideChess/ConfigFile.java | 150 +++++++++++++++++++++++++++ src/suicideChess/OpeningBook.java | 5 +- src/suicideChess/Piece.java | 12 +-- src/suicideChess/SuicideChess.java | 28 ++++- src/suicideChess/XBoardProtocol.java | 20 +++- 7 files changed, 241 insertions(+), 28 deletions(-) create mode 100644 src/suicideChess/ConfigFile.java diff --git a/src/suicideChess/Board.java b/src/suicideChess/Board.java index ab86047..65af16d 100644 --- a/src/suicideChess/Board.java +++ b/src/suicideChess/Board.java @@ -68,11 +68,11 @@ 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 = 1000; //10; + 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 = 1000; //5; + 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; @@ -81,14 +81,22 @@ public class Board { public static final int ENDGAME_PIECES = 8; public static final int[] SQUARE_WEIGHT = { - -20, -10, -10, -10, -10, -10, -10, -20, +/* -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 + -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 }; @@ -621,7 +629,7 @@ 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) + /*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) ) { //System.out.println("Playing endgame"); for (int i = Piece.OFFSET; i<=Piece.MAX_PIECE_NUMBER; i++) { @@ -629,17 +637,18 @@ 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]; - for(int squareNb = 0; squareNb=nbOfMovesThatHaveBeenPlayed)) { + if(validMoves[i] && (book.get(i).length>nbOfMovesThatHaveBeenPlayed)) { if (!(book.get(i)[nbOfMovesThatHaveBeenPlayed].equals(move.toString()))) { validMoves[i]=false; //this branch is not valid anymore } @@ -107,7 +107,7 @@ public class OpeningBook { for(int j=nbOfMovesThatHaveBeenPlayed; j=12)&&(whatMove.substring(8,12).equals("load"))) { SuicideProblems.suicideProblemsLoad(whatMove.substring(13)); } else { + openingPhase=false; try { int problemNb = Integer.parseInt(whatMove.substring(8)); bitboard=new Board(SuicideProblems.getProblemNumber(problemNb)); @@ -204,6 +208,11 @@ public class SuicideChess { switch (xBoardCommand) { case XBoardProtocol.XBOARD: + asciiGame=false; + break; + case XBoardProtocol.ACCEPTED: + break; + case XBoardProtocol.VARIANT_SUICIDE: break; case XBoardProtocol.PROTOVER: XBoardProtocol.initialise(); @@ -238,7 +247,6 @@ public class SuicideChess { System.out.println("Hint: "+ComputerPlayer.doRandomMove(bitboard)); break; case XBoardProtocol.FORCE: - openingPhase=false; //don't know what will happen next computerPlaying = false; break; case XBoardProtocol.PING: @@ -273,6 +281,17 @@ public class SuicideChess { System.out.println("Not a valid depth: "+ whatMove.substring(3)); } break; + case XBoardProtocol.BOOK: + //display book moves + boolean temp = postThinkingOutput; + postThinkingOutput=true; + try { + OpeningBook.getMove(bitboard); + } catch (NoOpeningMovesLeft e) { + openingPhase = false; + } + postThinkingOutput=temp; + break; case XBoardProtocol.UNKNOWN: if (acceptedUsermove) { System.out.println("Error (unknown command): "+whatMove); @@ -365,6 +384,7 @@ public class SuicideChess { if(openingPhase) { try { computerMove = OpeningBook.getMove(bitboard); + OpeningBook.played(computerMove); } catch (NoOpeningMovesLeft e) { openingPhase = false; computerMove = ComputerPlayer.doAlphaBetaMove(bitboard); diff --git a/src/suicideChess/XBoardProtocol.java b/src/suicideChess/XBoardProtocol.java index 85cbb9f..4dda737 100644 --- a/src/suicideChess/XBoardProtocol.java +++ b/src/suicideChess/XBoardProtocol.java @@ -87,9 +87,21 @@ public class XBoardProtocol { */ public static final int SETBOARD = 17; /** - * XBoard send a signal to limit ply depth + * XBoard sends a signal to limit ply depth */ public static final int SETPLY = 18; + /** + * XBoard sends an accepted signal + */ + public static final int ACCEPTED = 19; + /** + * XBoard sends an 'variant suicide' signal + */ + public static final int VARIANT_SUICIDE = 20; + /** + * XBoard sends a book request + */ + public static final int BOOK = 21; /** * Unknown command */ @@ -166,6 +178,12 @@ public class XBoardProtocol { return SETBOARD; } else if (command.startsWith("sd")) { return SETPLY; + } else if (command.startsWith("accepted")) { + return ACCEPTED; + } else if (command.equals("variant suicide")) { + return VARIANT_SUICIDE; + } else if (command.equals("bk")) { + return BOOK; } return UNKNOWN;