Compare commits

..

No commits in common. "583d4af93ec5ff7aa7ee885a4c0f8a0e92f7042c" and "84a05355d9d72d0a2ef5a86a84279661d6b734dd" have entirely different histories.

6 changed files with 19 additions and 60 deletions

2
bg.lua
View File

@ -1,5 +1,5 @@
function draw_animated_bg(startx) function draw_animated_bg(startx)
if amplitude <= 0 then return end if (amplitude <= 0) return
startx = startx or 0 startx = startx or 0
fillp(0b0101101001011010) fillp(0b0101101001011010)

View File

@ -3,8 +3,8 @@ function Board.new()
local debug = false local debug = false
local width = board_size local width = board_size
-- tiles
local tile_width = 20 local tile_width = 8
-- pixels -- pixels
local padding = 1 local padding = 1
local tiles = {} local tiles = {}
@ -12,16 +12,6 @@ function Board.new()
-- list of indexes -- list of indexes
local reset = function() local reset = function()
if width == 4 then
tile_width = 20
elseif width == 6 then
tile_width = 16
elseif width == 8 then
tile_width = 12
elseif width == 10 then
tile_width = 8
end
tiles = {} tiles = {}
for i = 1, width * width do for i = 1, width * width do
tiles[i] = 0 tiles[i] = 0
@ -134,22 +124,19 @@ function Board.new()
-- check count -- check count
if filled and count(row, BLUE) ~= count(row, YELLOW) then if filled and count(row, BLUE) ~= count(row, YELLOW) then
add(issues, { "row", "count", row, y }) add(issues, { "row", "count", row, y })
if debug then printh("uneven count on row " .. y) end if (debug) printh("uneven count on row " .. y) if (not details) return issues
if not details then return issues end
end end
-- check identical lines -- check identical lines
for k, other in ipairs(rows) do for k, other in ipairs(rows) do
if filled and equal(other, row) and other ~= row then if filled and equal(other, row) and other ~= row then
add(issues, { "row", "identical", row, y, k }) add(issues, { "row", "identical", row, y, k })
if debug then printh("equal rows " .. k) end if (debug) printh("equal rows " .. k) if (not details) return issues
if not details then return issues end
end end
end end
-- check triples -- check triples
if self:count_consecutives(row) > 2 then if self:count_consecutives(row) > 2 then
add(issues, { "row", "triples", row, y }) add(issues, { "row", "triples", row, y })
if debug then printh("triples") end if (debug) printh("triples") if (not details) return issues
if not details then return issues end
end end
end end
@ -160,22 +147,19 @@ function Board.new()
-- check count -- check count
if filled and count(col, BLUE) ~= count(col, YELLOW) then if filled and count(col, BLUE) ~= count(col, YELLOW) then
add(issues, { "col", "count", col, x }) add(issues, { "col", "count", col, x })
if debug then printh("uneven count") end if (debug) printh("uneven count") if (not details) return issues
if not details then return issues end
end end
-- check identical lines -- check identical lines
for k, other in ipairs(cols) do for k, other in ipairs(cols) do
if filled and equal(other, col) and other ~= col then if filled and equal(other, col) and other ~= col then
add(issues, { "col", "identical", col, x, k }) add(issues, { "col", "identical", col, x, k })
if debug then printh("equal cols") end if (debug) printh("equal cols") if (not details) return issues
if not details then return issues end
end end
end end
-- check triples -- check triples
if self:count_consecutives(col) > 2 then if self:count_consecutives(col) > 2 then
add(issues, { "col", "triples", col, x }) add(issues, { "col", "triples", col, x })
if debug then printh("triples") end if (debug) printh("triples") if (not details) return issues
if not details then return issues end
end end
end end
return issues return issues
@ -246,8 +230,7 @@ function Board.new()
-- Set a random color -- Set a random color
local z = self:get_random_zero() local z = self:get_random_zero()
self:fill(z, rnd({ BLUE, YELLOW })) self:fill(z, rnd({ BLUE, YELLOW }))
if debug then printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) end if (debug) printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) return "invalid"
return "invalid"
end end
return (changed or self:is_complete()) and "valid" or "invalid" return (changed or self:is_complete()) and "valid" or "invalid"
end, end,
@ -280,8 +263,7 @@ function Board.new()
-- do the surrounding -- do the surrounding
for item in all(neighbors) do for item in all(neighbors) do
if item[1] then if item[1] then
if debug then printh("Surrounding at " .. item[1]) end if (debug) printh("Surrounding at " .. item[1]) self:fill(item[1], tiles[item[2]], true)
self:fill(item[1], tiles[item[2]], true)
end end
end end
end end
@ -297,8 +279,7 @@ function Board.new()
local prev = tiles[idx - 1] local prev = tiles[idx - 1]
local next = tiles[idx + 1] local next = tiles[idx + 1]
if prev ~= 0 and prev == next then if prev ~= 0 and prev == next then
if debug then printh("Splitting at " .. idx) end if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
self:fill(idx, prev, true)
end end
end end
@ -307,8 +288,7 @@ function Board.new()
local prev = tiles[idx - width] local prev = tiles[idx - width]
local next = tiles[idx + width] local next = tiles[idx + width]
if prev ~= 0 and prev == next then if prev ~= 0 and prev == next then
if debug then printh("Splitting at " .. idx) end if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
self:fill(idx, prev, true)
end end
end end
end end
@ -341,7 +321,7 @@ function Board.new()
end, end,
fill_row = function(self, y, color) fill_row = function(self, y, color)
if debug then printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow")) end if (debug) printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow"))
local idx = self:xy_idx(1, y) local idx = self:xy_idx(1, y)
for i = idx, idx + width - 1 do for i = idx, idx + width - 1 do
if self:get_tile(i) == 0 then if self:get_tile(i) == 0 then
@ -351,7 +331,7 @@ function Board.new()
end, end,
fill_col = function(self, x, color) fill_col = function(self, x, color)
if debug then printh("Filling column " .. x .. " in " .. (color == BLUE and "blue" or "yellow")) end if (debug) printh("Filling column " .. x .. " in " .. (color == BLUE and "blue" or "yellow"))
local idx = self:xy_idx(x, 1) local idx = self:xy_idx(x, 1)
for i = idx, #tiles, width do for i = idx, #tiles, width do
if self:get_tile(i) == 0 then if self:get_tile(i) == 0 then
@ -447,15 +427,10 @@ function Board.new()
if color == 1 then fillp() else fillp() end if color == 1 then fillp() else fillp() end
if self:is_locked(idx) then if self:is_locked(idx) then
rectfill2(x, y, w, w, color) rectfill2(x, y, w, w, color)
pset(x + 1, y + 1, shade)
pset(x + w - 2, y + 1, shade)
pset(x + 1, y + w - 2, shade)
pset(x + w - 2, y + w - 2, shade)
else else
roundedrect(x, y, w, w, color) roundedrect(x, y, w, w, color)
line(x + 1, y + w - 1, x + w - 2, y + w - 1, shade) line(x + 1, y + w - 1, x + w - 2, y + w - 1, shade)
line(x + w - 1, y + 1, x + w - 1, y + w - 2, shade) line(x + w - 1, y + 1, x + w - 1, y + w - 2, shade)
pset(x + w - 2, y + w - 2, shade)
end end
else else
fillp() fillp()

View File

@ -93,8 +93,6 @@ function _init()
-- pal({[0]=0,128,132,7,136,8,14,137,9,10,131,3,11,1,140,12},1) -- pal({[0]=0,128,132,7,136,8,14,137,9,10,131,3,11,1,140,12},1)
-- poke(0x5f2e,1) --to keep colors -- poke(0x5f2e,1) --to keep colors
poke(0x5F2D, 1)
printh(" ") printh(" ")
printh("*************") printh("*************")
printh(" ") printh(" ")
@ -103,8 +101,6 @@ function _init()
printh("seed " .. date) printh("seed " .. date)
frame_count = 0 frame_count = 0
draw_mouse = false
last_mouse_pos = { 0, 0 }
states = { states = {
rules = state_rules(), rules = state_rules(),
@ -120,17 +116,9 @@ end
function _update60() function _update60()
frame_count += 1 frame_count += 1
if btnp() > 0 then
draw_mouse = false
end
-- update mouse coords -- update mouse coords
mouse_x = stat(32) mouse_x = stat(32)
mouse_y = stat(33) mouse_y = stat(33)
if mouse_x != last_mouse_pos[1] or mouse_y != last_mouse_pos[2] then
last_mouse_pos = { mouse_x, mouse_y }
draw_mouse = true
end
_coresolve() _coresolve()
gs._update() gs._update()
@ -142,7 +130,5 @@ function _draw()
overlay:_draw() overlay:_draw()
end end
-- mouse cursor -- mouse cursor
if draw_mouse then
spr(1, mouse_x, mouse_y) spr(1, mouse_x, mouse_y)
end
end end

View File

@ -36,10 +36,7 @@ function state_loading()
board:reset() board:reset()
repeat repeat
board:solve_step(true) board:solve_step(true)
-- reduce the number of yields to speed up the process
if board_size == 10 and rnd(1) < .2 or true then
yield() yield()
end
until board:is_complete() until board:is_complete()
until board:is_valid() until board:is_valid()

View File

@ -41,6 +41,7 @@ function state_menu()
local function _enter() local function _enter()
-- mouse not bound to buttons -- mouse not bound to buttons
poke(0x5F2D, 1)
end end
local function _draw() local function _draw()

View File

@ -79,7 +79,7 @@ function state_rules()
x = 44 x = 44
y = 90 y = 90
print("3) aLL ROWS OR COLUMNS\n ARE DIFFERENT", 2, y, 7) print("3) aLL ROWS AND COLUMNS\n ARE DIFFERENT", 2, y, 7)
sspr(78, 32, 12, 12, x, y + 20) sspr(78, 32, 12, 12, x, y + 20)
spr(2, x + 14, y + 21) spr(2, x + 14, y + 21)
sspr(91, 32, 12, 12, x + 26, y + 20) sspr(91, 32, 12, 12, x + 26, y + 20)