Skip to content

Commit

Permalink
Can't rely on code in an assert executing if asserts not enabled!
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbolt committed Dec 11, 2023
1 parent f9ff05d commit 3b1821c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 deletions EubosChess/src/main/java/eubos/main/EubosEngineMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ void createPositionFromAnalyseCommand(EngineAnalyzeCommand command) {
if (!command.moves.isEmpty()) {
for (GenericMove nextMove : command.moves) {
int move = Move.toMove(nextMove, rootPosition.getTheBoard());
assert rootPosition.performMove(move) : String.format("Illegal move in position command: %s", nextMove.toString());
boolean valid = rootPosition.performMove(move);
assert valid : String.format("Illegal move in position command: %s", nextMove.toString());
if (Move.isCapture(move) || Move.isPawnMove(move)) {
// Pawn moves and captures are irreversible so we can reset the draw checker
dc.reset(rootPosition.getPlyNumber());
Expand Down Expand Up @@ -587,7 +588,8 @@ private int validationSearch(boolean trustedMoveWasFromTrans, long tableRootTran
logger.info(String.format("Completed validation search %s", validation_result.report(pm.getTheBoard())));
}

assert pm.performMove(trusted_move);
boolean valid = pm.performMove(trusted_move);
assert valid;
SearchResult opponent_result = verifyTrustedMoveScore(pm, pc, sda, trusted_score, trusted_depth, trusted_move);

if (ENABLE_LOGGING) {
Expand Down Expand Up @@ -695,7 +697,8 @@ void validateEubosPv(PositionManager pm, String str, int[] pv) {
if (pv != null) {
int moves_applied = 0;
for (int move : pv) {
assert pm.performMove(move);
boolean valid = pm.performMove(move);
assert valid;
++moves_applied;
}

Expand Down
24 changes: 12 additions & 12 deletions EubosChess/src/main/java/eubos/search/PlySearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,27 @@ public int searchRoot(int depth, int alpha, int beta) {
// and we don't want to spoil the PV in the SMR with the aspiration fail line
if (SearchDebugAgent.DEBUG_ENABLED) sda.printRefutationFound(state[0].bestScore);
refuted = true;
if (EubosEngineMain.ENABLE_LOGGING) {
EubosEngineMain.logger.info(String.format("BETA FAIL AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
}
// if (EubosEngineMain.ENABLE_LOGGING) {
// EubosEngineMain.logger.info(String.format("BETA FAIL AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
// state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
// }
break;
}
trans = updateTranspositionTable(trans, (byte) depth, bestMove, (short) state[0].bestScore, Score.upperBound);
rootTransposition = trans;
if (EubosEngineMain.ENABLE_LOGGING) {
EubosEngineMain.logger.info(String.format("ALPHA INCREASED AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
}
// if (EubosEngineMain.ENABLE_LOGGING) {
// EubosEngineMain.logger.info(String.format("ALPHA INCREASED AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
// state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
// }
reportPv((short) state[0].alpha);
}
else if (positionScore > state[0].bestScore) {
bestMove = currMove;
state[0].bestScore = positionScore;
if (EubosEngineMain.ENABLE_LOGGING) {
EubosEngineMain.logger.info(String.format("BEST_SCORE INCREASED AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
}
// if (EubosEngineMain.ENABLE_LOGGING) {
// EubosEngineMain.logger.info(String.format("BEST_SCORE INCREASED AT ROOT score=%d alpha=%d beta=%d depth=%d move=%s",
// state[0].bestScore, state[0].alpha, state[0].beta, originalSearchDepthRequiredInPly, Move.toString(bestMove)));
// }
}

hasSearchedPv = true;
Expand Down
8 changes: 8 additions & 0 deletions EubosChess/src/test/java/eubos/main/EubosEngineMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ public void test_WAC_283_position() throws InterruptedException, IOException {
}
}

@Test
public void test_lichess_bot_startup() throws IOException, InterruptedException {
setupEngine();
commands.add(new CommandPair(POS_START_PREFIX+"moves e2e4 e7e6 g1f3"+CMD_TERMINATOR, null));
commands.add(new CommandPair("go wtime 1740 btime 1790 winc 1000 binc 1000"+CMD_TERMINATOR, BEST_PREFIX+"b8c6"+CMD_TERMINATOR));
performTest(1000);
}

@Test
public void test_aspiration_failure_processing() throws IOException, InterruptedException {
if (EubosEngineMain.ENABLE_TEST_SUITES) {
Expand Down

0 comments on commit 3b1821c

Please sign in to comment.