-
Notifications
You must be signed in to change notification settings - Fork 0
RubikHelper API RubikUtils
RubikHelper.static.RubikUtilsStatic Class that provides lots of methods and properties used by Rubik-family Classes.
| name | type | notes |
|---|---|---|
colors |
Object |
|
patterns |
Object |
|
pieces |
Object |
Group of methods which return Boolean values to check the type of the given move.
| name | returns | notes |
|---|---|---|
face(move) |
Boolean |
Checks if the given string is actually a cube's face |
slice(move) |
Boolean |
Checks if the given string is actually a cube's slice |
axis(move) |
Boolean |
Checks if the given string is actually a cube rotation |
move(move) |
Boolean |
Checks if the given string is a correct move (face, slice or axis) |
modifier(move) |
Boolean |
Checks if the given string is actually a modifier |
rotation(move) |
Boolean |
Checks if the given string is actually a single rotation |
median(move) |
Boolean |
Checks if the given string is actually a median piece |
pattern(move) |
Boolean |
Checks if the given string is actually a stored pattern |
piece(move) |
Boolean |
Checks if the given string is actually a cube's piece (edge or corner) |
edge(move) |
Boolean |
Checks if the given string is actually an edge piece |
corner(move) |
Boolean |
Checks if the given string is actually a corner piece |
buffer(move) |
Boolean |
Checks if the given string is actually a buffer piece |
Group of methods which return a Boolean values if the given move can be processed as intended.
| name | returns | notes |
|---|---|---|
negative(move) |
Boolean |
Checks if given move can be negative |
mirror(move) |
Boolean |
Checks if given move can be mirrored |
accepted(move, only, but) |
Boolean |
Checks if given move is one of only param or is not one of but param |
Group of service methods used inside and outside the Rubik-family Classes.
| name | returns | notes |
|---|---|---|
targetOf(piece) |
String |
Returns the correct orientation of a piece |
moveCounter(pattern, move) |
Number |
Count how many times the given move appears into pattern
|
cloneCube(cube) |
Object |
Returns an object representing the scrambled cube |
getPieceFromStickers(stickers, cube) |
`String | Boolean` |
getStickersFromPiece(piece, cube, includeMedian) |
String |
Returns the position of the given stickers inside the scrambled cube |
getRotation(piece, toTarget) |
Number |
Returns the position of the given stickers inside the scrambled cube |
rotate(piece, dir) |
String |
Returns the given piece rotated clockwise or counterclockwise |
replaceMove(moves, move, rep) |
Array |
Replace the given move with rep inside the moves array |
notAcceptedWithPiece(piece) |
Array |
Returns an array of faces which will be no longer accepted for creating a piece |
Group of methods which have kind of mathematical purposes (in rubik world).
| name | returns | notes |
|---|---|---|
multiply(moves, times) |
Array |
Returns a sequence of moves repeated N times |
negative(move) |
String |
Returns the negative of move
|
inverse(move) |
String |
Returns the negative of move (see notes) |
mirror(move, slice) |
String |
Returns the mirror of move depending on slice
|
negativePattern(moves, only, but) |
Array |
Returns a pattern with all negative signs |
inversePattern(moves, only, but) |
Array |
Returns an inverse pattern from the given one (it goes backward, and with negative signs) |
mirrorPattern(moves, slice) |
Array |
Returns the mirror pattern depending on slice
|
signSum(sign_a, sign_b) |
String |
Performs a sign sum |
signInverse(sign) |
String |
Returns the inverse of given sign |
Group of methods which expand the given piece or pattern to a full list of moves.
| name | returns | notes |
|---|---|---|
piece(piece, full) |
Array |
Returns the array of moves corresponding to the setup of the given piece |
pattern(pattern) |
Array |
Returns an array of moves combining the mix of given patterns |
Group of methods for parsing purposes.
| name | returns | notes |
|---|---|---|
moves(sequence, uncollapse, caseSensitive, keepCase) |
Array |
Returns an array of simple moves from an user typed sequence of moves |
pieces(pieces, uncollapse) |
Array |
Returns an array of simple moves from an user typed sequence of pieces or patterns (comma separated) |
Group of methods for clear the user typed sequence.
| name | returns | notes |
|---|---|---|
all(sequence) |
String |
Returns a string with only accepted moves (faces, slices, axis, pieces, patterns) |
pieces(sequence) |
String |
Returns a comma separated string with only accepted moves and patterns (faces, slices, axis, pieces, orient, parity) |
sequence(sequence) |
String |
Returns a string with only accepted moves (faces, slices, axis) |
patterns(sequence_array) |
Array |
|
adjustCase(move) |
String |
Returns the given move with its correct case (upper for faces and slices, lower for axis) |
collapseSequence(moves) |
Array |
Returns an array of moves where all double moves are converted to move*2 |
uncollapseSequence(moves) |
Array |
Returns an array of moves where all double moves (move*2) are converted to single rotations |
RubikHelper.static.RubikUtils.colors = {}RubikHelper.static.RubikUtils.patterns = {}RubikHelper.static.RubikUtils.pieces = {}RubikHelper.static.RubikUtils.is.face(move)Checks if the given string is actually a cube's face.
- params
-
{String}move: the face to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.slice(move)Checks if the given string is actually a cube's slice.
- params
-
{String}move: the slice to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.axis(move)Checks if the given string is actually a cube rotation.
- params
-
{String}move: the axis to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.move(move)Checks if the given string is a correct move (face, slice or axis).
- params
-
{String}move: the move to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.modifier(move)Checks if the given string is actually a modifier.
- params
-
{String}move: the sign to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.rotation(move)Checks if the given string is actually a single rotation.
- params
-
{String}move: the move to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.median(move)Checks if the given string is actually a median piece.
- params
-
{String}move: the piece to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.pattern(move)Checks if the given string is actually a stored pattern.
ie. orient edges, orient corners or parity patterns
- params
-
{String}move: the pattern to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.piece(move)Checks if the given string is actually a cube's piece (edge or corner).
- params
-
{String}move: the piece to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.edge(move)Checks if the given string is actually an edge piece.
- params
-
{String}move: the piece to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.corner(move)Checks if the given string is actually a corner piece.
- params
-
{String}move: the piece to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.is.buffer(move)Checks if the given string is actually a buffer piece.
- params
-
{String}move: the piece to search for
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.canbe.negative(move)Checks if given move can be negative.
- params
-
{String}move: the move to get the negative of
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.canbe.mirror(move)Checks if given move can be mirrored.
- params
-
{String}move: the move to get the mirror of
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.canbe.accepted(move, only, but)Checks if given move is one of only param or is not one of but param.
- params
-
{String}move: the move to check the acceptance criteria -
{String|Array}only: the move or moves to be NOT accepted -
{String|Array}but: the only move or moves to be accepted
-
- returns
{Boolean}
RubikHelper.static.RubikUtils.service.targetOf(piece)Returns the correct orientation of a piece.
eg.
RFU->URF,URF->URF,RF->FR
- params
-
{String}piece: the piece to search for
-
- returns
{String}
RubikHelper.static.RubikUtils.service.moveCounter(pattern, move)Count how many times the given move appears inside pattern array.
- params
-
{Array}pattern: the pattern to search into -
{String}move: the move to search for
-
- returns
-
{Number}: the count ofmoveinsidepattern
-
RubikHelper.static.RubikUtils.service.cloneCube(cube)Returns an object representing the scrambled cube.
- params
-
{Object}cube: an object representing the scrambled cube (it could contain only unoriented/unpermuted pieces)
-
- returns
-
{Object}: the full cube with unoriented/unpermuted pieces
-
RubikHelper.static.RubikUtils.service.getPieceFromStickers(stickers, cube)Returns the position of the given stickers inside the scrambled cube.
- params
-
{String}sticers: the stickers you are searching for -
{Object}cube: the scrambled cube to search into
-
- returns
-
{String}: the target position ofstickers -
{Boolean}:FALSEif it's not a piece ofcube
-
RubikHelper.static.RubikUtils.service.getStickersFromPiece(piece, cube, includeMedian)Returns the current stickers of the given piece inside the scrambled cube.
- params
-
{String}piece: -
{Object}cube: -
{Boolean}includeMedian:
-
- returns
{String}
Notes
it returns the ordered stickers depending on the requestedpiece, excepts for median edges
ifincludeMedian = trueit will compute m-edges tooeg. (with an unscrambled cube)
getStickersFromPiece('FUR',cube,false);->'FUR'
getStickersFromPiece('FU',cube,false);->'UF'
getStickersFromPiece('FU',cube,true);->'FU'
RubikHelper.static.RubikUtils.service.getRotation(piece, toTarget)Returns the rotation of a corner, if it's an edge will return true if flipped.
- params
-
{String}piece: the piece to get its rotation -
{Boolean}toTarget: whether to return its current rotation (FALSE), or the one needed to get it correctly oriented (TRUE)
-
- returns
-
{Number}: the actual rotation of requested piece (+1 or -1, 0 if it's already oriented)
-
Notes
iftoTarget=false
'FRD'-> -1,'RDF'-> 1,'DFR'-> 0,'FU'-> true, ...if
toTarget=true
'FRD'-> 1,'RDF'-> -1,'DFR'-> 0,'FU'-> true, ...
RubikHelper.static.RubikUtils.service.rotate(piece, dir)Returns the given piece rotated clockwise or counter-clockwise.
eg.
FU->UFDFR->FRD|RDF
- params
-
{String}piece: the piece to rotate -
{Number}dir: the rotation to be applied on piece (1,-1,0)
-
- returns
-
{String}: the rotated piece
-
RubikHelper.static.RubikUtils.service.replaceMove(moves, move, rep)Replace the given move with rep inside the moves array.
- params
-
{Array}moves: the list of moves to search into -
{String}move: the move to search for -
{String}rep: the replacing move
-
- returns
-
{Array}: the new sequence with replaced moves
-
RubikHelper.static.RubikUtils.service.notAcceptedWithPiece(piece)Returns an array of faces which will be no longer accepted for creating a piece.
- params
-
{String|Array}piece: could be'URF'or['U','R','F']
-
- returns
{Array}
RubikHelper.static.RubikUtils.math.multiply(moves, times)Returns a sequence of moves repeated N times.
- params
-
{Array}moves: the moves to be repeated -
{Number}times: the amount of repeat
-
- returns
-
{Array}: the final sequence array of moves
-
RubikHelper.static.RubikUtils.math.negative(move)Returns the negative of move.
- params
-
{String}move: the single move to get its negative (eg.R,F+,U-)
-
- returns
-
{String}: the single move with negative sign (eg.R-,F-,U+)
-
RubikHelper.static.RubikUtils.math.inverse(move)Returns the inverse (negative) of move.
- params
-
{String}move: the single move to get its negative (eg.R,F+,U-,CC3, ... )
-
- returns
-
{String}: the single move with negative sign (eg.R-,F-,U+,CW3, ... )
-
Notes
ifmoveis a corner orientation pattern, it will return the opposite pattern
RubikHelper.static.RubikUtils.math.mirror(move, slice)Returns the mirror of move depending on slice.
- params
-
{String}move: the move to get the mirror of -
{String}slice: the slice used as mirror (default:'M')
-
- returns
-
{String}: the mirrored move
-
RubikHelper.static.RubikUtils.math.negativePattern(moves, only, but)Returns a pattern with all negative signs.
- params
-
{Array}moves: the pattern array to convert in negative -
{String|Array}only: the only face or faces that should be processed -
{String|Array}but: the face or faces that should not be processed
-
- returns
-
{Array}: the negative pattern
-
RubikHelper.static.RubikUtils.math.inversePattern(moves, only, but)Returns an inverse pattern from the one passed as moves (it goes backward, and with negative signs).
- params
-
{Array}moves: the pattern array to be inverted -
{String|Array}only: the only face or faces that should be processed -
{String|Array}but: the face or faces that should not be processed
-
- returns
-
{Array}: the inverted pattern
-
RubikHelper.static.RubikUtils.math.mirrorPattern(moves, slice)Returns the mirror pattern depending on slice.
- params
-
{Array}moves: the array of moves to get the mirror of -
{String}slice: the slice used as mirror (default:'M')
-
- returns
-
{Array}: the mirrored moves
-
RubikHelper.static.RubikUtils.math.signSum(sign_a, sign_b)Performs a sign sum.
- params
-
{String}sign_a: -
{String}sign_b:
-
- returns
{String}
RubikHelper.static.RubikUtils.math.signInverse(sign)Returns the inverse of the passed sign.
- params
-
{String}sign:
-
- returns
{String}
RubikHelper.static.RubikUtils.expand.piece(piece, full)Returns the array of moves corresponding to the Setup pattern for the given piece.
- params
-
{String}piece: the piece to search for -
{Boolean}full: whether should return the full pattern or only the Setup
-
- returns
-
{Array}: the final array of single moves
-
RubikHelper.static.RubikUtils.expand.pattern(pattern)Returns an array of moves combining the mix of given patterns.
eg.
callingexpand.pattern(['CC3','F-','DR']);will return this array:
['R-','U-','R','U','R-','U-','R','U','F-','U','R2','U-','M2','U','R2','U-']
- params
-
{Array}pattern: an array of patterns, pieces and moves
-
- returns
-
{Array}: the final array of single moves
-
RubikHelper.static.RubikUtils.parse.moves(sequence, uncollapse, caseSensitive, keepCase)Returns an array of simple moves from an user typed sequence of moves.
- params
-
{String}sequence: the user typed sequence of moves -
{Boolean}uncollapse: whether double moves should be converted in a pair of positive single moves (F2->[F+,F+]) -
{Boolean}caseSensitive: whether the sequence should be converted to uppercase before the parsing process -
{Boolean}keepCase: whether the returned string should contains lowercase face rotations (only if caseSensitive:true)
-
- returns
-
{Array}: the array of simple face rotations
-
Some examples
parse.moves('U2FitriX');->'U2,F-,R-,x+'
parse.moves('U2FitriX',true);->'U+,U+,F-,R-,x+'
parse.moves('U2FitriX',false,true);->'U2,F-,R-,M+,x+'
parse.moves('U2FitriX',true,true,true);->'U+,U+,F-,r-,x+'You can also use parenthesis for grouping and square brackets for pieces
eg.
[dr] d'b (lu)' u2 (r'bu)4 [ulb]
((RU[BR])m)i F [LB] (F'[LB])'Notes
use(...)mto mirror,(...)ito invert and(...)'to negative the whole parenthesis content
RubikHelper.static.RubikUtils.parse.pieces(pieces, uncollapse)Returns an array of simple moves from an user typed sequence of pieces or patterns (comma separated)
- params
-
{String}pieces: the user typed sequence of pieces or patterns -
{Boolean}uncollapse: whether double moves should be converted in a pair of positive single moves (F2->[F+,F+])
-
- returns
-
{Array}: the array of simple face rotations
-
RubikHelper.static.RubikUtils.clear.all(sequence)Returns a comma separated string with only accepted moves (faces, slices, axis, pieces, patterns).
- params
-
{String}sequence:
-
- returns
-
{String}:
-
RubikHelper.static.RubikUtils.clear.pieces(sequence)Returns a comma separated string with only accepted moves and patterns (faces, slices, axis, pieces, orient, parity).
- params
-
{String}sequence:
-
- returns
{String}
Notes
It accepts all from clear.sequence, other than these patterns:
_o2u,_o2d,_o2f,_o2b,_o4e,_o6l,_o6r,_cw2,_cc2,_cw3,_cc3,_ptj,_par
RubikHelper.static.RubikUtils.clear.sequence(sequence)Returns a comma separated string with only accepted moves (faces, slices, axis).
- params
-
{String}sequence:
-
- returns
{String}
RubikHelper.static.RubikUtils.clear.patterns(sequence_array)- params
-
{Array}sequence_array:
-
- returns
{Array}
RubikHelper.static.RubikUtils.clear.adjustCase(move)Returns the given move with its correct case (upper for faces and slices, lower for axis).
- params
-
{String}move:
-
- returns
{String}
RubikHelper.static.RubikUtils.clear.collapseSequence(moves)Returns an array of moves where all double moves are converted to move*2.
- params
-
{Array}moves:
-
- returns
{Array}
RubikHelper.static.RubikUtils.clear.uncollapseSequence(moves)Returns an array of moves where all double moves (move*2) are converted to single rotations.
- params
-
{Array}moves:
-
- returns
{Array}