From 5f036267b298c1d3e52b59c02fd463aac1db8868 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Mon, 16 Nov 2020 22:05:09 +0100 Subject: [PATCH] Fix NNUE rotation for non-standard board sizes --- src/nnue/features/half_kp.cpp | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nnue/features/half_kp.cpp b/src/nnue/features/half_kp.cpp index 9dfa703..29648fb 100644 --- a/src/nnue/features/half_kp.cpp +++ b/src/nnue/features/half_kp.cpp @@ -23,13 +23,15 @@ namespace Eval::NNUE::Features { + // Map square to numbering on 8x8 board + constexpr Square map_to_standard_board(Square s) { + return Square(s - rank_of(s) * (FILE_MAX - FILE_H)); + } + // Orient a square according to perspective (rotates by 180 for black) inline Square orient(const Position& pos, Color perspective, Square s) { -#ifdef LARGEBOARDS - return Square(int(rank_of(s) * 8 + file_of(s)) ^ (!(pos.capture_the_flag(BLACK) & Rank8BB) * bool(perspective) * 63)); -#else - return Square(int(s) ^ (!(pos.capture_the_flag(BLACK) & Rank8BB) * bool(perspective) * 63)); -#endif + return map_to_standard_board( perspective == WHITE || (pos.capture_the_flag(BLACK) & Rank8BB) ? s + : flip_rank(flip_file(s, pos.max_file()), pos.max_rank())); } // Find the index of the feature quantity from the king position and PieceSquare -- 1.7.0.4