Skip to content

Commit

Permalink
Fix FEN validating regarding the legal castling when more than 2 rook…
Browse files Browse the repository at this point in the history
…s on the board
  • Loading branch information
DOBRO committed Mar 18, 2022
1 parent 8a23c7b commit 534d2ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/binbo_position.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ validate_fen_castling([Color|Tail], #{?GAME_KEY_CASTLING := Castling} = Game) ->
IsKingOnPlace = (KingSqBB =:= KingBB),
case Castling of
_ when (Castling band CastlingAny) =:= CastlingAny ->
case IsKingOnPlace andalso (RooksBB =:= (SqABB bor SqHBB)) of
case IsKingOnPlace andalso ?IS_AND(SqABB bor SqHBB, RooksBB) of
true -> validate_fen_castling(Tail, Game);
false -> {error, {Color, both_sides}}
end;
Expand Down
8 changes: 8 additions & 0 deletions test/binbo_fen_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ test_initial_fen(Config) ->
test_legal_string_fens(Config) ->
Pid = get_pid(Config),
{ok,continue} = binbo:new_game(Pid, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"),
% Issue #8 https://github.com/DOBRO/binbo/issues/8
{ok,continue} = binbo:new_game(Pid, "r3k2r/2p1qppp/p3p3/n2n4/P2P4/P2QPNP1/1p1N1PBP/2r1RRK1 b kq - 0 1"),
% 3 rooks, white to move
{ok,continue} = binbo:new_game(Pid, "r3k2r/pbqpbppp/1p2pn2/8/1R6/B1NPPN2/P1PQBPPP/R3K2R w KQkq - 0 1"),
% 4 white rooks, white to move
{ok,continue} = binbo:new_game(Pid, "r3k2r/pbq1bppp/1p2pn2/6r1/1R6/B1NPPN2/P1RQBPPP/R3K2R w KQkq - 0 1"),
% 4 black rooks, black to move
{ok,continue} = binbo:new_game(Pid, "r3k2r/pbqrbppp/1p3n2/6r1/1R6/B1NPPN2/P1RQBPPP/R3K2R b KQkq - 0 1"),
ok.

%% test_bad_fens/1
Expand Down

0 comments on commit 534d2ab

Please sign in to comment.