DOBRO / binbo

Chess representation written in Erlang using Bitboards, ready for use on game servers
Apache License 2.0
124 stars 12 forks source link

Validating FEN with 3 rooks on the board #8

Closed nextchessmove closed 2 years ago

nextchessmove commented 2 years ago

Greetings, and excellent library!

I think I ran across an issue with validating FEN when there are three rooks on the board:

iex(1)> :binbo_game.new("r3k2r/2p1qppp/p3p3/n2n4/P2P4/P2QPNP1/1p1N1PBP/2r1RRK1 b kq - 0 1")                
{:error, {:castling, {:black, :both_sides}}}

That position results from the pawn at c2 advancing to c1 and under-promoting to rook.

I'm not confident enough in my Erlang to submit a pull request, but I think it may just be a matter of changing line 1011 of src/binbo_position.erl from:

case IsKingOnPlace andalso (RooksBB =:= (SqABB bor SqHBB)) of

to something like:

case IsKingOnPlace andalso (RooksBB band (SqABB bor SqHBB)) =:= (SqABB bor SqHBB) of

So, instead of testing, in the case of black, "does black have exactly two rooks and are they on a1 and h8", instead test "does black have a rook on a1 and h8".

DOBRO commented 2 years ago

Hi,

thanks for reporting the issue! Fixed in 4.0.1

nextchessmove commented 2 years ago

Thank you for the prompt reply and fix!