From 00e5af5e3409d351522225762a8fba975f868e23 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 12 Jul 2023 11:37:09 +0200 Subject: [PATCH] Chess: Fix AI crash --- src/chess.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chess.lua b/src/chess.lua index 091ba5e..616d822 100644 --- a/src/chess.lua +++ b/src/chess.lua @@ -534,7 +534,7 @@ local function best_move(moves) end if #choices == 0 then - return -1, -1 + return nil end local random = math.random(1, #choices) local choice_from, choice_to = choices[random].from, choices[random].to @@ -1587,7 +1587,7 @@ local function ai_move(inv, meta) end local choice_from, choice_to = best_move(moves) - if choice_from == -1 then + if choice_from == nil then -- No best move: stalemate or checkmate return end @@ -1636,7 +1636,7 @@ local function ai_move(inv, meta) local lastMoveTime = meta:get_int("lastMoveTime") if lastMoveTime > 0 then if not kingSafe then - if bestMoveSaveTo ~= -1 then + if bestMoveSaveTo ~= nil then inv:set_stack("board", bestMoveSaveTo, board[bestMoveSaveFrom]) inv:set_stack("board", bestMoveSaveFrom, "") meta:set_string("blackAttacked", "")