From f67d82d1290713a26f7c2904676ac96dec1c9b50 Mon Sep 17 00:00:00 2001 From: djib Date: Tue, 4 Jul 2006 11:55:00 +0000 Subject: [PATCH] Version 0.8.9 ============= Added external config file -> the resulting program seems a lot faster !!! Added help. --- src/suicideChess/Board.java | 81 +++---- src/suicideChess/ComputerPlayer.java | 3 - src/suicideChess/ConfigFile.java | 344 +++++++++++++++++++-------- src/suicideChess/Piece.java | 57 +---- src/suicideChess/SuicideChess.java | 38 ++- 5 files changed, 319 insertions(+), 204 deletions(-) diff --git a/src/suicideChess/Board.java b/src/suicideChess/Board.java index 65af16d..5ca18ca 100644 --- a/src/suicideChess/Board.java +++ b/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,19 +570,33 @@ 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()*REAL_MOBILITY_VALUE - +Rules.getLegalMovesNonCapture().size()*RELATIVE_MOBILITY_VALUE; + return Rules.getLegalMovesCapture().size()*ConfigFile.getPrimaryMobilityValueEndgame() + +Rules.getLegalMovesNonCapture().size()*ConfigFile.getScondaryMobilityValueEndgame(); } else { - return Rules.getLegalMovesNonCapture().size()*REAL_MOBILITY_VALUE; + 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()*ConfigFile.getPrimaryMobilityValueMidgame() + +Rules.getLegalMovesNonCapture().size()*ConfigFile.getPrimaryMobilityValueMidgame(); + } else { + return Rules.getLegalMovesNonCapture().size()*ConfigFile.getPrimaryMobilityValueMidgame(); + } + } + + private void evaluateNewBoardValue (Move move) throws NotAValidSquare { if (move.isCaptureMove()) { @@ -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; squareNb6)) { + ConfigFile.loadFile(whatMove.substring(7)); + } } else if (whatMove.startsWith("asciiplay")) { asciiGame=true; bitboard.display();