package suicideChess; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * This class is used to read configuration settings for the AI * * @author Jean-Baptiste Hétier * @version $LastChangedRevision$, $LastChangedDate$ * */ public class ConfigFile { 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[] getPieceValuesMidgame() { return pieceValuesMidgame; } /** * The pieces value in the end */ 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"); } /** * 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(configFile)); String line = null; //not declared within while loop while ((line = problemReader.readLine()) != null) { currentLine=line; currentLineNumber++; if(line.startsWith("pvm")) { String[] result=line.split("\t"); //start from 1 not to include "pvm" for(int i=1; i