Post
by Richard1964 » Thu Sep 07, 2017 1:44 pm
Behind the scene ...
Every change in the chess engine is being testing using regression and integration tests, currently there are 116 tests every test has its own scenario. To load a chess game RelaxChess supports EPD and its own XML format. The game in EPD format must be converted first to XML format ((not available yet from RelaxChess GUI). Testing game scenarios the game is being loaded and depending of the configuartion checked against best move(s). This is done in batch mode, here for curious ones a piece of code from the RelaxChess test part.
public boolean setupClientsTest() {
String clientId = "Rysiek";
boolean passed = true;
Map<String, List<String>> units = null;
Object[] tests = new Object[100];
Object[] keys = new Object[100];
try {
strategy = new WowChessStrategy("c:\\Users\\Richard\\AppData\\Local\\RelaxChess\\log.txt", null, true);
strategy.removeAllPieces(clientId, true);
strategy.removeClient(clientId, true);
strategy.setClientType("remote");
strategy.registerClient(clientId);
strategy.setMode(clientId, ChessUtils.AUTO_MODE);
strategy.setGameLevel(clientId, ChessUtils.ADVANCED_LEVEL);
units = createUnitTests();
tests = units.values().toArray();
ArrayList<String>[] tests2 = Arrays.copyOf(tests, tests.length, ArrayList[].class);
keys = units.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
passed = performTest(keys.toString(), (ArrayList<String>) tests2,
Boolean.parseBoolean(reverse.get(i).toString()),
Integer.parseInt(gameLevels.get(i).toString()));
System.out.println(keys.toString() + " Test: " + (passed ? "Passed" : "Failed"));
reset();
}
} catch (Exception e) {
e.printStackTrace();
strategy.removeAllPieces(clientId, true);
strategy.removeClient(clientId, true);
}
return passed;
}
public void loadChessGame(String fileName) {
String document = null;
boolean computerPiece = false;
int position = 0;
int color = -1;
int newChar = 0;
FileReader reader = null;
List<ChessPiece> chessPieces = new ArrayList<ChessPiece>();
List<String> chessPiecesValues = null;
List<String> computerPieceAttributes = null;
List<String> colorAttributes = null;
List<String> positionAttributes = null;
StringBuffer redGame = new StringBuffer();
ChessPiece piece = null;
try {
reader = new FileReader(fileName);
while ((newChar = reader.read()) != -1) {
redGame.append((char) newChar);
}
document = redGame.toString();
chessPiecesValues = ChessUtils.getElementValues(document, "chessPiece");
computerPieceAttributes = ChessUtils.getAttributeValues(document, "computerPiece");
colorAttributes = ChessUtils.getAttributeValues(document, "color");
positionAttributes = ChessUtils.getAttributeValues(document, "position");
for (int i = 0; i < chessPiecesValues.size(); i++) {
computerPiece = (Boolean.parseBoolean(computerPieceAttributes.get(i).toString()));
color = Integer.parseInt(colorAttributes.get(i).toString());
position = Integer.parseInt(positionAttributes.get(i).toString());
if (chessPiecesValues.get(i).toString().contains(ChessUtils.BISHOP)) {
piece = new ChessBishop(position, color,
color == 0 ? ChessUtils.bishopWhite : ChessUtils.bishopBlack, null, getClientId());
piece.setComputerPiece(computerPiece);
} else if (chessPiecesValues.get(i).toString().contains(ChessUtils.PAWN)) {
piece = new ChessPawn(position, color, color == 0 ? ChessUtils.pawnWhite : ChessUtils.pawnBlack,
null, getClientId());
piece.setComputerPiece(computerPiece);
} else if (chessPiecesValues.get(i).toString().contains(ChessUtils.KNIGHT)) {