From f8f128c5d01ed060eab037039eaa597661c87441 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Mon, 29 Mar 2021 21:38:00 +0200 Subject: [PATCH] Add more comments for variant code No functional change. --- src/bitboard.cpp | 2 ++ src/evaluate.cpp | 11 ++++++++++- src/movepick.cpp | 5 +++++ src/psqt.cpp | 2 +- src/search.cpp | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index a1d1772..7534002 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -51,6 +51,8 @@ Magic* magics[] = {BishopMagics, RookMagicsH, RookMagicsV, CannonMagicsH, Cannon namespace { +// Some magics need to be split in order to reduce memory consumption. +// Otherwise on a 12x10 board they can be >100 MB. #ifdef LARGEBOARDS Bitboard RookTableH[0x11800]; // To store horizontalrook attacks Bitboard RookTableV[0x4800]; // To store vertical rook attacks diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7fc5601..77ade99 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -639,9 +639,13 @@ namespace { } Bitboard theirHalf = pos.board_bb() & ~forward_ranks_bb(Them, relative_rank(Them, Rank((pos.max_rank() - 1) / 2), pos.max_rank())); mobility[Us] += DropMobility * popcount(b & theirHalf & ~attackedBy[Them][ALL_PIECES]); + + // Bonus for Kyoto shogi style drops of promoted pieces if (pos.promoted_piece_type(pt) != NO_PIECE_TYPE && pos.drop_promoted()) score += make_score(std::max(PieceValue[MG][pos.promoted_piece_type(pt)] - PieceValue[MG][pt], VALUE_ZERO), std::max(PieceValue[EG][pos.promoted_piece_type(pt)] - PieceValue[EG][pt], VALUE_ZERO)) / 4 * pos.count_in_hand(Us, pt); + + // Mobility bonus for reversi variants if (pos.enclosing_drop()) mobility[Us] += make_score(500, 500) * popcount(b); @@ -1178,6 +1182,7 @@ namespace { Bitboard inaccessible = pos.pieces(Us, PAWN) & shift(pos.pieces(Them, PAWN)); // Traverse all paths of the CTF pieces to the CTF targets. // Put squares that are attacked or occupied on hold for one iteration. + // This reflects that likely a move will be needed to block or capture the attack. for (int dist = 0; (ctfPieces || onHold || onHold2) && (ctfTargets & ~processed); dist++) { int wins = popcount(ctfTargets & ctfPieces); @@ -1214,6 +1219,7 @@ namespace { for (PieceType pt : pos.extinction_piece_types()) if (pt != ALL_PIECES) { + // Single piece type extinction bonus int denom = std::max(pos.count(Us, pt) - pos.extinction_piece_count(), 1); if (pos.count(Them, pt) >= pos.extinction_opponent_piece_count() || pos.two_boards()) score += make_score(1000000 / (500 + PieceValue[MG][pt]), @@ -1221,7 +1227,10 @@ namespace { * (pos.extinction_value() / VALUE_MATE); } else if (pos.extinction_value() == VALUE_MATE) + { + // Losing chess variant bonus score += make_score(pos.non_pawn_material(Us), pos.non_pawn_material(Us)) / pos.count(Us); + } else if (pos.count(Us) == pos.count(Us)) { // Pawns easy to stop/capture @@ -1268,7 +1277,7 @@ namespace { } } - // Potential piece flips + // Potential piece flips (Reversi) if (pos.flip_enclosed_pieces()) { // Stable pieces diff --git a/src/movepick.cpp b/src/movepick.cpp index b4d7cda..ac1fe6e 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -20,10 +20,15 @@ #include "movepick.h" + +// Since continuation history grows quadratically with the number of piece types, +// we need to reserve a limited number of slots and map piece types to these slots +// in order to reduce memory consumption to a reasonable level. int history_slot(Piece pc) { return pc == NO_PIECE ? 0 : (type_of(pc) == KING ? PIECE_SLOTS - 1 : type_of(pc) % (PIECE_SLOTS - 1)) + color_of(pc) * PIECE_SLOTS; } + namespace { enum Stages { diff --git a/src/psqt.cpp b/src/psqt.cpp index e5a4a4e..7c6d2c7 100644 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@ -239,7 +239,7 @@ void init(const Variant* v) { // Add a penalty for unpromoted soldiers if (pt == SOLDIER && r < v->soldierPromotionRank) psq[pc][s] -= score * (v->soldierPromotionRank - r) / (4 + f); - // Corners are valuable in othello + // Corners are valuable in reversi if (v->enclosingDrop == REVERSI) { if (f == FILE_A && (r == RANK_1 || r == v->maxRank)) diff --git a/src/search.cpp b/src/search.cpp index 9ca6919..3f63836 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -258,6 +258,7 @@ void MainThread::search() { Thread::search(); // main thread start searching } + // Sit in bughouse variants if partner requested it or we are dead if (rootPos.two_boards() && !Threads.abort && Options["Protocol"] == "xboard") { while (!Threads.stop && (Partner.sitRequested || Partner.weDead) && Time.elapsed() < Limits.time[us] - 1000) @@ -569,6 +570,7 @@ void Thread::search() { if (rootMoves.size() == 1) totalTime = std::min(500.0, totalTime); + // Update partner in bughouse variants if (completedDepth >= 8 && rootPos.two_boards() && Options["Protocol"] == "xboard") { if (Limits.time[us]) -- 1.7.0.4