fairy-stockfish / Fairy-Stockfish

chess variant engine supporting Xiangqi, Shogi, Janggi, Makruk, S-Chess, Crazyhouse, Bughouse, and many more
https://fairy-stockfish.github.io/
GNU General Public License v3.0
603 stars 189 forks source link

Pawn Mobility Region #498

Closed DSARichard closed 1 year ago

DSARichard commented 2 years ago

I believe there may be a problem with the mobilityRegion of pawns: they are able to move out of their mobilityRegion.

Recently I tried to playing with some custom variants in browser fairyground (https://fairyground.vercel.app/). I attempted to create an inaccessible hole in the center of the board. Since the asterisk FEN notation in WinBoard is of course not available in fairyground, I tried tediously defining the mobilityRegion for each of the pieces, and then filled the hole with immobile pieces to block long-range pieces. All pieces functioned correctly except pawns, which were able to capture the immobile pieces of opposite color in the inaccessible region somehow.

Is this expected or unexpected behavior? If not, is this solely a problem with fairyground, or does it manifest in others too? Apologies if there is a simple mistake I have committed or if I have missed a solution easily available.

ianfab commented 2 years ago

Thanks for the report. I can imagine where this might be coming from since pawn moves are generated completely separately from other pieces. It definitely is not intended, and since fairyground uses the same game logic under the hood it should be an issue in all Fairy-SF based code.

Could you please add a sample configuration where this occurs to reproduce the problem?

Edit: Bug should be about missing restriction of capture and non-capture targets to board_bb(c, PAWN) at https://github.com/ianfab/Fairy-Stockfish/blob/8ec72eff3bcf82648396756d03085d2c9363257d/src/movegen.cpp#L117-L119

DSARichard commented 2 years ago

I will just paste a short simplified version that retains the bug:

longer, with bishop and king [chessvariant:chess]
pieceToCharTable = PBKXpbkx
immobile = x
mobilityRegionWhitePawn = a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7 a8 b8 c8 f8 g8 h8
mobilityRegionBlackPawn = a1 b1 c1 f1 g1 h1 a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7
mobilityRegionWhiteBishop = a1 b1 c1 f1 g1 h1 a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7 a8 b8 c8 f8 g8 h8
mobilityRegionBlackBishop = a1 b1 c1 f1 g1 h1 a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7 a8 b8 c8 f8 g8 h8
mobilityRegionWhiteKing = a1 b1 c1 f1 g1 h1 a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7 a8 b8 c8 f8 g8 h8
mobilityRegionBlackKing = a1 b1 c1 f1 g1 h1 a2 b2 c2 f2 g2 h2 a3 b3 c3 f3 g3 h3 a4 b4 c4 f4 g4 h4 a5 b5 c5 f5 g5 h5 a6 b6 c6 f6 g6 h6 a7 b7 c7 f7 g7 h7 a8 b8 c8 f8 g8 h8
startFen = 3xxb2/3xxpk1/3xx3/3xx3/3XX3/3XX3/3XXPK1/3XXB2 w - - 0 1

Edit: Or this which is much more succinct and easy to test: [chessvariant:chess] mobilityRegionWhitePawn = f2 mobilityRegionBlackPawn = d7 startFen = 8/3p4/8/8/8/8/5P2/8 w - - 0 1

kimeundong commented 2 years ago

When update korea janggi??