Version 0.8.0
============= Just before creating the external config file
This commit is contained in:
150
src/suicideChess/ConfigFile.java
Normal file
150
src/suicideChess/ConfigFile.java
Normal file
@ -0,0 +1,150 @@
|
||||
package suicideChess;
|
||||
|
||||
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
|
||||
*
|
||||
* @author Jean-Baptiste Hétier
|
||||
* @version $LastChangedRevision$, $LastChangedDate$
|
||||
*
|
||||
*/
|
||||
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 endGamePawns;
|
||||
private static int endGamePieces;
|
||||
|
||||
/**
|
||||
* The pieces value in the middlegame
|
||||
*/
|
||||
public static int[] getPieceValuesMiddle() {
|
||||
return pieceValuesMiddle;
|
||||
}
|
||||
/**
|
||||
* 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 void load(String file) {
|
||||
//declared here only to make visible to finally clause
|
||||
BufferedReader problemReader = null;
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user