Fix NNUE for large-board version (#199)
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 31 Oct 2020 10:56:15 +0000 (11:56 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 31 Oct 2020 10:56:15 +0000 (11:56 +0100)
src/evaluate.cpp
src/nnue/features/half_kp.cpp
src/nnue/features/half_kp.h
src/nnue/nnue_common.h
src/types.h

index 3488c35..7aed771 100644 (file)
@@ -75,8 +75,7 @@ namespace Eval {
 
     useNNUE = Options["Use NNUE"]
              && (   eval_file.find(string(Options["UCI_Variant"])) != string::npos
-                 || (Options["UCI_Variant"] == "chess" && eval_file.rfind("nn-", 0) != string::npos)) // restrict NNUE usage to corresponding variant
-             && RANK_MAX == RANK_8; // TODO: fix for large boards
+                 || (Options["UCI_Variant"] == "chess" && eval_file.rfind("nn-", 0) != string::npos)); // restrict NNUE usage to corresponding variant
     if (!useNNUE)
         return;
 
index 116157c..6a09192 100644 (file)
@@ -25,7 +25,11 @@ namespace Eval::NNUE::Features {
 
   // Orient a square according to perspective (rotates by 180 for black)
   inline Square orient(Color perspective, Square s) {
+#ifdef LARGEBOARDS
+    return Square(int(rank_of(s) * 8 + file_of(s)) ^ (bool(perspective) * 63));
+#else
     return Square(int(s) ^ (bool(perspective) * 63));
+#endif
   }
 
   // Find the index of the feature quantity from the king position and PieceSquare
index 52a83ee..ff29657 100644 (file)
@@ -39,7 +39,7 @@ namespace Eval::NNUE::Features {
         0x5D69D5B9u ^ (AssociatedKing == Side::kFriend);
     // Number of feature dimensions
     static constexpr IndexType kDimensions =
-        static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(PS_END);
+        static_cast<IndexType>(SQUARE_NB_CHESS) * static_cast<IndexType>(PS_END);
     // Maximum number of simultaneously active features
     static constexpr IndexType kMaxActiveDimensions = 30; // Kings don't count
     // Trigger for full calculation instead of difference calculation
index 8afea18..1d5f29a 100644 (file)
@@ -98,19 +98,19 @@ namespace Eval::NNUE {
   enum {
     PS_NONE     =  0,
     PS_W_PAWN   =  1,
-    PS_B_PAWN   =  1 * SQUARE_NB + 1,
-    PS_W_KNIGHT =  2 * SQUARE_NB + 1,
-    PS_B_KNIGHT =  3 * SQUARE_NB + 1,
-    PS_W_BISHOP =  4 * SQUARE_NB + 1,
-    PS_B_BISHOP =  5 * SQUARE_NB + 1,
-    PS_W_ROOK   =  6 * SQUARE_NB + 1,
-    PS_B_ROOK   =  7 * SQUARE_NB + 1,
-    PS_W_QUEEN  =  8 * SQUARE_NB + 1,
-    PS_B_QUEEN  =  9 * SQUARE_NB + 1,
-    PS_W_KING   = 10 * SQUARE_NB + 1,
+    PS_B_PAWN   =  1 * SQUARE_NB_CHESS + 1,
+    PS_W_KNIGHT =  2 * SQUARE_NB_CHESS + 1,
+    PS_B_KNIGHT =  3 * SQUARE_NB_CHESS + 1,
+    PS_W_BISHOP =  4 * SQUARE_NB_CHESS + 1,
+    PS_B_BISHOP =  5 * SQUARE_NB_CHESS + 1,
+    PS_W_ROOK   =  6 * SQUARE_NB_CHESS + 1,
+    PS_B_ROOK   =  7 * SQUARE_NB_CHESS + 1,
+    PS_W_QUEEN  =  8 * SQUARE_NB_CHESS + 1,
+    PS_B_QUEEN  =  9 * SQUARE_NB_CHESS + 1,
+    PS_W_KING   = 10 * SQUARE_NB_CHESS + 1,
     PS_END      = PS_W_KING, // pieces without kings (pawns included)
-    PS_B_KING   = 11 * SQUARE_NB + 1,
-    PS_END2     = 12 * SQUARE_NB + 1
+    PS_B_KING   = 11 * SQUARE_NB_CHESS + 1,
+    PS_END2     = 12 * SQUARE_NB_CHESS + 1
   };
 
   extern const uint32_t kpp_board_index[PIECE_NB][COLOR_NB];
index 680f444..18afd6a 100644 (file)
@@ -504,7 +504,8 @@ enum Square : int {
   SQUARE_NB = 64,
   SQUARE_BIT_MASK = 63,
 #endif
-  SQ_MAX = SQUARE_NB - 1
+  SQ_MAX = SQUARE_NB - 1,
+  SQUARE_NB_CHESS = 64
 };
 
 enum Direction : int {