Skip to content

Commit

Permalink
Fix issue 31
Browse files Browse the repository at this point in the history
  • Loading branch information
pioz committed Aug 28, 2024
1 parent 3f70f48 commit 15b5078
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/chess/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ def expand_move(notation)
expand[:from] = match[2] if match[2] && match[2].size == 2

# Support UCI protocol (Lichess)
case expand[:from]
when 'e1'
if expand[:from] == 'e1' && self.board['e1'] == 'K'
expand[:to] = 'g1' if expand[:to] == 'h1' # UCI protocol (Lichess) white king short castling
expand[:to] = 'c1' if expand[:to] == 'a1' # UCI protocol (Lichess) white king long castling
when 'e8'
elsif expand[:from] == 'e8' && self.board['e8'] == 'k'
expand[:to] = 'g8' if expand[:to] == 'h8' # UCI protocol (Lichess) black king short castling
expand[:to] = 'c8' if expand[:to] == 'a8' # UCI protocol (Lichess) black king long castling
end
Expand Down
11 changes: 11 additions & 0 deletions test/test_uci_castling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ def test_uci_invalid_white_long_castling
game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e8a8]
end
end

def test_github_issue_31
g = Chess::Game.load_fen('4Q3/8/8/8/8/8/4K3/7k w - - 0 1')
assert_equal 'Q', g.board['e8']
assert_equal 'K', g.board['e2']
assert_equal 'k', g.board['h1']
assert_equal '*', g.result
assert_equal :in_progress, g.status
g << 'e8a8' # It should not be considered as a UCI casting
assert_equal 'Q', g.board['a8']
end
end

0 comments on commit 15b5078

Please sign in to comment.