Commit before algo change

This commit is contained in:
2022-06-02 17:55:52 +02:00
parent 65871f1789
commit 7fcd9b4ee0
5 changed files with 63 additions and 10 deletions
+16 -6
View File
@@ -3,33 +3,37 @@ function stateGame()
local selectedId = 1
function drawSelectedTile()
local function drawSelectedTile()
local x, y = board:draw_coords(selectedId)
local w = board:getTileWidth()
rect2(x-1, y-1, w+2, w+2, 6)
end
local function _enter()
-- Create a board
local function create_board()
printh("a: " .. time())
repeat
board:reset()
repeat
board:solveStep(true)
yield()
until board:isComplete()
until board:isValid()
printh("b: " .. time())
-- 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])
-- remove a random tile
local i = board:getRandomNonZero()
board:fill(i, 0)
add(previous, board:getTilesCopy())
-- try to solve the board
local solved = ""
yield()
repeat
solved = board:solveStep()
until board:isComplete() or solved == "invalid"
@@ -40,16 +44,23 @@ function stateGame()
deli(previous)
invalidcount += 1
end
if invalidcount == 100 then
if invalidcount > 50 then
break
end
end -- end while
printh("c: " .. time())
board:setTiles(previous[#previous])
printh(board:tostring())
printh(count(board:getTilesCopy(), 0).." zeroes")
end
local function _enter()
local c = cocreate(create_board)
end
local function _draw()
cls()
board:draw()
drawSelectedTile()
end
@@ -66,7 +77,6 @@ function stateGame()
elseif btnp(RIGHT) then
x += 1
end
printh(x.." "..y)
if (x<1) x=size
if (x>size) x=1
if (y<1) y=size
+1 -1
View File
@@ -11,7 +11,7 @@ function stateRules()
setState(states.menu)
end
local btnBack = makeButton({x=1, y=118, w=30, h=7, text="❎ mENU", color=8,
local btnBack = makeButton({x=1, y=118, w=30, h=7, text="❎menu", color=8,
onClick=function() goBack() end,
onHover=function(btn) btn.color = 7 end})