Add more comments for variant code
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 29 Mar 2021 19:38:00 +0000 (21:38 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Mon, 29 Mar 2021 19:38:00 +0000 (21:38 +0200)
No functional change.

src/bitboard.cpp
src/evaluate.cpp
src/movepick.cpp
src/psqt.cpp
src/search.cpp

index a1d1772..7534002 100644 (file)
@@ -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
index 7fc5601..77ade99 100644 (file)
@@ -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<Down>(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<ALL_PIECES>(Us);
+            }
             else if (pos.count<PAWN>(Us) == pos.count<ALL_PIECES>(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
index b4d7cda..ac1fe6e 100644 (file)
 
 #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 {
index e5a4a4e..7c6d2c7 100644 (file)
@@ -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))
index 9ca6919..3f63836 100644 (file)
@@ -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])