Don't truncate game history when sending moves to the chess engine

The LC0 engine evaluation function depends on the move history.

Null moves are still truncated though, since a UCI engine is not
expected to be able to handle null moves.
This commit is contained in:
Peter Osterlund 2019-05-25 02:01:16 +02:00
parent dfaa220946
commit 5573b2be2f
2 changed files with 15 additions and 11 deletions

View File

@ -409,8 +409,7 @@ public class GameTest extends TestCase {
assertEquals(Game.GameState.ALIVE, game.getGameState());
}
/** Test that UCI history is not longer than necessary.
* We can't expect engines to handle null moves, for example. */
/** Test that UCI history does not include null moves. */
public void testUCIHistory() throws ChessParseError {
Game game = new Game(null, new TimeControlData());
@ -427,21 +426,26 @@ public class GameTest extends TestCase {
game.processString("e5");
hist = game.getUCIHistory();
expectedPos = new Position(game.currPos());
assertEquals(0, hist.second.size());
assertEquals(2, hist.second.size());
assertEquals(TextIO.UCIstringToMove("g1f3"), hist.second.get(0));
assertEquals(TextIO.UCIstringToMove("e7e5"), hist.second.get(1));
assertEquals(expectedPos, hist.first);
game.processString("Nc3");
hist = game.getUCIHistory();
assertEquals(1, hist.second.size());
assertEquals(TextIO.UCIstringToMove("b1c3"), hist.second.get(0));
assertEquals(3, hist.second.size());
assertEquals(TextIO.UCIstringToMove("g1f3"), hist.second.get(0));
assertEquals(TextIO.UCIstringToMove("e7e5"), hist.second.get(1));
assertEquals(TextIO.UCIstringToMove("b1c3"), hist.second.get(2));
assertEquals(expectedPos, hist.first);
game.processString("Nc6");
hist = game.getUCIHistory();
assertEquals(2, hist.second.size());
assertEquals(TextIO.UCIstringToMove("b1c3"), hist.second.get(0));
assertEquals(TextIO.UCIstringToMove("b8c6"), hist.second.get(1));
assertEquals(4, hist.second.size());
assertEquals(TextIO.UCIstringToMove("g1f3"), hist.second.get(0));
assertEquals(TextIO.UCIstringToMove("e7e5"), hist.second.get(1));
assertEquals(TextIO.UCIstringToMove("b1c3"), hist.second.get(2));
assertEquals(TextIO.UCIstringToMove("b8c6"), hist.second.get(3));
assertEquals(expectedPos, hist.first);
int varNo = game.tree.addMove("--", "", 0, "", "");

View File

@ -447,7 +447,7 @@ public class Game {
/**
* Return the last zeroing position and a list of moves
* Return the position after the last null move and a list of moves
* to go from that position to the current position.
*/
public final Pair<Position, ArrayList<Move>> getUCIHistory() {
@ -462,7 +462,7 @@ public class Game {
Node n = moveList.get(i);
mList.add(n.move);
currPos.makeMove(n.move, ui);
if (currPos.halfMoveClock == 0) {
if (currPos.halfMoveClock == 0 && n.move.equals(new Move(0, 0, 0))) {
pos = new Position(currPos);
mList.clear();
}