From 5573b2be2f895b7a6339ca2d1cf1969b2a177890 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 25 May 2019 02:01:16 +0200 Subject: [PATCH] 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. --- .../petero/droidfish/gamelogic/GameTest.java | 22 +++++++++++-------- .../org/petero/droidfish/gamelogic/Game.java | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java index c64af01..8e3874d 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java @@ -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, "", ""); diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java index e9a9352..c212eac 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java @@ -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> 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(); }