From ef65e86547867f02fc2de6bd930e69c8d97209b3 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 16 Jul 2023 09:35:09 +0200 Subject: [PATCH] Chess: Fix AI pawn doublestep safe from en passant --- src/chess.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/chess.lua b/src/chess.lua index 9105316..bc96457 100644 --- a/src/chess.lua +++ b/src/chess.lua @@ -2036,6 +2036,15 @@ local function ai_move(inv, meta) inv:set_stack("board", choice_to, pieceFrom) end + -- Note the pawn double step + local c_from_x, c_from_y = index_to_xy(choice_from) + local c_to_x, c_to_y = index_to_xy(choice_to) + if pieceFrom:find("pawn") and math.abs(c_from_y - c_to_y) == 2 then + meta:set_int("prevDoublePawnStepTo", choice_to) + else + meta:set_int("prevDoublePawnStepTo", 0) + end + inv:set_stack("board", choice_from, "") end