]> git.lizzy.rs Git - xdecor.git/commitdiff
prevent crash after king is taken
authory <y@y>
Sat, 13 Jul 2019 22:48:36 +0000 (23:48 +0100)
committerJean-Patrick Guerrero <kilbith@users.noreply.github.com>
Tue, 16 Jul 2019 09:45:49 +0000 (11:45 +0200)
src/chess.lua

index 15f1000babe979c3ca9e853f49c759755db92352..dc42be3036a69906c18fac5a7f479bf80fd775e0 100644 (file)
@@ -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)