function stateGame() local board = Board.new() function _enter() -- Create a board repeat board:reset() repeat board:solveStep(true) until board:isComplete() until board:isValid() -- Remove tiles until randomness is unavoidable local previous = {board:getTilesCopy()} -- initial state local invalidcount = 0 while true do -- remove a random tile board:setTiles(previous[#previous]) local i = board:getRandomNonZero() board:fill(i, 0) add(previous, board:getTilesCopy()) -- try to solve the board local solved = "" repeat solved = board:solveStep() until board:isComplete() or solved == "invalid" if board:isComplete() then invalidcount = 0 end if solved == "invalid" then deli(previous) invalidcount += 1 end if invalidcount == 100 then break end end -- end while board:setTiles(previous[#previous]) printh(board:tostring()) end return { _enter = _enter, _update = function() end, _draw = function() board:draw() end, } end