- // Get the material key of a Position out of the given endgame key code
- // like "KBPKN". The trick here is to first forge an ad-hoc fen string
- // and then let a Position object to do the work for us. Note that the
- // fen string could correspond to an illegal position.
+ // Map the square as if strongSide is white and strongSide's only pawn
+ // is on the left half of the board.
+ Square normalize(const Position& pos, Color strongSide, Square sq) {
+
+ assert(pos.count<PAWN>(strongSide) == 1);
+
+ if (file_of(pos.list<PAWN>(strongSide)[0]) >= FILE_E)
+ sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
+
+ if (strongSide == BLACK)
+ sq = ~sq;
+
+ return sq;
+ }
+
+ // Get the material key of Position out of the given endgame key code
+ // like "KBPKN". The trick here is to first forge an ad-hoc FEN string
+ // and then let a Position object do the work for us. Note that the
+ // FEN string could correspond to an illegal position.