Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Chess: Fix queen-side castling
Browse files Browse the repository at this point in the history
When castling queen side, the king moves two squares to the left,
not three as this implementation used previously.

This resolves issue #120.
  • Loading branch information
femtobit authored and kilbith committed Jun 24, 2020
1 parent d868488 commit 16adad0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/chess.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player

if thisMove == "white" then
if from_y == 7 and to_y == 7 then
if to_x == 1 then
if to_x == 2 then
local castlingWhiteL = meta:get_int("castlingWhiteL")
local idx57 = inv:get_stack(from_list, 57):get_name()

Expand All @@ -1108,7 +1108,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player
end

inv:set_stack(from_list, 57, "")
inv:set_stack(from_list, 59, "realchess:rook_white_1")
inv:set_stack(from_list, 60, "realchess:rook_white_1")
check = false
end
elseif to_x == 6 then
Expand All @@ -1130,7 +1130,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player
end
elseif thisMove == "black" then
if from_y == 0 and to_y == 0 then
if to_x == 1 then
if to_x == 2 then
local castlingBlackL = meta:get_int("castlingBlackL")
local idx1 = inv:get_stack(from_list, 1):get_name()

Expand All @@ -1142,7 +1142,7 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player
end

inv:set_stack(from_list, 1, "")
inv:set_stack(from_list, 3, "realchess:rook_black_1")
inv:set_stack(from_list, 4, "realchess:rook_black_1")
check = false
end
elseif to_x == 6 then
Expand Down

0 comments on commit 16adad0

Please sign in to comment.