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)
if amplitude <= 0 then return end
if (amplitude <= 0) return
startx = startx or 0
fillp(0b0101101001011010)

View File

@ -3,8 +3,8 @@ function Board.new()
local debug = false
local width = board_size
local tile_width = 20
-- tiles
local tile_width = 8
-- pixels
local padding = 1
local tiles = {}
@ -12,16 +12,6 @@ function Board.new()
-- list of indexes
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 = {}
for i = 1, width * width do
tiles[i] = 0
@ -134,22 +124,19 @@ function Board.new()
-- check count
if filled and count(row, BLUE) ~= count(row, YELLOW) then
add(issues, { "row", "count", row, y })
if debug then printh("uneven count on row " .. y) end
if not details then return issues end
if (debug) printh("uneven count on row " .. y) if (not details) return issues
end
-- check identical lines
for k, other in ipairs(rows) do
if filled and equal(other, row) and other ~= row then
add(issues, { "row", "identical", row, y, k })
if debug then printh("equal rows " .. k) end
if not details then return issues end
if (debug) printh("equal rows " .. k) if (not details) return issues
end
end
-- check triples
if self:count_consecutives(row) > 2 then
add(issues, { "row", "triples", row, y })
if debug then printh("triples") end
if not details then return issues end
if (debug) printh("triples") if (not details) return issues
end
end
@ -160,22 +147,19 @@ function Board.new()
-- check count
if filled and count(col, BLUE) ~= count(col, YELLOW) then
add(issues, { "col", "count", col, x })
if debug then printh("uneven count") end
if not details then return issues end
if (debug) printh("uneven count") if (not details) return issues
end
-- check identical lines
for k, other in ipairs(cols) do
if filled and equal(other, col) and other ~= col then
add(issues, { "col", "identical", col, x, k })
if debug then printh("equal cols") end
if not details then return issues end
if (debug) printh("equal cols") if (not details) return issues
end
end
-- check triples
if self:count_consecutives(col) > 2 then
add(issues, { "col", "triples", col, x })
if debug then printh("triples") end
if not details then return issues end
if (debug) printh("triples") if (not details) return issues
end
end
return issues
@ -246,8 +230,7 @@ function Board.new()
-- Set a random color
local z = self:get_random_zero()
self:fill(z, rnd({ BLUE, YELLOW }))
if debug then printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) end
return "invalid"
if (debug) printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) return "invalid"
end
return (changed or self:is_complete()) and "valid" or "invalid"
end,
@ -280,8 +263,7 @@ function Board.new()
-- do the surrounding
for item in all(neighbors) do
if item[1] then
if debug then printh("Surrounding at " .. item[1]) end
self:fill(item[1], tiles[item[2]], true)
if (debug) printh("Surrounding at " .. item[1]) self:fill(item[1], tiles[item[2]], true)
end
end
end
@ -297,8 +279,7 @@ function Board.new()
local prev = tiles[idx - 1]
local next = tiles[idx + 1]
if prev ~= 0 and prev == next then
if debug then printh("Splitting at " .. idx) end
self:fill(idx, prev, true)
if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
end
end
@ -307,8 +288,7 @@ function Board.new()
local prev = tiles[idx - width]
local next = tiles[idx + width]
if prev ~= 0 and prev == next then
if debug then printh("Splitting at " .. idx) end
self:fill(idx, prev, true)
if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
end
end
end
@ -341,7 +321,7 @@ function Board.new()
end,
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)
for i = idx, idx + width - 1 do
if self:get_tile(i) == 0 then
@ -351,7 +331,7 @@ function Board.new()
end,
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)
for i = idx, #tiles, width do
if self:get_tile(i) == 0 then
@ -447,15 +427,10 @@ function Board.new()
if color == 1 then fillp() else fillp() end
if self:is_locked(idx) then
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
roundedrect(x, y, w, w, color)
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)
pset(x + w - 2, y + w - 2, shade)
end
else
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)
-- poke(0x5f2e,1) --to keep colors
poke(0x5F2D, 1)
printh(" ")
printh("*************")
printh(" ")
@ -103,8 +101,6 @@ function _init()
printh("seed " .. date)
frame_count = 0
draw_mouse = false
last_mouse_pos = { 0, 0 }
states = {
rules = state_rules(),
@ -120,17 +116,9 @@ end
function _update60()
frame_count += 1
if btnp() > 0 then
draw_mouse = false
end
-- update mouse coords
mouse_x = stat(32)
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()
gs._update()
@ -142,7 +130,5 @@ function _draw()
overlay:_draw()
end
-- mouse cursor
if draw_mouse then
spr(1, mouse_x, mouse_y)
end
spr(1, mouse_x, mouse_y)
end

View File

@ -36,10 +36,7 @@ function state_loading()
board:reset()
repeat
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()
end
yield()
until board:is_complete()
until board:is_valid()

View File

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

View File

@ -79,7 +79,7 @@ function state_rules()
x = 44
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)
spr(2, x + 14, y + 21)
sspr(91, 32, 12, 12, x + 26, y + 20)