Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title...

29
Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson <[email protected]> Depends R (>= 3.0.0) Imports grDevices, graphics, utils, stats, rgl Description Functions for visualizing, animating, solving and analyzing the Rubik's cube. Includes data structures for solvable and unsolvable cubes, random moves and random state scrambles and cubes, 3D displays and animations using 'OpenGL', patterned cube generation, and lightweight solvers. See Rokicki, T. (2008) <arXiv:0803.3435> for the Kociemba solver. License GPL-3 NeedsCompilation yes Repository CRAN Date/Publication 2018-04-23 12:29:32 UTC R topics documented: animate ........................................... 2 comparison ......................................... 4 composition ......................................... 5 cubieCube .......................................... 6 cycle ............................................. 8 getMovesCube ....................................... 9 getMovesPattern ...................................... 10 invCube ........................................... 11 invMoves .......................................... 12 move ............................................. 14 plot.cube ........................................... 15 1

Transcript of Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title...

Page 1: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

Package ‘cubing’April 23, 2018

Version 1.0-5

Date 2018-04-24

Title Rubik's Cube Solving

Author Alec Stephenson.

Maintainer Alec Stephenson <[email protected]>

Depends R (>= 3.0.0)

Imports grDevices, graphics, utils, stats, rgl

Description Functions for visualizing, animating, solving andanalyzing the Rubik's cube. Includes data structures forsolvable and unsolvable cubes, random moves and randomstate scrambles and cubes, 3D displays and animationsusing 'OpenGL', patterned cube generation, and lightweightsolvers. See Rokicki, T. (2008) <arXiv:0803.3435> for theKociemba solver.

License GPL-3

NeedsCompilation yes

Repository CRAN

Date/Publication 2018-04-23 12:29:32 UTC

R topics documented:animate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5cubieCube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8getMovesCube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9getMovesPattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10invCube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11invMoves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14plot.cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1

Page 2: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

2 animate

plot3D.cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16read.cubesolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18rotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20scramble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21solvable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23stickerCube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Index 28

animate Create Cube Animations

Description

Create cubing animation and record png frames using OpenGL.

Usage

animate(aCube, moves, fpt = 8, colvec = getOption("cubing.colors"), recolor = FALSE,bg = grey(0.8), rand.col = FALSE, size = 0.98, col.interior = grey(0.5),al.interior = 0.4, al.exterior = 1, start.delay = 2, move.delay = 0, rinit = 30,bbox = TRUE, bbcolor = "#333377", bbemission = "#333377", bbspecular = "#3333FF",bbshininess = 5, bbalpha = 0.5, movie = NULL, dir = file.path(getwd(), movie),verbose = TRUE, start.fdelay = fpt, end.fdelay = fpt, move.fdelay = 1, ...)

Arguments

aCube Any cube object.

moves A move sequence; either a single string or a character vector with one elementper move. Can include URFDLBEMS face turns, wide turns and xyz rotations.

fpt Number of frames per quarter turn. Must be a non-negative even integer. Wholecube rotations and wide moves use half the number of frames.

colvec Vector of sticker colors. The default is the cubing.colors option.

recolor If TRUE, previous rotations are ignored and therefore the cube is recolored wheninitially displayed.

bg Background color.

rand.col If TRUE then sticker colors are chosen at random and colvec is ignored.

size Size of the individual cubies. Must be less than one. Values closer to one givecubes that look stickerless because the gap between cubies decreases. Smallersizes give exploded cubes.

col.interior Color of the cube interior.

al.interior Alpha value of cube interior.

al.exterior Alpha value of cube exterior.

Page 3: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

animate 3

start.delay The delay in seconds added to the start.

move.delay The delay in seconds between moves (turns or rotations).

rinit The initial plot is rotated rinit degrees about the z-axis.

bbox Use a bounding box?

bbcolor Bounding box parameter.

bbemission Bounding box parameter.

bbspecular Bounding box parameter.

bbshininess Bounding box parameter.

bbalpha Bounding box parameter.

movie If movie is a character string, then a png file is saved for every frame, usingmovie as the base file name. The following arguments are only relevant whenmovie is a character string.

dir The directory where the png frames are stored. If the directory does not existthen it is created. By default the name of the directory is the same as the basefilename and is located within the working directory.

verbose Print progress on the saving of the png frames?

start.fdelay The number of additional repeated frames added to the start.

end.fdelay The number of additional repeated frames added to the end.

move.fdelay The number of additional repeated frames between moves (turns or rotations).

... Other parameters to be passed through to plotting functions.

Details

The move U3 represents three quarter turns in a clockwise direction, and so the animation is dif-ferent to the quarter turn anti-clockwise move U’, even though the resulting cube is the same. Thissimilarly applies to the U3’ and U moves, and to the half turn moves U2 and U2’. Wide turns canbe denoted by lower case or w notation, so u2 and Uw2 are equivalent.

This function uses the R package rgl which is an interface to OpenGL. During the animation, thecube can be rotated using a mouse, and the rotations will be captured in the png frames if movieis not NULL. See the documentation for the rgl package to explore the large number of optionsavailable.

Following the production of the png frames, you can create movies or gifs using external utilities.One powerful command line utility is ffmpeg. ImageMagick is a software suite which performssimilar conversions.

The plot3D function also uses the rgl package to produce interactive plots for individual cubes.

For a 2D version of the animate function, see plot.seqCubes.

See Also

plot3D.cube, plot.cube, plot.rotCubes, plot.seqCubes

Page 4: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

4 comparison

Examples

scramb <- "D2F2UF2DR2DBL'BRULRUL2FL'U'"aCube <- getMovesCube(scramb)mvs <- "x2D'R'L2'U'FU'F'D'U'U'R'y'R'U'Ry'RU'R'U'RUR'U'R'U'F'UFRU'"## Not run: animate(aCube, mvs, movie = "ChoWRSolve")

comparison Logical Comparison for Cube Objects

Description

Determine if two cubes are equal, accounting for recoloring and rotation.

Usage

## S3 method for class 'cube'aCube == bCube## S3 method for class 'cube'all.equal(target, current, ...)

Arguments

aCube, target Any cube object.

bCube, current Any cube object.

... Not used.

Details

Two cubes are defined to be equal via == if they are the same except perhaps for a recoloring. Thismeans that the permutation and orientation components are the same but the spatial orientationcomponent may be different.

Two cubes are defined to be the same via all.equal if and only if one cube is equal to the otherfollowing any of the 24 rotations of the whole cube (including the no rotation case).

For testing if two cubes are exactly identical, you can use the R function identical, however thecubes must be of the same type; either both cubieCubes or both stickerCubes.

Value

A logical value.

See Also

is.solvable, is.solved

Page 5: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

composition 5

Examples

aCube <- randCube()bCube <- rotate(aCube, "y'")aCube == bCube

composition Composition Operators For Cube Objects

Description

Composition operators for cubieCube objects.

Usage

aCube %v% bCubeaCube %e% bCubeaCube %c% bCube

Arguments

aCube A cubieCube object.

bCube A cubieCube object.

Details

Both arguments must be cubieCube objects, not stickerCube objects.

If A and B are cubes then A %v% B is the composition (or multiplication) of A and B. This meansthat if a and b are move sequences that produce A and B respectively from the solved cube I, thenA %v% B is produced using the combined move sequence ab applied to I. Typically we just writeAB for A %v% B.

Similarly to matrix multiplication, the operator %v% is associative but in general not commutative,with AI and IA both equal to A. Every 3x3x3 cube A has a unique inverse cube A’ where AA’ andA’A are both equal to I. The inverse cube can be calculated using the invCube function.

The %e% and %c% operators are similar to %v% but they compose only the edges and corners respec-tively. Use of these operators may create an unsolvable cube from two solvable cubes. They largelyexist for internal reasons. See the help page on cycleEdges for details of their impact on solvability.

Value

A cubieCube object

See Also

cycleEdges, getMovesCube, invCube, is.solvable, move

Page 6: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

6 cubieCube

Examples

aCube <- getCubieCube("Superflip")bCube <- getCubieCube("EasyCheckerboard")aCube %v% bCube

cubieCube Create and Convert CubieCubes

Description

Creates, converts and tests for cubieCube objects.

Usage

getCubieCube(pattern = c("Solved","Superflip","EasyCheckerboard","Wire","PlusMinus","Tablecloth","Spiral","SpeedsolvingLogo","VerticalStripes","OppositeCorners","Cross","UnionJack","CubeInTheCube","CubeInACubeInACube","Anaconda","Python","BlackMamba","GreenMamba","FourSpots","SixSpots","Twister","Kilt","Tetris","DontCrossLine","Hi","HiAllAround","AreYouHigh","CUAround","OrderInChaos","Quote","MatchingPictures","3T","LooseStrap","ZZLine","Doubler","CheckerZigzag","ExchangedDuckFeet","StripeDotSolved","Picnic","PercentSign","Mirror","PlusMinusCheck","FacingCheckerboards","OppositeCheckerboards","4Plus2Dots","Rockets","Slash","Pillars","TwistedDuckFeet","RonsCubeInACube","Headlights","CrossingSnake","Cage","4Crosses","Pyraminx","EdgeTriangle","TwistedRings","ExchangedRings","TwistedChickenFeet","ExchangedChickenFeet","CornerPyramid","TwistedPeaks","ExchangedPeaks","SixTwoOne","YinYang","YanYing","HenrysSnake","TwistedCorners","QuickMaths"))

cubieCube(string)as.cubieCube(aCube)is.cubieCube(aCube)

Arguments

pattern A character string giving a pattern for the returned cube. Approximately seventydifferent patterns are available. The default pattern is the solved cube. Thepatterns and names are derived from the ruwix.com website.

string A character string representing the color on each cube sticker. The string mustcontain only the letters URFLBD, representing the color on each face, and maycontain any amount of white space. There must be 9 occurrences of each letter,or 8 occurrences if the centre stickers are omitted. A character vector can also begiven instead of a character string, with one element for each letter. The stickertemplate can be displayed using the code at the end of the Examples sectionbelow.

aCube Any object.

Page 7: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

cubieCube 7

Details

The is.cubieCube function returns TRUE for cubieCube objects and FALSE otherwise. The as.cubieCubefunction converts a cube object to a cubieCube object and returns an error for other arguments.

The getCubieCube function creates cubieCube objects using known patterns. The cubieCube func-tion creates cubieCube objects using colors entered by the user. For alternative ways of creatingcubieCube objects, see randCube and getMovesCube.

A cubieCube is a list with five vector elements. The first four are cp ep co eo for the cornerpermuation, edge permuation, corner orientation, and edge orientation. The fifth, spor, tracks thefixed centres and therefore represents the spatial orientation. It exists to avoid recoloring the cubewhen plotting it after a rotation, middle slice move or wide move.

A stickerCube object does not hold information on spatial orientation, therefore if you convert acubieCube to a stickerCube, and then convert back to a cubieCube, the spor vector will be reset to1:6.

The cubieCube function contains a large amount of bulletproofing to ensure the cube has validcubies that are stickered correctly, but the cube may or may not be solvable. Both stickerCube andcubieCube objects are designed to hold both solvable and unsolvable cubes. You can test solvabilitywith the is.solvable function.

Value

A logical value for is.cubieCube. A cubieCube object for all other functions.

See Also

getMovesCube, is.solvable, randCube, stickerCube

Examples

aCube <- getCubieCube("Wire")bCube <- cubieCube("UUUUUUUUU RLLRRRLLR BBFFFFFBB DDDDDDDDD LRRLLLRRL FFBBBBBFF")cCube <- cubieCube("FBBBUFRRB DUUFRUFFB DBRBFDUFL FRDDDLDDL UUFULLLLL RDRRBLURB")identical(aCube, bCube)is.cubieCube(aCube)

## Not run: plot(aCube)## Not run: plot3D(aCube)## Not run: plot(cCube)## Not run: plot3D(cCube)

## Not run: plot(getCubieCube(), numbers = TRUE)## Not run: plot(getCubieCube(), numbers = TRUE, blank = TRUE)

Page 8: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

8 cycle

cycle Cycle and Twist Cubies

Description

Functions for cycling permuatations and altering orientations.

Usage

flipEdges(aCube, flip = 1:12)twistCorners(aCube, clock = numeric(0), anti = numeric(0))cycleEdges(aCube, cycle, right = TRUE, orient = TRUE)cycleCorners(aCube, cycle, right = TRUE, orient = TRUE)

Arguments

aCube A cubieCube object.

flip An integer vector subset of 1:12 giving the set of edges to flip. By default, alledges are flipped.

clock An integer vector subset of 1:8 giving the set of corners to twist clockwise. Bydefault, none are twisted.

anti An integer vector subset of 1:8 giving the set of corners to twist anti-clockwise.By default, none are twisted.

cycle An integer vector representing the permutation cycle. See Details.

right If FALSE, cycles to the left. See Details.

orient Controls the orientation change for the permuation cycle. If TRUE each cubie isre-oriented according to the cubie it replaces, so the orientation vector does notchange. If FALSE each cubie orientation is fixed so that the orientation vectoralso cycles.

Details

The cycle vector should be given according to mathematical cycle notation. For example, thevector c(5,3,7) means that the edge at position 5 moves to 3, 3 moves to 7 and 7 moves to 5. Thevectors c(3,7,5) and c(7,5,3) are equivalent. The length of the vector is the length of the cycle,and so this example is a 3-cycle. If right is FALSE it cycles in the opposite direction, so 7 movesto 3, 3 moves to 5 and 5 moves to 7.

All of these functions can change the solvability of a cube. Solvability of a cube can be testedusing the is.solvable function. For orientation solvability, the sum of the edge orientation vectormust be even, and the sum of the corner orientation vector must be divisible by three. For the edgeorientation to remain solvable, you must flip an even number of edges. For the corner orientationto remain solvable, the difference between the number of clockwise and anti-clockwise twists mustbe divisible by three. For example, the number of twists in each direction could be the same (adifference of zero), or you could have three clockwise twists and no anti-clockwise twists.

Page 9: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

getMovesCube 9

The sign of a permuation (even or odd) changes under a 2-cycle, which is just a swapping of twoelements. In mathematical terminology this is called a transposition. A k-cycle can be written ask-1 transpositions, and therefore a k-cycle will change the sign of a permuatation if and only if k iseven. So for a solvable cube to remain solvable, the length of cycle should be odd.

Two binary operators within the package that also impact solvability are %e% and %c%, which arecomposition operators for only edges and only corners respectively. If two cubes A and B aresolvable, then A %e% B may be unsolvable because the edge and corner permuations may be ofdifferent sign; the orientations will always remain solvable. It is also possibe for A %e% B to besolvable but B %e% A to be unsolvable. The same reasoning applies to %c%.

In detail: if A and B have odd permutations, then both A %e% B and B %e% A become unsolvable.If A and B have even permutations, then both A %e% B and B %e% A remain solvable. If A has evenand B has odd, then A %e% B is unsolvable but B %e% A is solvable.

Value

A cubieCube object.

See Also

%v%, is.solvable, is.solved, invCube

Examples

aCube <- getCubieCube("Superflip")aCube <- flipEdges(aCube, flip = 1:12)is.solved(aCube)aCube <- twistCorners(aCube, clock = 3:6, anti = 2)is.solvable(aCube)aCube <- cycleEdges(aCube, c(2,10,5,6))is.solvable(aCube)

getMovesCube Create a Cube for a Move Sequence

Description

Creates a cube that corresponds to a move sequence via post-multiplication.

Usage

getMovesCube(moves = character(0), cubie = TRUE)

Arguments

moves A move sequence; either a single string or a character vector with one elementper move. Can include URFDLB face turns. Cannot include rotations, middleslice moves or wide moves.

cubie If FALSE, produce a stickerCube rather than a cubieCube.

Page 10: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

10 getMovesPattern

Details

The cube object created by this function represents the application of the move sequence by meansof post-multiplication with the composition operator %v%. If A is a cube and m is the move sequence,then A %v% getMovesCube(m) is the cube that results from applying the move sequence to A. Inparticular, if A is the solved state then this is just getMovesCube(m). If m represents a scramblesequence, then getMovesCube(m) is the scrambled cube state.

The move sequence cannot include rotations, middle slice moves or wide moves because thesecannot be expressed via post-multiplication. To implement these moves, see the move and rotatefunctions.

Value

A cube object.

See Also

%v%, invMoves, move, rotate, slice

Examples

scramb <- "D2F2UF2DR2DBL'BRULRUL2FL'U'"aCube <- getMovesCube(scramb)mvs <- "x2D'R'L2'U'FU'F'D'U'U'R'y'R'U'Ry'RU'R'U'RUR'U'R'U'F'UFRU'"is.solved(move(aCube, mvs))

getMovesPattern Get Moves for Patterned Cubes

Description

Extracts the move sequence for a patterned cube.

Usage

getMovesPattern(pattern = c("Solved","Superflip","EasyCheckerboard","Wire","PlusMinus","Tablecloth","Spiral","SpeedsolvingLogo","VerticalStripes","OppositeCorners","Cross","UnionJack","CubeInTheCube","CubeInACubeInACube","Anaconda","Python","BlackMamba","GreenMamba","FourSpots","SixSpots","Twister","Kilt","Tetris","DontCrossLine","Hi","HiAllAround","AreYouHigh","CUAround","OrderInChaos","Quote","MatchingPictures","3T","LooseStrap","ZZLine","Doubler","CheckerZigzag","ExchangedDuckFeet","StripeDotSolved","Picnic","PercentSign","Mirror","PlusMinusCheck","FacingCheckerboards","OppositeCheckerboards","4Plus2Dots","Rockets","Slash","Pillars","TwistedDuckFeet","RonsCubeInACube","Headlights","CrossingSnake","Cage","4Crosses","Pyraminx","EdgeTriangle","TwistedRings","ExchangedRings","TwistedChickenFeet","ExchangedChickenFeet","CornerPyramid","TwistedPeaks","ExchangedPeaks","SixTwoOne","YinYang","YanYing","HenrysSnake","TwistedCorners","QuickMaths"))

Page 11: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

invCube 11

Arguments

pattern A character string giving a pattern for the corresponding cube. Approximatelyseventy different patterns are available. The default pattern is the solved cube,returning an empty character vector. The patterns and names are derived fromthe ruwix.com website.

Details

This function is mainly for internal use. It is used by the functions getCubieCube and getStickerCubeto produce patterned cubes via getMovesCube. The returned move sequence contains only URFDLBface turns.

Value

A character vector of moves.

See Also

getCubieCube, getMovesCube, getStickerCube

Examples

getMovesPattern()getMovesPattern("Solved")getMovesPattern("Wire")getMovesPattern("UnionJack")

invCube Calculate Inverse Cube

Description

Calculates the inverse of a cube.

Usage

invCube(aCube, edges = TRUE, corners = TRUE)

Arguments

aCube A cubieCube object.

edges If FALSE, the inverse is not taken for the edges.

corners If FALSE, the inverse is not taken for the corners.

Page 12: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

12 invMoves

Details

Every 3x3x3 cube A has a unique inverse cube A’ where AA’ and A’A are both equal to the solvedstate. The cube A does not need to be solvable. Larger cubes do not have unique inverses becauselarger cubes have indistinct pieces in the centres.

One use of the inverse is to enable the solver function to generate moves towards a target statethat is not the solved state. For an initial cube A and a target state B the solver is applied to B’A.The moves of the solver then represent post-multiplication by A’B, which when applied to A givesAA’B which is equal to B, the target state. Only B’A needs to be solvable; both A and B could beunsolvable.

A solvable cube will always remain solvable after the function invCube is applied, even if edgesor corners is FALSE. This is because the sign (even or odd) of a permutation is the same as the signof the inverse permutation.

Value

A cubieCube object.

See Also

%v%, invMoves, is.solvable, solver

Examples

aCube <- getCubieCube("Tetris")is.solved(aCube %v% invCube(aCube))is.solved(invCube(aCube) %v% aCube)

## Not run: plot(aCube)## Not run: plot(invCube(aCube))## Not run: plot3D(aCube)## Not run: plot3D(invCube(aCube))

invMoves Manipulate Move Sequences

Description

Invert, mirror and rotate move sequences, and calculate the order of a move sequence.

Usage

invMoves(moves, revseq = TRUE, collapse = NULL)mirMoves(moves, mirror = c("0","UD","DU","RL","LR","FB","BF"), collapse = NULL)rotMoves(moves, rotation = c("0","x","x1","x3'","y","y1","y3'","z","z1","z3'","x2","x2'","y2","y2'","z2","z2'","x'","x3","x1'","y'","y3","y1'","z'","z3","z1'"), invrot = FALSE, collapse = NULL)moveOrder(moves)

Page 13: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

invMoves 13

Arguments

moves A move sequence. Either a character sting, which may include white space, ora character vector where each element is a single move. For moveOrder, can in-clude only URFDLB face turns. For other functions, can include URFDLBEMSface turns, URFDLB wide turns and xyz rotations.

revseq If FALSE, the move sequence is not reversed so that only the direction of theturns is altered.

mirror The mirror to be used. The U/D mirror can be specified using the UD or DUcharacter string. Similarly for R/L and F/B.

rotation The rotation to be used.invrot Inverts the direction of the rotation.collapse If not NULL then the returned moves are output as a single string with collapse

as the separator, rather than a character vector of moves. If collapse is theempty string then a single string with no separator is returned.

Details

For moveOrder an integer value is returned giving the order of the move sequence, which is thenumber of times it needs to be applied for the solved cube to return to its solved state. The largestorder for any sequence is known to be 1260; for example, the order of "R U2 D' B D'" is 1260.

For other functions, a move sequence is returned. The returned move sequence will always use thecanonical form for the turn notation: U not U1, U’ not U1’, and Uw not u for wide turns. Howeverany form may be used for the input.

The Examples section below demonstrates the relationship between rotated move sequences. If therotation is r and the rotated move sequence is m, then the move sequence rmr’ is equivalent to theoriginal. If invrot is TRUE, then this becomes r’mr.

Value

A character vector of moves, or a character string if collapse is not NULL.

See Also

move, invCube, rotate, scramble

Examples

mv <- "RB'y'F2MD'"invMoves(mv)mirMoves(mv, mirror = "RL")

iCube <- getCubieCube("TwistedChickenFeet")rmv <- rotMoves(mv, rotation = "x")aCube <- move(iCube, c("x", rmv, "x'"))bCube <- move(iCube, mv)identical(aCube, bCube)

moveOrder("RU2D'BD'")

Page 14: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

14 move

move Moving a Cube and Creating a Move Sequence

Description

Applies moves to a cube and creates a move sequence.

Usage

move(aCube, moves, history = FALSE)## S3 method for class 'seqCubes'plot(x, initial = TRUE, which = 1:length(moves), ask = FALSE,

colvec = getOption("cubing.colors"), recolor = FALSE, show.rot = TRUE,title = NULL, cex.title = 1, font.title = 2, ...)

Arguments

aCube A cubieCube object.

moves A move sequence; either a single string or a character vector with one elementper move. Can include URFDLBEMS face turns, URFDLB wide turns and xyzrotations.

history If TRUE the output is a list containing the initial cube state and every subsequentcube state created during the move sequence. If FALSE (the default) only thefinal cube state is returned.

x An object produced by the move function when history is set to TRUE.

initial Plot the initial cube state?

which If only a subset of subsequent cube states are to be plotted, specify a subset ofthe numbers 1:length(moves).

ask If TRUE, the user is asked before each plot.

colvec Vector of sticker colors. The default is the cubing.colors option.

recolor If TRUE, the spatial orientation is ignored and therefore the cube is recolored.

show.rot Should rotation moves be plotted?

title If specified as a character string, the first plot represents a title page with titlein the centre. This is useful for putting a title page on multiple page graphingdevices such as pdf.

cex.title Size of title on title page.

font.title Font of title on title page.

... Other parameters to be passed through to plotting functions.

Page 15: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

plot.cube 15

Details

By default move gives the result of applying the move sequence moves to the cube aCube. All rota-tions xyz, face turns URFDLBEMS, and wide moves URFDLB are allowed. Moves specificationssuch as U U1 U’ U1’ U2 U2’ U3 U3’ and rotation specifications such as x x1 x’ x1’ x2 x2’ x3 x3’are all allowed. For wide moves, lower case lettering and w notation are both allowed, so u2 andUw2 are equivalent. If moves is a single string, it may contain any amount of white space.

The definition of the E M S middle slice moves is respectively given by D’Uy’ L’Rx’ B’Fz’. Inparticular, the S slice direction is different to what you may find elsewhere; the definition used forS in this package is consistent with the rotation directions.

When history is TRUE a list is created of class seqCubes. The list contains cubieCube objects. Thelength of the list is the number of moves plus one, where the first element of the list is the originalcube.

The plot.seqCubes function plots a list of class seqCubes. It can be regarded and a 2D version ofthe animate function. For permanent recording of the 2D plots for the move sequence, it is helpfulto open a multiple page graphing device such as pdf. A pdf file can then be created and used as aflick book.

Value

For move, either a cubieCube object, or (if history is TRUE) an object of class seqCubes, which isa list where each element is a cubieCube. An attribute of the list stores the move sequence.

See Also

animate, getMovesCube, invMoves, plot.cube, rotate, slice

Examples

scramb <- "D2F2UF2DR2DBL'BRULRUL2FL'U'"aCube <- getMovesCube(scramb)mvs <- "x2D'R'L2'U'FU'F'D'U'U'R'y'R'U'Ry'RU'R'U'RUR'U'R'U'F'UFRU'"is.solved(move(aCube, mvs))sCubes <- move(aCube, mvs, history = TRUE)## Not run: plot(sCubes, title = "SeungBeom Cho\nWorld Record Solve\n4.59")

## Not run: pdf("SeungBeomCho.pdf")## Not run: plot(sCubes, title = "SeungBeom Cho\nWorld Record Solve\n4.59")## Not run: dev.off()

plot.cube Cube Object 2D Plot

Description

Plots a 2D representation of a cube object.

Page 16: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

16 plot3D.cube

Usage

## S3 method for class 'cube'plot(x, colvec = getOption("cubing.colors"), recolor = FALSE,

xlab = "", ylab = "", main = "", centres = TRUE, numbers = FALSE,text.size = 1, text.col = "black", rand.col = FALSE, blank = FALSE,...)

Arguments

x Any cube object.

colvec Vector of sticker colors. The default is the cubing.colors option.

recolor If TRUE, previous rotations are ignored and therefore the cube is recolored.

xlab, ylab Plot labels.

main Plot title.

centres Add identifier text to the centre stickers.

numbers Add identifier text to all stickers.

text.size Size of text.

text.col Color of text. The default is black but if you are using black stickers then purpleis a good choice. White does not read well on yellow stickers.

rand.col If TRUE then sticker colors are chosen at random and colvec is ignored.

blank If TRUE then all colors are set to ghost white. This is designed to create a templateplot for the sticker naming schemes.

... Other parameters to be passed through to plotting functions.

See Also

animate, plot3D.cube, plot.rotCubes, plot.seqCubes

Examples

aCube <- getCubieCube("Superflip")## Not run: plot(aCube)

plot3D.cube Cube Object Interactive 3D Plot

Description

Plots an interactive 3D representation of a cube object using OpenGL.

Page 17: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

plot3D.cube 17

Usage

## S3 method for class 'cube'plot3D(x, colvec = getOption("cubing.colors"), recolor = FALSE,

bg = grey(0.8), rand.col = FALSE, size = 0.98, col.interior = grey(0.5),al.interior = 0.4, al.exterior = 1, rinit = 30, bbox = TRUE, bbcolor ="#333377", bbemission = "#333377", bbspecular = "#3333FF", bbshininess =5, bbalpha = 0.5, ...)

Arguments

x Any cube object.colvec Vector of sticker colors. The default is the cubing.colors option.recolor If TRUE, previous rotations are ignored and therefore the cube is recolored.bg Background color.rand.col If TRUE then sticker colors are chosen at random and colvec is ignored.size Size of the individual cubies. Must be less than one. Values closer to one give

cubes that look stickerless because the gap between cubies decreases. Smallersizes give exploded cubes.

col.interior Color of the cube interior.al.interior Alpha value of cube interior.al.exterior Alpha value of cube exterior.rinit The initial plot is rotated rinit degrees about the z-axis.bbox Use a bounding box?bbcolor Bounding box parameter.bbemission Bounding box parameter.bbspecular Bounding box parameter.bbshininess Bounding box parameter.bbalpha Bounding box parameter.... Other parameters to be passed through to plotting functions.

Details

This function uses the R package rgl which is an interface to OpenGL. The cube can be rotatedusing a mouse. See the documentation for the rgl package to explore the large number of optionsavailable.

The animate function also uses the rgl package to produce cubing animations.

See Also

animate, plot.cube, plot.rotCubes, plot.seqCubes

Examples

aCube <- getCubieCube("Superflip")## Not run: plot3D(aCube)

Page 18: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

18 read.cubesolve

read.cubesolve Read Cube Solving Reconstructions

Description

Reads cube solving scrambles and solutions for the cube solves website.

Usage

read.cubesolve(n, warn = FALSE)

Arguments

n A single integer n giving the id for the solve.

warn If FALSE, an error is returned when the id does not exist. If TRUE, a warning isgiven.

Details

The function reads from the html source of the www.cubesolv.es website, and may fail if the websitesubsequently changes.

Round brackets immediately followed by any single digit are expanded upon reading, for example(R U)4 becomes R U R U R U R U. All other round brackets are removed. Commutator andconjugate notation is not implemented, so square brackets cannot be used and a warning is given ifthey are found.

The website does not have automated checking and therefore a typographic error may lead to non-valid moves (or cubes that do not solve). This most commonly occurs when the space between twovalid moves is accidentally omitted.

Value

A list containing the scramble, solution and description. The scramble and solution items are char-acter vectors of moves. The description is a character string. If the scramble or solution (or both) ismissing, then length zero vectors are returned for these items.

See Also

getMovesCube, invMoves, is.solved, move

Examples

## Not run: cho <- read.cubesolve(4995)## Not run: aCube <- getMovesCube(cho$scramble)## Not run: mv <- cho$solution## Not run: is.solved(move(aCube, mv))

Page 19: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

rotate 19

rotate Perform Rotations, Wide Moves and Middle Slice Moves

Description

Functions for rotating the whole cube and performing middle slice (E M S) and wide (Uw Rw FwDw Lw Bw) moves.

Usage

wide(aCube, wmv)slice(aCube, smv)rotate(aCube, rot)

Arguments

aCube A cubieCube object.

smv A single string giving a middle slice move. Must be one of E E1 E’ E1’ E2 E2’E3 E3’ M M1 M’ M1’ M2 M2’ M3 M3’ S S1 S’ S1’ S2 S2’ S3 S3’.

wmv A single string giving a wide move. Lower case letters and w notation are bothallowed. For turns on the U face must be one of Uw u Uw1 u1 Uw’ u’ Uw1’ u1’Uw2 u2 Uw2’ u2’ Uw3 u3 Uw3’ u3’, and similarly for the R F D L B faces.

rot A rotation. This can be specified using an integer or a character string. If aninteger, must be a number between 1 and 24 representing one of the 24 possiblerotations in space. The number 1 is the no rotation case. If a character string,must be one of 0 x x1 x’ x1’ x2 x2’ x3 x3’ y y1 y’ y1’ y2 y2’ y3 y3’ z z1 z’z1’ z2 z2’ z3 z3’ where the 0 character string represents no rotation. Characterstrings correspond only to the 10 distinct rotations around the the x, y and z axes(including the no rotation case).

Details

These functions are used internally by the move function for performing rotations, wide moves andmiddle slice moves, but can also be called directly if you only need to perform a single move. Inmost circumstances it is better to use the move function.

The definition of the E M S middle slice moves is respectively given by D’Uy’ L’Rx’ B’Fz’. Inparticular, the S slice direction is different to what you may find elsewhere; the definition used forS in this package is consistent with the rotation directions.

Value

A cubieCube object.

See Also

move

Page 20: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

20 rotations

Examples

aCube <- getCubieCube("HenrysSnake")bCube <- slice(rotate(aCube, "z'"), "M2")cCube <- move(aCube, "z'M2")identical(bCube, cCube)

## Not run: plot(cCube)## Not run: plot3D(cCube)

rotations Create and Plot All Rotations of a Cube

Description

Creates and plots all 24 possible whole cube rotations.

Usage

rotations(aCube)## S3 method for class 'rotCubes'plot(x, which = 1:24, ask = FALSE, colvec =getOption("cubing.colors"), recolor = FALSE, ...)

Arguments

aCube A cubieCube object.

x An object produced by the rotations function.

which If only a subset of the rotations is to be plotted, specify a subset of the numbers1:24.

ask If TRUE, the user is asked before each plot.

colvec Vector of sticker colors. The default is the cubing.colors option.

recolor If TRUE, the spatial orientation is ignored and therefore the cube is recolored.

... Other parameters to be passed through to plotting functions.

Details

There are 24 possible spatial orientations, including the original no rotation case. The rotationsfunction produces all of these cubes as a list of class rotCubes, which can be subsequently plottedby plot.rotCubes.

The 24 cubes produced by rotations are all related to each other via some rotation and thereforethey are all the same as defined by the all.equal.cube function. If the original cube has symmetricproperties then the set of 24 may contain equivalent cubes as defined by the ==.cube operator. Inthe case of the solved cube all 24 will be equivalent.

Page 21: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

scramble 21

Value

For rotations, an object of class rotCubes, which is a list of length 24 where each element is acubieCube.

See Also

==.cube, all.equal.cube, rotate

Examples

rCubes <- rotations(randCube())all.equal(rCubes[[5]], rCubes[[10]])rCubes[[5]] == rCubes[[10]]## Not run: plot(rCubes)

scramble Generate Random Cubes, Moves and Scrambles

Description

Generate random cubes, random move sequences, and scrambles.

Usage

randCube(n = 1, cubie = TRUE, solvable = TRUE, drop = TRUE, spor = 1:6)randMoves(n = 1, nm = 20, drop = TRUE)scramble(n = 1, state = FALSE, nm = 20, drop = TRUE, type = c("KB", "ZT",

"TF", "ZZ", "CFOP"), maxMoves = 24, bound = TRUE)

Arguments

n Number of cubes, move sequences or scrambles to generate.

cubie If FALSE, simulate stickerCubes rather than cubieCubes.

solvable If FALSE, then solvable and unsolvable cubes can be simulated. See Details.

drop If FALSE, then a list of one element is returned when n is equal to one.

spor The spatial orientation vector that is added to each simulated cubieCube.

nm The number of moves in the move sequence or the scramble. Ignored for scrambleif state is TRUE.

state If FALSE (the default), use a random moves scramble. If TRUE, use a randomstate scramble.

type The type of solver used for the random state scramble. This and all followingarguments are ignored unless state is TRUE.

maxMoves Argument passed to the solver.

bound Argument passed to the solver.

Page 22: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

22 solvable

Details

If solvable is TRUE, the randCube function generates a solvable cube where every solvable state isequally likely. If solvable is FALSE, it generates a random cube where every obtainable physicalconstruction is equally likely. The resulting cube may or may not be solvable: the chance of it beingsolvable is only 1 in 12.

The randMoves function generates a random move sequence using URFDLB face turns, restrictedso that you cannot get two moves in a row on the same face, or three moves in a row on opposingfaces. An alternative way of constructing a random cube is getMovesCube(randMoves()). If nm is20 or more then every solvable state has a non-zero chance of occuring, but the states will not beequally likely to occur.

The scramble function generates random move scrambles by default (which just uses the randMovesfunction), but will generate random state scrambles when state is TRUE.

Value

A cube object or list of cube objects for randCube. A move sequence or list of move sequences forrandMoves and scramble.

See Also

getMovesCube, invCube, invMoves, is.solvable, solver

Examples

randCube()getMovesCube(randMoves())sapply(randCube(20, solvable = FALSE), is.solvable)randMoves(5, nm = 25)scramble(nm = 17)scramble(state = TRUE, type = "ZT", maxMoves = 24)

solvable Solved and Solvability Tests for Cube Objects

Description

Determine if a cube is solved or solvable, and calculate the sign of the corner and edge permutations.

Usage

is.solved(aCube, split = FALSE, co = TRUE, eo = TRUE)is.solvable(aCube, split = FALSE)parity(aCube)

Page 23: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

solver 23

Arguments

aCube Any cube object.

split Split output into logical vector? See Details.

co If FALSE, ignore corner orientation.

eo If FALSE, ignore edge orientation.

Details

The cubieCube and stickerCube objects contain Rubik’s cubes that can be physically constructedfrom properly stickered cubies, but they are not necessarily solvable. These functions test for solvedand solvable cubes. The parity function gives the permuation sign (+1 for even and -1 for odd) forthe corner and edge permuations. For a cube to be solvable, the two signs must be the same.

For is.solved, a logical value for each separate permutation and orientation component will begiven if split is TRUE.

For is.solvable, logical values corresponding to permuatation parity, edge orientation and cornerorientation will be given if split is TRUE. The cube is only solvable if all three values are TRUE.The edge and corner orientation values correspond to the fact that if all but one edge (or corner)orientation is known, then the orientation of the final edge (or corner) must be fixed for the cube tobe solvable. More precisely, the sum of the edge orientation vector must be even, and the sum ofthe corner orientation vector must be divisible by three.

Value

A logical value or vector for is.solved and is.solvable. A named integer vector of length twofor parity.

See Also

==.cube, randCube, solver

Examples

aCube <- randCube()is.solvable(aCube)aCube <- randCube(solvable = FALSE)is.solvable(aCube)

solver Rubik’s Cube Solver

Description

Cube solvers to generate moves to a target cube state.

Page 24: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

24 solver

Usage

solver(aCube, tCube, type = c("KB", "ZT", "TF"), inv = FALSE,maxMoves = switch(type, KB = 24, ZT = 20, TF = 16), bound =TRUE, collapse = NULL, divide = FALSE, history = FALSE,verbose = FALSE)

Arguments

aCube A cubieCube object giving the cube to be solved. If tCube is not specified thenthe object must be solvable.

tCube A cubieCube object giving the target state. If not specified, then the target stateis the solved state. See Details.

type The type of solver used. KB is Kociemba. ZT is Zemdegs-Twist. TF is Twist-Flip.

inv If TRUE the moves are inverted. For producing random state scrambles.

maxMoves The maximum number of moves allowed for the search phases of the algorithm.The search algorithm may take a long time for smaller move requirements. Thedefault value depends on the solver.

bound By default the maxMoves value cannot be too small to avoid the search algorithmtaking an excessively long time or never returning. If bound is set to FALSEthis safety measure is removed, allowing any value of maxMoves to be specified.This is not recommended unless you know the cube can be solved within a smallnumber of moves.

collapse If not NULL then the returned moves are output as a single string with collapseas the separator, rather than a character vector of moves. If collapse is theempty string then a single string with no separator is returned.

divide If TRUE, a period symbol is placed between the phases of the search algorithm.

history If TRUE the solver returns a list where the second element gives a matrix objectthat provides information on the history of the search algorithm. Mainly usedfor debugging.

verbose If TRUE print details of the status of the search. Mainly used for debugging.

Details

The solver produces a move sequence that brings aCube to either a solved state or to the target statetCube. If the target state is specified, then invCube(tCube) %v% aCube must be solvable, but thetwo cubes aCube and tCube could be unsolvable. See the help file on invCube for more details.

The KB algorithm is a 2-phase search. The ZT algorithm is similar but allows for twisting cornersat the end to solve the corner orientation. The TF algorithm allows for twisting corners and flippingedges at the end to solve both corner and edge orientation. The twisting and flipping procedures aregiven as attributes in the returned object. If inv is TRUE, then they need to be performed at the startfrom the solved (or target) state.

The ZT and TF solvers may not produce a smaller move count than KB because the aim of thesolver is to return any solution that consists of maxMoves moves or less. If smaller move counts arerequired then maxMoves should be specified.

Page 25: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

stickerCube 25

These solvers are lightweight in the sense that they use small look-up tables (move tables and prunetables). If maxMoves is small then it can take a few seconds to find a solution.

The look-up tables for a solver are silently loaded into memory the first time the solver is used. Thetables are hidden objects that are not visible to the user. If you wish to ensure that all tables arealready loaded into memory (for example, if you want to do timing comparisons), then you can runeach type of solver once, using any cube other than the solved (or target) state.

The solvers will never produce two moves in a row on the same face, but may produce three (oreven four) moves in a row on opposite faces if this coincides with the break between the two searchphases. They cannot produce three moves in a row on opposite faces within the same search phase.This behaviour is a design choice in order to minimize second phase solutions that are rejected dueto move sequences across the phase break.

Value

A character vector of moves, or a character string if collapse is not NULL. For ZT the vector (orstring) has a twist attribute. For TF the vector (or string) has twist and flip attributes.

If history is TRUE, then a list of length two is returned where the second element is a matrix thatprovides information on the history of the search algorithm.

See Also

getMovesCube, invCube, invMoves, is.solvable, scramble

Examples

aCube <- getCubieCube("EasyCheckerboard")## Not run: plot(aCube)## Not run: plot3D(aCube)mvs <- solver(aCube, type = "KB")is.solved(aCube %v% getMovesCube(mvs))

stickerCube Create and Convert StickerCubes

Description

Creates, converts and tests for stickerCube objects.

Usage

getStickerCube(pattern = c("Solved","Superflip","EasyCheckerboard","Wire","PlusMinus","Tablecloth","Spiral","SpeedsolvingLogo","VerticalStripes","OppositeCorners","Cross","UnionJack","CubeInTheCube","CubeInACubeInACube","Anaconda","Python","BlackMamba","GreenMamba","FourSpots","SixSpots","Twister","Kilt","Tetris","DontCrossLine","Hi","HiAllAround","AreYouHigh","CUAround","OrderInChaos","Quote","MatchingPictures","3T","LooseStrap","ZZLine","Doubler","CheckerZigzag","ExchangedDuckFeet","StripeDotSolved","Picnic","PercentSign","Mirror",

Page 26: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

26 stickerCube

"PlusMinusCheck","FacingCheckerboards","OppositeCheckerboards","4Plus2Dots","Rockets","Slash","Pillars","TwistedDuckFeet","RonsCubeInACube","Headlights","CrossingSnake","Cage","4Crosses","Pyraminx","EdgeTriangle","TwistedRings","ExchangedRings","TwistedChickenFeet","ExchangedChickenFeet","CornerPyramid","TwistedPeaks","ExchangedPeaks","SixTwoOne","YinYang","YanYing","HenrysSnake","TwistedCorners","QuickMaths"))

stickerCube(string)as.stickerCube(aCube)is.stickerCube(aCube)

Arguments

pattern A character string giving a pattern for the returned cube. Approximately seventydifferent patterns are available. The default pattern is the solved cube. Thepatterns and names are derived from the ruwix.com website.

string A character string representing the color on each cube sticker. The string mustcontain only the letters URFLBD, representing the color on each face, and maycontain any amount of white space. There must be 9 occurrences of each letter,or 8 occurrences if the centre stickers are omitted. A character vector can also begiven instead of a character string, with one element for each letter. The stickertemplate can be displayed using the code at the end of the Examples sectionbelow.

aCube Any object.

Details

The is.stickerCube function returns TRUE for stickerCube objects and FALSE otherwise. Theas.stickerCube function converts a cube object to a stickerCube object and returns an error forother arguments.

The getStickerCube function creates stickerCube objects using known patterns. The stickerCubefunction creates stickerCube objects using colors entered by the user. For alternative ways of creat-ing stickerCube objects, see randCube and getMovesCube.

A stickerCube is a named character vector of length 54 where each element is one of the sixletters URFLBD. The element named U5 is always equal to the character string U as this representsa centre sticker. The elements named R5 F5 L5 B5 D5 are similarly fixed.

The stickerCube function contains a large amount of bulletproofing to ensure the cube has validcubies that are stickered correctly, but the cube may or may not be solvable. Both stickerCube andcubieCube objects are designed to hold both solvable and unsolvable cubes. You can test solvabilitywith the is.solvable function.

Value

A logical value for is.stickerCube. A stickerCube object for all other functions.

See Also

getMovesCube, is.solvable, randCube, cubieCube

Page 27: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

stickerCube 27

Examples

aCube <- getStickerCube("Wire")bCube <- stickerCube("UUUUUUUUU RLLRRRLLR BBFFFFFBBD DDDDDDDDL RRLLLRRLF FBBBBBFF")cCube <- stickerCube("FBBBUFRRB DUUFRUFFB DBRBFDUFLF RDDDLDDLU UFULLLLLR DRRBLURB")identical(aCube, bCube)is.stickerCube(aCube)

## Not run: plot(aCube)## Not run: plot3D(aCube)## Not run: plot(cCube)## Not run: plot3D(cCube)

## Not run: plot(getStickerCube(), numbers = TRUE)## Not run: plot(getStickerCube(), numbers = TRUE, blank = TRUE)

Page 28: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

Index

∗Topic distributionscramble, 21

∗Topic dynamicanimate, 2plot3D.cube, 16

∗Topic hplotmove, 14plot.cube, 15rotations, 20

∗Topic manipcomparison, 4composition, 5cubieCube, 6cycle, 8getMovesCube, 9getMovesPattern, 10invCube, 11invMoves, 12move, 14read.cubesolve, 18rotate, 19rotations, 20solvable, 22solver, 23stickerCube, 25

==.cube, 21, 23==.cube (comparison), 4%c% (composition), 5%e% (composition), 5%v% (composition), 5%v%, 9, 10, 12

all.equal.cube, 21all.equal.cube (comparison), 4animate, 2, 15–17as.cubieCube (cubieCube), 6as.stickerCube (stickerCube), 25

comparison, 4composition, 5

cubieCube, 6, 26cycle, 8cycleCorners (cycle), 8cycleEdges, 5cycleEdges (cycle), 8

flipEdges (cycle), 8

getCubieCube, 11getCubieCube (cubieCube), 6getMovesCube, 5, 7, 9, 11, 15, 18, 22, 25, 26getMovesPattern, 10getStickerCube, 11getStickerCube (stickerCube), 25

invCube, 5, 9, 11, 13, 22, 25invMoves, 10, 12, 12, 15, 18, 22, 25is.cubieCube (cubieCube), 6is.solvable, 4, 5, 7, 9, 12, 22, 25, 26is.solvable (solvable), 22is.solved, 4, 9, 18is.solved (solvable), 22is.stickerCube (stickerCube), 25

mirMoves (invMoves), 12move, 5, 10, 13, 14, 18, 19moveOrder (invMoves), 12

parity (solvable), 22plot.cube, 3, 15, 15, 17plot.rotCubes, 3, 16, 17plot.rotCubes (rotations), 20plot.seqCubes, 3, 16, 17plot.seqCubes (move), 14plot3D (plot3D.cube), 16plot3D.cube, 3, 16, 16

randCube, 7, 23, 26randCube (scramble), 21randMoves (scramble), 21read.cubesolve, 18

28

Page 29: Package ‘cubing’ - R · Package ‘cubing’ April 23, 2018 Version 1.0-5 Date 2018-04-24 Title Rubik's Cube Solving Author Alec Stephenson. Maintainer Alec Stephenson

INDEX 29

rotate, 10, 13, 15, 19, 21rotations, 20rotMoves (invMoves), 12

scramble, 13, 21, 25slice, 10, 15slice (rotate), 19solvable, 22solver, 12, 22, 23, 23stickerCube, 7, 25

twistCorners (cycle), 8

wide (rotate), 19