Special case for pawns (2-cell movement)

This commit is contained in:
beyondlimits 2015-10-25 15:50:26 +01:00
parent 11bbeb1cec
commit bfc09c5008

@ -131,23 +131,20 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl
if thisMove == "white" then if thisMove == "white" then
-- white pawns can go up only -- white pawns can go up only
if from_y - 1 ~= to_y then if from_y - 1 == to_y then
return 0 if from_x == to_x then
end if pieceTo ~= "" then
return 0
-- if x not changed, end
-- ensure that destination cell is empty elseif from_x - 1 == to_x or from_x + 1 == to_x then
-- elseif x changed one unit left or right if not pieceTo:find("black") then
-- ensure the pawn is killing opponent piece return 0
-- else end
-- move is not legal - abort else
if from_x == to_x then
if pieceTo ~= "" then
return 0 return 0
end end
elseif from_x - 1 == to_x or from_x + 1 == to_x then elseif from_y - 2 == to_y then
if not pieceTo:find("black") then if pieceTo ~= "" or from_y < 6 or inv:get_stack(from_list, xy_to_index(from_x, from_y - 1)):get_name() ~= "" then
return 0 return 0
end end
else else
@ -155,7 +152,19 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl
end end
elseif thisMove == "black" then elseif thisMove == "black" then
-- black pawns can go down only -- black pawns can go down only
if from_y + 1 ~= to_y then if from_y + 1 == to_y then
if from_x == to_x then
if pieceTo ~= "" then
return 0
end
elseif from_x - 1 == to_x or from_x + 1 == to_x then
return 0
end
elseif from_y + 2 == to_y then
if pieceTo ~= "" or from_y > 1 or inv:get_stack(from_list, xy_to_index(from_x, from_y + 1)):get_name() ~= "" then
return 0
end
else
return 0 return 0
end end