hans-ekbrand / lc0

The rewritten engine, originally for tensorflow. Now all other backends have been ported here.
GNU General Public License v3.0
3 stars 1 forks source link

Castling-like moves by the A/B-helper is mis-interpreted as legacy encoded castling. #2

Closed hans-ekbrand closed 2 years ago

hans-ekbrand commented 2 years ago

This output from the A/B helper: "1210 18:19:52.086406 140709401196288 ../../src/mcts/auxengine.cc:302] pv:info depth 15 seldepth 26 multipv 1 score cp -180 time 17 nodes 89153 nps 5244294 tbhits 56 hashfull 10 pv e5b2 h6h7 e7e8 h7a7 b2c3 e6g7 e8d8 a7f7 c3b2 g7e6 d8e8 f7g7 f2f1 g7b7 b2a1 f5e4 f1e1 e4d3 e1c1 d3d2 c1c8"

Was interpreted as "debug info: length of PV given to helper engine: 4 position given to helper: position fen 8/4k3/3pNp1R/3PbK2/5P2/8/5r2/8 b - - 2 52 black to move at root, length of my_moves_from_the_white_side 25 my_moves_from_the_white_side: g5g7 f2f4 g7f7 h3h6 e4b7 h6h7 e2e1 h7a7 b7c6 e6g7 e1d1 a7f7 c6b7 g7e6 d1e1 f7g7 f7f8 g7b7 b7a8 f5e4 f8e8 e4d3 e8a8 d3d2 c8c1"

The problem is the move "e1c1" which is interpreted as "e8a8" (seen from white's perspective) (which is e1a1 from black's perspective) which is an application of convert legacy encoding of long castling to FRC encoding of long castling, where the move is a rook move, not a castling move. "e8c8" is the correct move here.

I thought my code for detecting legacy encoded castling (and converting to FRC encoding castling) was correct but apparently not. The code in question is this section from auxengine.cc

    // convert to Modern encoding, update the board and the position
    // For the conversion never flip the board. Only flip the board when you need to apply the move!
    Move m_in_modern_encoding = my_board.GetModernMove(m);

    if (my_board.flipped()) m_in_modern_encoding.Mirror();
    // Should the move applied be modern or legacy, or does it not matter?
    m_in_modern_encoding = my_board.GetModernMove(m_in_modern_encoding);
    // my_board.ApplyMove(m_in_modern_encoding); // Todo verify the correctness here, e.g. by printing a FEN.
    my_board.ApplyMove(m); // Todo verify the correctness here, e.g. by printing a FEN. 
    my_position = Position(my_position, m_in_modern_encoding);

    if (my_board.flipped()) m_in_modern_encoding.Mirror();
    my_board.Mirror();