From 7b7e4159973cb057bd8c699cac81ad17f7f59cc5 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Tue, 27 Feb 2018 08:50:02 +0100 Subject: [PATCH] fixed bug with white pawn move --- apps/realchess_app.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/realchess_app.lua b/apps/realchess_app.lua index ab3cfa9..81155e5 100644 --- a/apps/realchess_app.lua +++ b/apps/realchess_app.lua @@ -96,6 +96,25 @@ function realchess.move(data, pos, from_list, from_index, to_list, to_index, _, else return 0 end + + -- if x not changed, + -- ensure that destination cell is empty + -- elseif x changed one unit left or right + -- ensure the pawn is killing opponent piece + -- else + -- move is not legal - abort + + 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 + if not pieceTo:find("black") then + return 0 + end + else + return 0 + end elseif thisMove == "black" then local pawnBlackMove = inv:get_stack(from_list, xy_to_index(from_x, from_y + 1)):get_name() -- black pawns can go down only