2022-06-02 22:39:23 +02:00
|
|
|
function state_loading()
|
2023-10-07 19:12:53 +02:00
|
|
|
local board
|
|
|
|
local size
|
|
|
|
local og_rt
|
|
|
|
local removing_tile
|
|
|
|
|
|
|
|
local spinner = split "-,\\,|,/"
|
|
|
|
local loading_messages = {
|
|
|
|
"rETICULATING SPLINES",
|
|
|
|
"aLLOCATING RESSOURCES",
|
|
|
|
"eMULATING HARDWARE",
|
|
|
|
"uNCLOGGING MEMORY BUS",
|
|
|
|
"sPINNING UP ai AGENT",
|
|
|
|
"sIDE-STEPPING VIRTUAL MACHINE",
|
|
|
|
"iNSTALLING BACKTRACKING WIZARD",
|
|
|
|
"eXFOLIATING PIXELS",
|
|
|
|
"sCAFFOLDING RAY-TRACING ALGORITHM",
|
|
|
|
"sWEEPING PARTICLES",
|
|
|
|
"pRESSURIZING USER INTERFACE",
|
|
|
|
"sHAKING RED AND BLUE PAINT BUCKETS",
|
|
|
|
"gATHERING GRAVITY",
|
|
|
|
"sERIALIZING BOARD MATRIX",
|
|
|
|
"bACKPORTING e2e ENCRYPTION"
|
|
|
|
}
|
|
|
|
|
|
|
|
local message = ""
|
|
|
|
local messages_str = ""
|
|
|
|
local messages_x = 128
|
|
|
|
local loaded = false
|
|
|
|
local done = {}
|
|
|
|
|
|
|
|
local create_board = function()
|
|
|
|
printh("creating")
|
|
|
|
local start = time()
|
|
|
|
repeat
|
|
|
|
board:reset()
|
|
|
|
repeat
|
|
|
|
board:solve_step(true)
|
|
|
|
yield()
|
|
|
|
until board:is_complete()
|
|
|
|
until board:is_valid()
|
|
|
|
|
|
|
|
-- Remove tiles that can be removed
|
|
|
|
local previous = { board:get_tiles_copy() }
|
|
|
|
-- initial state
|
|
|
|
done = {}
|
|
|
|
while true do
|
|
|
|
board:set_tiles(previous[#previous])
|
|
|
|
-- remove a random tile
|
|
|
|
repeat
|
|
|
|
removing_tile += 1
|
|
|
|
if removing_tile > size then
|
|
|
|
removing_tile = 1
|
|
|
|
end
|
|
|
|
until removing_tile == size or board:get_tiles_copy()[removing_tile] ~= 0
|
|
|
|
if removing_tile == og_rt then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
board:fill(removing_tile, 0)
|
|
|
|
add(done, removing_tile)
|
|
|
|
add(previous, board:get_tiles_copy())
|
|
|
|
|
|
|
|
-- try to solve the board
|
|
|
|
local solved = ""
|
|
|
|
yield()
|
|
|
|
repeat
|
|
|
|
solved = board:solve_step()
|
|
|
|
if solved == "valid" then
|
|
|
|
amplitude -= .125
|
|
|
|
end
|
|
|
|
until board:is_complete() or solved == "invalid"
|
|
|
|
|
|
|
|
if solved == "invalid" then
|
|
|
|
deli(previous)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- end while
|
|
|
|
printh("board generated in " .. time() - start .. " seconds")
|
|
|
|
startcoroutine(cocreate(function()
|
|
|
|
repeat
|
|
|
|
amplitude -= .5
|
|
|
|
yield()
|
|
|
|
until amplitude <= 0
|
|
|
|
end))
|
|
|
|
|
|
|
|
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 v == 0 or contains(done, k) then
|
|
|
|
board:draw_tile(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _enter()
|
|
|
|
printh("enter loading")
|
|
|
|
board = Board:new()
|
|
|
|
size = board:get_size() * board:get_size()
|
|
|
|
og_rt = rnd(size) \ 1 + 1
|
|
|
|
-- original removing tile
|
|
|
|
removing_tile = og_rt
|
|
|
|
|
|
|
|
amplitude = 64
|
|
|
|
loaded = false
|
|
|
|
done = {}
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
startcoroutine(cocreate(create_board))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _update()
|
|
|
|
board:lock_tiles()
|
|
|
|
|
|
|
|
messages_x -= 4
|
|
|
|
if loaded then
|
|
|
|
set_state(states.game, board)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _draw()
|
|
|
|
cls()
|
|
|
|
local x, y = board:draw_coords(1)
|
|
|
|
draw_animated_bg(x)
|
|
|
|
-- board:draw_bg()
|
|
|
|
draw_tiles(board)
|
|
|
|
local s = board:get_size() * board:get_size()
|
|
|
|
local l = print(message, 0, -100)
|
|
|
|
local y = 118 + removing_tile / s * 100 / 8
|
|
|
|
local ci = removing_tile \ 20 + 1
|
|
|
|
-- if not loaded then
|
|
|
|
-- rectfill2(0,y-2,127,10,0)
|
|
|
|
-- print(messages_str, messages_x, y, 3, 0)
|
|
|
|
-- -- print(spinner[t()\.25%4+1], 120, 120)
|
|
|
|
-- end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
_enter = _enter,
|
|
|
|
_update = _update,
|
|
|
|
_draw = _draw
|
|
|
|
}
|
2022-06-02 22:39:23 +02:00
|
|
|
end
|