Fix NNUE rotation for non-standard board sizes
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 16 Nov 2020 21:05:09 +0000 (22:05 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Mon, 16 Nov 2020 21:05:09 +0000 (22:05 +0100)
src/nnue/features/half_kp.cpp

index 9dfa703..29648fb 100644 (file)
 
 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