From: Fabian Fichter Date: Sat, 31 Oct 2020 10:56:15 +0000 (+0100) Subject: Fix NNUE for large-board version (#199) X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=46bde1c0cce48b7565308c0cad2f4c7343e18b16;p=fairystockfish.git Fix NNUE for large-board version (#199) --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 3488c35..7aed771 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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; diff --git a/src/nnue/features/half_kp.cpp b/src/nnue/features/half_kp.cpp index 116157c..6a09192 100644 --- a/src/nnue/features/half_kp.cpp +++ b/src/nnue/features/half_kp.cpp @@ -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 diff --git a/src/nnue/features/half_kp.h b/src/nnue/features/half_kp.h index 52a83ee..ff29657 100644 --- a/src/nnue/features/half_kp.h +++ b/src/nnue/features/half_kp.h @@ -39,7 +39,7 @@ namespace Eval::NNUE::Features { 0x5D69D5B9u ^ (AssociatedKing == Side::kFriend); // Number of feature dimensions static constexpr IndexType kDimensions = - static_cast(SQUARE_NB) * static_cast(PS_END); + static_cast(SQUARE_NB_CHESS) * static_cast(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 diff --git a/src/nnue/nnue_common.h b/src/nnue/nnue_common.h index 8afea18..1d5f29a 100644 --- a/src/nnue/nnue_common.h +++ b/src/nnue/nnue_common.h @@ -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]; diff --git a/src/types.h b/src/types.h index 680f444..18afd6a 100644 --- a/src/types.h +++ b/src/types.h @@ -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 {