Refactored board creation
This commit is contained in:
+9
-10
@@ -23,11 +23,17 @@ function stateGame()
|
||||
printh("b: " .. time())
|
||||
-- Remove tiles until randomness is unavoidable
|
||||
local previous = {board:getTilesCopy()} -- initial state
|
||||
local invalidcount = 0
|
||||
local i = 0
|
||||
while true do
|
||||
board:setTiles(previous[#previous])
|
||||
-- remove a random tile
|
||||
local i = board:getRandomNonZero()
|
||||
repeat
|
||||
i += 1
|
||||
until i == 100 or board:getTilesCopy()[i] ~= 0
|
||||
if i == 100 then
|
||||
break
|
||||
end
|
||||
|
||||
board:fill(i, 0)
|
||||
add(previous, board:getTilesCopy())
|
||||
|
||||
@@ -37,15 +43,8 @@ function stateGame()
|
||||
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 > 50 then
|
||||
break
|
||||
end
|
||||
end -- end while
|
||||
printh("c: " .. time())
|
||||
@@ -56,7 +55,7 @@ function stateGame()
|
||||
end
|
||||
|
||||
local function _enter()
|
||||
local c = cocreate(create_board)
|
||||
cocreate(create_board)
|
||||
end
|
||||
|
||||
local function _draw()
|
||||
|
||||
Reference in New Issue
Block a user