Compare commits
5 Commits
84a05355d9
...
583d4af93e
Author | SHA1 | Date | |
---|---|---|---|
583d4af93e | |||
3bec0e91fe | |||
4c925cb911 | |||
7b256d0ef0 | |||
10191afb92 |
2
bg.lua
2
bg.lua
|
@ -1,5 +1,5 @@
|
||||||
function draw_animated_bg(startx)
|
function draw_animated_bg(startx)
|
||||||
if (amplitude <= 0) return
|
if amplitude <= 0 then return end
|
||||||
startx = startx or 0
|
startx = startx or 0
|
||||||
fillp(0b0101101001011010)
|
fillp(0b0101101001011010)
|
||||||
|
|
||||||
|
|
53
board.lua
53
board.lua
|
@ -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 = 8
|
local tile_width = 20
|
||||||
-- pixels
|
-- pixels
|
||||||
local padding = 1
|
local padding = 1
|
||||||
local tiles = {}
|
local tiles = {}
|
||||||
|
@ -12,6 +12,16 @@ 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
|
||||||
|
@ -124,19 +134,22 @@ 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) printh("uneven count on row " .. y) if (not details) return issues
|
if debug then printh("uneven count on row " .. y) end
|
||||||
|
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) printh("equal rows " .. k) if (not details) return issues
|
if debug then printh("equal rows " .. k) end
|
||||||
|
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) printh("triples") if (not details) return issues
|
if debug then printh("triples") end
|
||||||
|
if not details then return issues end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,19 +160,22 @@ 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) printh("uneven count") if (not details) return issues
|
if debug then printh("uneven count") end
|
||||||
|
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) printh("equal cols") if (not details) return issues
|
if debug then printh("equal cols") end
|
||||||
|
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) printh("triples") if (not details) return issues
|
if debug then printh("triples") end
|
||||||
|
if not details then return issues end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return issues
|
return issues
|
||||||
|
@ -230,7 +246,8 @@ 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) printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) return "invalid"
|
if debug then printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) end
|
||||||
|
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,
|
||||||
|
@ -263,7 +280,8 @@ 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) printh("Surrounding at " .. item[1]) self:fill(item[1], tiles[item[2]], true)
|
if debug then printh("Surrounding at " .. item[1]) end
|
||||||
|
self:fill(item[1], tiles[item[2]], true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -279,7 +297,8 @@ 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) printh("Splitting at " .. idx) self:fill(idx, prev, true)
|
if debug then printh("Splitting at " .. idx) end
|
||||||
|
self:fill(idx, prev, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -288,7 +307,8 @@ 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) printh("Splitting at " .. idx) self:fill(idx, prev, true)
|
if debug then printh("Splitting at " .. idx) end
|
||||||
|
self:fill(idx, prev, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -321,7 +341,7 @@ function Board.new()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
fill_row = function(self, y, color)
|
fill_row = function(self, y, color)
|
||||||
if (debug) printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow"))
|
if debug then printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow")) end
|
||||||
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
|
||||||
|
@ -331,7 +351,7 @@ function Board.new()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
fill_col = function(self, x, color)
|
fill_col = function(self, x, color)
|
||||||
if (debug) printh("Filling column " .. x .. " in " .. (color == BLUE and "blue" or "yellow"))
|
if debug then printh("Filling column " .. x .. " in " .. (color == BLUE and "blue" or "yellow")) end
|
||||||
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
|
||||||
|
@ -427,10 +447,15 @@ 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(█)
|
||||||
|
|
14
main.lua
14
main.lua
|
@ -93,6 +93,8 @@ 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(" ")
|
||||||
|
@ -101,6 +103,8 @@ 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(),
|
||||||
|
@ -116,9 +120,17 @@ 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()
|
||||||
|
@ -130,5 +142,7 @@ 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
|
|
@ -36,7 +36,10 @@ 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()
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ 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()
|
||||||
|
|
|
@ -79,7 +79,7 @@ function state_rules()
|
||||||
|
|
||||||
x = 44
|
x = 44
|
||||||
y = 90
|
y = 90
|
||||||
print("3) aLL ROWS AND COLUMNS\n ARE DIFFERENT", 2, y, 7)
|
print("3) aLL ROWS OR 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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user