From 3dcb54db2aca986377b141ddbc617bc4da20e38d Mon Sep 17 00:00:00 2001 From: TehPers Date: Fri, 18 Aug 2017 01:54:25 -0700 Subject: [PATCH] Bugfixes, added command to set a face's values --- cube.lua | 27 +++++++++++++++++++++------ cubically.lua | 30 +++++++++++++++++++++++++++--- program.cb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 9 deletions(-) diff --git a/cube.lua b/cube.lua index eec788b..c7acc2c 100644 --- a/cube.lua +++ b/cube.lua @@ -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 }, { @@ -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 @@ -246,7 +261,7 @@ 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 @@ -254,7 +269,7 @@ function Cube:tostring() 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" @@ -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 diff --git a/cubically.lua b/cubically.lua index 8d3e94e..6bd8a18 100644 --- a/cubically.lua +++ b/cubically.lua @@ -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) @@ -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) @@ -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() @@ -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()) @@ -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() diff --git a/program.cb b/program.cb index 14ff651..baf858f 100644 --- a/program.cb +++ b/program.cb @@ -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'