From a4ccf71bdbf4114c34a585ecd9bba7b06e7b2037 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Mon, 13 Apr 2020 18:28:32 +0200 Subject: [PATCH] Rewrite CTF bonus Consider paths instead of just the distance between squares. racingkings STC LLR: 2.96 (-2.94,2.94) [0.00,10.00] Total: 413 W: 205 L: 116 D: 92 http://www.variantfishtest.org:6543/tests/view/5e94459d6e23db4f73614c65 racingkings LTC LLR: 2.95 (-2.94,2.94) [0.00,10.00] Total: 387 W: 181 L: 97 D: 109 http://www.variantfishtest.org:6543/tests/view/5e944f3c6e23db4f73614c72 kingofthehill STC LLR: 2.95 (-2.94,2.94) [0.00,10.00] Total: 1416 W: 701 L: 587 D: 128 http://www.variantfishtest.org:6543/tests/view/5e9445b86e23db4f73614c69 kingofthehill LTC LLR: 2.96 (-2.94,2.94) [0.00,10.00] Total: 1130 W: 553 L: 445 D: 132 http://www.variantfishtest.org:6543/tests/view/5e944f5a6e23db4f73614c75 --- src/evaluate.cpp | 29 ++++++++++++++++++----------- 1 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 8b7f065..f478716 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -905,20 +905,27 @@ namespace { // Capture the flag if (pos.capture_the_flag(Us)) { - bool isKingCTF = pos.capture_the_flag_piece() == KING; + PieceType ptCtf = pos.capture_the_flag_piece(); Bitboard ctfPieces = pos.pieces(Us, pos.capture_the_flag_piece()); - int scale = pos.count(Us, pos.capture_the_flag_piece()); - while (ctfPieces) + Bitboard ctfTargets = pos.capture_the_flag(Us) & pos.board_bb(); + Bitboard onHold = 0; + Bitboard processed = 0; + // Traverse all paths of the CTF pieces to the CTF targets. + // Put squares that are attacked or occupied on hold for one iteration. + for (int dist = 0; ctfPieces && (ctfTargets & ~processed); dist++) { - Square s1 = pop_lsb(&ctfPieces); - Bitboard target_squares = pos.capture_the_flag(Us) & pos.board_bb(); - while (target_squares) + score += make_score(2500, 2500) * popcount(ctfTargets & ctfPieces) / (1 + dist * dist); + Bitboard current = ctfPieces; + processed |= ctfPieces; + ctfPieces = onHold & ~processed; + onHold = 0; + while (current) { - Square s2 = pop_lsb(&target_squares); - int dist = distance(s1, s2) - + (isKingCTF || pos.flag_move() ? popcount(pos.attackers_to(s2, Them)) : 0) - + !!(pos.pieces(Us) & s2); - score += make_score(2500, 2500) / (1 + scale * dist * dist); + Square s = pop_lsb(¤t); + Bitboard attacks = ( (PseudoAttacks[Us][ptCtf][s] & pos.pieces()) + | (PseudoMoves[Us][ptCtf][s] & ~pos.pieces())) & ~processed & pos.board_bb(); + ctfPieces |= attacks & ~pos.pieces(Us) & ~attackedBy[Them][ALL_PIECES]; + onHold |= attacks; } } } -- 1.7.0.4