Simple NxNxN Rubik's Cube Implementation made in Lua.
Creating a cube:
local Lubiks = require("Lubiks")
local Cube = Lubiks:new() -- default creates a 3x3 cube
print(Cube) -- prints cube:
--[[
W W W
W W W
W W W
O O O G G G R R R B B B
O O O G G G R R R B B B
O O O G G G R R R B B B
Y Y Y
Y Y Y
Y Y Y
]]
Executing moves:
local Lubiks = require("Lubiks")
local Cube = Lubiks:new() -- default creates a 3x3 cube
Cube:move("R U R' U'") -- moves R U R' U'
Cube:undoMove(2) -- undo moves R' U'
Scrambling a cube:
local Lubiks = require("Lubiks")
local Cube = Lubiks:new() -- default creates a 3x3 cube
local scramble = Cube:generateScramble(10) -- generates a 10 move long scramble string
Cube:move(scramble) -- scramble cube
Creating different sized cubes:
local Lubiks = require("Lubiks")
local Cube = Lubiks:new(2) -- creates a 2x2 cube
Cube:move("R U R' F' R U R' U' R' F R2 U' R' U'") -- Do a JPerm
print(Cube)
--[[
W W
W W
O O G R B G R B
O O G G R R B B
Y Y
Y Y
]]
Cube:setSize(3) -- resets cube and sets cube size to 3x3
print(Cube)
--[[
W W W
W W W
W W W
O O O G G G R R R B B B
O O O G G G R R R B B B
O O O G G G R R R B B B
Y Y Y
Y Y Y
Y Y Y
]]
function new(size: number = 3)
- Creates a new Cube
function reset()
- Resets the cube into its initial state
function solved(face_colors: table)
- Determines if the cube is solved/not
- Returns true if solved, false otherwise
function generateScramble(len: number, return_list: boolean)
- Generates and returns a len move scramble string
function undoMove(count: number = 1)
- Undoes an amount of moves from MoveHistory
- Perform a move on the cube [e.g.: "R U R' U'"]
function moveOnce(move: string, blockHistory: boolean)
- Move the cube once [e.g.: R, x2, 2r4]