Skip to content

Commit 3dcb54d

Browse files
committed
Bugfixes, added command to set a face's values
1 parent 7177254 commit 3dcb54d

File tree

3 files changed

+93
-9
lines changed

3 files changed

+93
-9
lines changed

cube.lua

+21-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ function Cube.new(size)
1717
faces.F = faces[2]
1818
faces.B = faces[4]
1919

20+
local faceValues = {}
21+
for i = 0, 5 do
22+
faceValues[i] = i
23+
end
24+
2025
return setmetatable({
2126
faces = faces,
27+
faceValues = faceValues,
2228
size = size,
2329
sizeSquared = sizeSquared
2430
}, {
@@ -224,18 +230,27 @@ function Cube:B(n, depth)
224230
end
225231
end
226232

233+
function Cube:setFace(index, n)
234+
if not index or index < 0 or index > 5 or index % 1 ~= 0 then
235+
return
236+
end
237+
n = n or index
238+
self.faceValues[index] = n
239+
end
240+
227241
function Cube:value(n, index)
228-
if n < 0 or n > 5 or n % 1 ~= 0 then
242+
if not n or n < 0 or n > 5 or n % 1 ~= 0 then
229243
return 0
230244
end
231245

232246
if index then
233-
return self.faces[n][index] or 0
247+
local f = self.faces[n][index]
248+
return f and self.faceValues[f] or 0
234249
end
235250

236251
local sum = 0
237252
for i = 0, self.sizeSquared - 1 do
238-
sum = sum + self.faces[n][i]
253+
sum = sum + self.faceValues[self.faces[n][i]]
239254
end
240255
return sum
241256
end
@@ -246,15 +261,15 @@ function Cube:tostring()
246261
for y = 0, size - 1 do
247262
s = s .. (" "):rep(size)
248263
for x = 0, size - 1 do
249-
s = s .. self.faces.U[self:index(x, y)]
264+
s = s .. self:value(0, self:index(x, y))
250265
end
251266
s = s .. "\n"
252267
end
253268

254269
for y = 0, size - 1 do
255270
for i = 1, 4 do
256271
for x = 0, size - 1 do
257-
s = s .. self.faces[i][self:index(x, y)]
272+
s = s .. self:value(i, self:index(x, y))
258273
end
259274
end
260275
s = s .. "\n"
@@ -263,7 +278,7 @@ function Cube:tostring()
263278
for y = 0, size - 1 do
264279
s = s .. (" "):rep(size)
265280
for x = 0, size - 1 do
266-
s = s .. self.faces.D[self:index(x, y)]
281+
s = s .. self:value(5, self:index(x, y))
267282
end
268283
s = s .. "\n"
269284
end

cubically.lua

+27-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ C.commands = {
245245
self.notepad = n and bit32.bxor(self.commandIndex or self.notepad, n) or bit32.bnot(self.commandIndex or self.notepad)
246246
end,
247247
['¬'] = function(self, n)
248-
self.notepad = (n or self.notepad) and 0 or 1
248+
self.notepad = (n or self.notepad) == 0 and 1 or 0
249249
end,
250250

251251
['>n'] = function(self, n)
@@ -285,6 +285,8 @@ C.commands = {
285285
else
286286
label.args = nil
287287
end
288+
289+
label.index = self.commandIndex
288290
end,
289291
[')'] = function(self, n)
290292
local label = table.remove(self.loops)
@@ -299,8 +301,8 @@ C.commands = {
299301
end
300302
end
301303
end,
302-
['?n'] = function(self, n)
303-
if n == 0 then
304+
['?'] = function(self, n)
305+
if (n or self.notepad) == 0 then
304306
self.conditionFailed = true
305307
if not self.options.experimental then
306308
self:skipcmd()
@@ -377,6 +379,21 @@ C.commands = {
377379
[''] = function(self, n)
378380
self.cube = Cube.new(n)
379381
end,
382+
['fi'] = function(self, n)
383+
self.cube:setFace(self.commandIndex, n)
384+
end,
385+
386+
['p'] = function(self, n)
387+
n = n or self.notepad
388+
local sqrt = math.sqrt(n)
389+
for i = 2, sqrt do
390+
if i % n == 0 then
391+
self.notepad = 0
392+
return
393+
end
394+
end
395+
self.notepad = 1
396+
end,
380397

381398
['#x'] = function(self, n)
382399
print(self.cube:tostring())
@@ -400,6 +417,13 @@ C.commands = table.iterator(C.commands)
400417
end
401418
end
402419

420+
if args:match("i") then
421+
local f = func
422+
func = function(self, n)
423+
return self.commandIndex and f(self, n) or nil
424+
end
425+
end
426+
403427
return cmd, args, func
404428
end)
405429
:totable()

program.cb

+45
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,51 @@
44
UR'UF'D2
55
■:𝟘
66

7+
■𝟝
8+
f₀𝟛₂f₁𝟛₅f₂𝟛₅
9+
f₀f₁f₂
10+
D₁D₃
11+
B₀.B₂.D₁2D₃2.F₄.
12+
^ bugged, it calls B₂
13+
D₁D₃
14+
15+
.
16+
R₁R₃F₁F₃
17+
18+
02020
19+
11111
20+
02020
21+
11111
22+
02020
23+
24+
$
25+
-₀𝟝(+𝟝
26+
f₄6
27+
:7(
28+
f₅6
29+
-₀𝟝(+𝟝
30+
f₃6
31+
*₅4₀+3₀@0⁶
32+
:3₀
33+
-𝟜)6
34+
@𝟙₀
35+
:5₀
36+
-𝟙)6
37+
:4₀
38+
-𝟜)6
39+
40+
.
41+
42+
-₀𝟚₅(+𝟚₅
43+
@0⁶
44+
45+
-𝟚₄
46+
47+
f₃6
48+
%⁶𝟝?@𝟙₀
49+
:3₀
50+
)6
51+
752
$:7(UR'UF'D𝟚-𝟙)6
853
(
954
D𝟚FU'RU'

0 commit comments

Comments
 (0)