Skip to content

Commit

Permalink
Bugfixes, added command to set a face's values
Browse files Browse the repository at this point in the history
  • Loading branch information
TehPers committed Aug 18, 2017
1 parent 7177254 commit 3dcb54d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
27 changes: 21 additions & 6 deletions cube.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ function Cube.new(size)
faces.F = faces[2]
faces.B = faces[4]

local faceValues = {}
for i = 0, 5 do
faceValues[i] = i
end

return setmetatable({
faces = faces,
faceValues = faceValues,
size = size,
sizeSquared = sizeSquared
}, {
Expand Down Expand Up @@ -224,18 +230,27 @@ function Cube:B(n, depth)
end
end

function Cube:setFace(index, n)
if not index or index < 0 or index > 5 or index % 1 ~= 0 then
return
end
n = n or index
self.faceValues[index] = n
end

function Cube:value(n, index)
if n < 0 or n > 5 or n % 1 ~= 0 then
if not n or n < 0 or n > 5 or n % 1 ~= 0 then
return 0
end

if index then
return self.faces[n][index] or 0
local f = self.faces[n][index]
return f and self.faceValues[f] or 0
end

local sum = 0
for i = 0, self.sizeSquared - 1 do
sum = sum + self.faces[n][i]
sum = sum + self.faceValues[self.faces[n][i]]
end
return sum
end
Expand All @@ -246,15 +261,15 @@ function Cube:tostring()
for y = 0, size - 1 do
s = s .. (" "):rep(size)
for x = 0, size - 1 do
s = s .. self.faces.U[self:index(x, y)]
s = s .. self:value(0, self:index(x, y))
end
s = s .. "\n"
end

for y = 0, size - 1 do
for i = 1, 4 do
for x = 0, size - 1 do
s = s .. self.faces[i][self:index(x, y)]
s = s .. self:value(i, self:index(x, y))
end
end
s = s .. "\n"
Expand All @@ -263,7 +278,7 @@ function Cube:tostring()
for y = 0, size - 1 do
s = s .. (" "):rep(size)
for x = 0, size - 1 do
s = s .. self.faces.D[self:index(x, y)]
s = s .. self:value(5, self:index(x, y))
end
s = s .. "\n"
end
Expand Down
30 changes: 27 additions & 3 deletions cubically.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ C.commands = {
self.notepad = n and bit32.bxor(self.commandIndex or self.notepad, n) or bit32.bnot(self.commandIndex or self.notepad)
end,
['¬'] = function(self, n)
self.notepad = (n or self.notepad) and 0 or 1
self.notepad = (n or self.notepad) == 0 and 1 or 0
end,

['>n'] = function(self, n)
Expand Down Expand Up @@ -285,6 +285,8 @@ C.commands = {
else
label.args = nil
end

label.index = self.commandIndex
end,
[')'] = function(self, n)
local label = table.remove(self.loops)
Expand All @@ -299,8 +301,8 @@ C.commands = {
end
end
end,
['?n'] = function(self, n)
if n == 0 then
['?'] = function(self, n)
if (n or self.notepad) == 0 then
self.conditionFailed = true
if not self.options.experimental then
self:skipcmd()
Expand Down Expand Up @@ -377,6 +379,21 @@ C.commands = {
[''] = function(self, n)
self.cube = Cube.new(n)
end,
['fi'] = function(self, n)
self.cube:setFace(self.commandIndex, n)
end,

['p'] = function(self, n)
n = n or self.notepad
local sqrt = math.sqrt(n)
for i = 2, sqrt do
if i % n == 0 then
self.notepad = 0
return
end
end
self.notepad = 1
end,

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

if args:match("i") then
local f = func
func = function(self, n)
return self.commandIndex and f(self, n) or nil
end
end

return cmd, args, func
end)
:totable()
Expand Down
45 changes: 45 additions & 0 deletions program.cb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@
UR'UF'D2
■:𝟘

■𝟝
f₀𝟛₂f₁𝟛₅f₂𝟛₅
f₀f₁f₂
D₁D₃
B₀.B₂.D₁2D₃2.F₄.
^ bugged, it calls B₂
D₁D₃

.
R₁R₃F₁F₃

02020
11111
02020
11111
02020

$
-₀𝟝(+𝟝
f₄6
:7(
f₅6
-₀𝟝(+𝟝
f₃6
*₅4₀+3₀@0⁶
:3₀
-𝟜)6
@𝟙₀
:5₀
-𝟙)6
:4₀
-𝟜)6

.

-₀𝟚₅(+𝟚₅
@0⁶

-𝟚₄

f₃6
%⁶𝟝?@𝟙₀
:3₀
)6

$:7(UR'UF'D𝟚-𝟙)6
(
D𝟚FU'RU'
Expand Down

0 comments on commit 3dcb54d

Please sign in to comment.