]> git.sesse.net Git - stockfish/blobdiff - src/bitbase.cpp
Contempt factor: use DrawValue also in case of stealmates
[stockfish] / src / bitbase.cpp
index b01a03d4bc8815ea3c20794057dfc1b3cde159c5..5f0438a3846c4bbd58a0136c41ff9db24d888b82 100644 (file)
@@ -62,16 +62,16 @@ namespace {
 }
 
 
-uint32_t probe_kpk_bitbase(Square wksq, Square wpsq, Square bksq, Color stm) {
+uint32_t Bitbases::probe_kpk(Square wksq, Square wpsq, Square bksq, Color stm) {
 
   int idx = index(wksq, bksq, wpsq, stm);
   return KPKBitbase[idx / 32] & (1 << (idx & 31));
 }
 
 
-void kpk_bitbase_init() {
+void Bitbases::init_kpk() {
 
-  Result db[IndexMax];
+  Result* db = new Result[IndexMax]; // Avoid to hit stack limit on some platforms
   KPKPosition pos;
   int idx, bit, repeat = 1;
 
@@ -90,6 +90,8 @@ void kpk_bitbase_init() {
       for (bit = 0; bit < 32; bit++)
           if (db[32 * idx + bit] == WIN)
               KPKBitbase[idx] |= 1 << bit;
+
+  delete [] db;
 }
 
 
@@ -117,7 +119,7 @@ namespace {
     stm  = Color(idx & 1);
     bksq = Square((idx >> 1) & 63);
     wksq = Square((idx >> 7) & 63);
-    psq  = make_square(File((idx >> 13) & 3), Rank((idx >> 15) + 1));
+    psq  = File((idx >> 13) & 3) | Rank((idx >> 15) + 1);
   }
 
   Result KPKPosition::classify_leaf(int idx) {
@@ -156,7 +158,7 @@ namespace {
         && rank_of(psq) < RANK_7)
         return DRAW;
 
-    //  Case 4: White king in front of pawn and black has opposition
+    // Case 4: White king in front of pawn and black has opposition
     if (   stm == WHITE
         && wksq == psq + DELTA_N
         && bksq == wksq + DELTA_N + DELTA_N
@@ -168,6 +170,13 @@ namespace {
         && file_of(psq) == FILE_A)
         return DRAW;
 
+    // Case 6: White king trapped on the rook file
+    if (   file_of(wksq) == FILE_A
+        && file_of(psq) == FILE_A
+        && rank_of(wksq) > rank_of(psq)
+        && bksq == wksq + 2)
+        return DRAW;
+
     return UNKNOWN;
   }
 
@@ -189,8 +198,8 @@ namespace {
 
     while (b)
     {
-        r |= Us == WHITE ? db[index(pop_1st_bit(&b), bksq, psq, BLACK)]
-                         : db[index(wksq, pop_1st_bit(&b), psq, WHITE)];
+        r |= Us == WHITE ? db[index(pop_lsb(&b), bksq, psq, BLACK)]
+                         : db[index(wksq, pop_lsb(&b), psq, WHITE)];
 
         if (Us == WHITE && (r & WIN))
             return WIN;