function state_loading() local board = Board.new() local spinner = split"-,\\,|,/" local loading_messages = { "rETICULATING SPLINES", "aLLOCATING RESSOURCES", "eMULATING HARDWARE", "uNCLOGGING MEMORY BUS", "sPINNING UP ai AGENT", "bOOTING VIRTUAL MACHINE", "cOLLECTING PIXELS TO BUILD TILES", "lOADING RAY-TRACING ALGORITHM", "sWEEPING PARTICLES", "pRESSURIZING USER INTERFACE", "rECOMPUTING BOARD MATRIX" } local message = "" local messages_str = "" local messages_x = 128 local loaded = false local removing_tile = 0 local create_board = cocreate(function() repeat board:reset() repeat board:solve_step(true) yield() until board:is_complete() until board:is_valid() printh("b: " .. time()) -- Remove tiles until randomness is unavoidable local previous = {board:get_tiles_copy()} -- initial state while true do board:set_tiles(previous[#previous]) -- remove a random tile repeat removing_tile += 1 until removing_tile == 100 or board:get_tiles_copy()[iremoving_tile] ~= 0 if removing_tile == 100 then break end board:fill(removing_tile, 0) add(previous, board:get_tiles_copy()) -- try to solve the board local solved = "" yield() repeat solved = board:solve_step() until board:is_complete() or solved == "invalid" if solved == "invalid" then deli(previous) end end -- end while printh("c: " .. time()) board:set_tiles(previous[#previous]) printh(board:tostring()) printh(count(board:get_tiles_copy(), 0).." zeroes") loaded = true end) local function draw_tiles(board) local w = board:get_size() local tiles = board:get_tiles_copy() for k,v in ipairs(tiles) do if k 0 then local x,y = board:draw_coords(k) local color = v == BLUE and 12 or 8 if color == 1 then fillp(▒) else fillp(█) end rectfill2(x, y, w, w, color) end end end local function _enter() loaded = false local copy_messages = copy(loading_messages) messages_str = "" messages_x = 128 while #copy_messages > 0 do local m = rnd(copy_messages) messages_str ..= m .. " " del(copy_messages, m) end messages_str ..= "tHANK YOU FOR YOUR PATIENCE" custom_font() startcoroutine(create_board) end local function _update() messages_x -= 2 if loaded then set_state(states.game, board) end end local function _draw() cls() board:draw_bg() draw_tiles(board) local l = print(message, 0, -100) if not loaded then print(messages_str, messages_x, 50, 7, 0) -- print(spinner[t()\.25%4+1], 120, 120) end end return { _enter = _enter, _update = _update, _draw = _draw, } end