From bedcc4d4e4221a8e8b8c2f63ff29d1a7619ce0df Mon Sep 17 00:00:00 2001 From: y Date: Sat, 13 Jul 2019 23:48:36 +0100 Subject: [PATCH] prevent crash after king is taken --- src/chess.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/chess.lua b/src/chess.lua index 15f1000..dc42be3 100644 --- a/src/chess.lua +++ b/src/chess.lua @@ -2,6 +2,9 @@ local realchess = {} screwdriver = screwdriver or {} local function index_to_xy(idx) + if not idx then + return nil + end idx = idx - 1 local x = idx % 8 local y = (idx - x) / 8 @@ -1188,6 +1191,9 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player board[from_index] = "" local black_king_idx, white_king_idx = locate_kings(board) + if not black_king_idx or not white_king_idx then + return 0 + end local blackAttacked = attacked("black", black_king_idx, board) local whiteAttacked = attacked("white", white_king_idx, board) -- 2.44.0