Skip to content

Commit

Permalink
Fix application of the fifty-move rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchessmove committed Mar 21, 2022
1 parent 7e1602b commit f3f0d00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/binbo_position.erl
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,7 @@ update_hashmap(Game) ->
%% https://en.wikipedia.org/wiki/Fifty-move_rule
-spec is_rule50(bb_game()) -> boolean().
is_rule50(Game) ->
case (get_halfmove(Game) < 50) of
true ->
false;
false ->
case (get_fullmove(Game) < 75) of
true -> false;
false -> true
end
end.
get_halfmove(Game) > 99.

%% is_k_vs_k/2
%% Returns true when:
Expand Down
9 changes: 9 additions & 0 deletions test/play_game_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
-export([move_all_pieces/1,
checkmate_white/1, checkmate_black/1,
stalemate_white/1, stalemate_black/1,
rule50/1,
castling_kingside/1, castling_queenside/1,
castling_white_after_king_move/1,
castling_white_after_rook_move/1,
Expand Down Expand Up @@ -152,6 +153,14 @@ stalemate_black(Config) ->
{ok, {draw,stalemate}} = binbo:game_status(Pid),
ok.

%% rule50/1
rule50(Config) ->
Pid = get_pid(Config),
{ok, continue} = binbo:new_game(Pid, <<"6R1/7k/8/8/1r3B2/5K2/8/8 w - - 99 119">>),
{ok, {draw,rule50}} = binbo:move(Pid, <<"Ra4">>),
{ok, {draw,rule50}} = binbo:game_status(Pid),
ok.

%% castling_kingside/1
castling_kingside(Config) ->
Pid = get_pid(Config),
Expand Down

0 comments on commit f3f0d00

Please sign in to comment.