cube_solver.cube.maneuver module

Maneuver module.

class cube_solver.cube.maneuver.Maneuver(moves, reduce=True)[source]

Bases: str

Create Maneuver object.

A Maneuver is a subclass of str that represents the sequence of moves that can be applied to a cube_solver.Cube object.

Parameters:
  • moves (str or list of Move) – Sequence of moves.

  • reduce (bool, optional) – Whether to reduce the sequence of moves. Default is True.

Examples

>>> from cube_solver import Cube, Move, Maneuver

Apply a maneuver to a cube.

>>> Maneuver("U F2 R'")
"U F2 R'"
>>> Maneuver([Move.U1, Move.F2, Move.R3])
"U F2 R'"
>>> Cube(Maneuver("U F2 R'")) == Cube("U F2 R'")
True

Compare equvalent maneuvers.

>>> Maneuver("R L") == "L R"
True
>>> Maneuver("F S B'") == "z"
True
>>> Maneuver("R L F2 B2 R' L' D R L F2 B2 R' L'") == "U"
True

Reduce consecutive moves along the same axis.

>>> Maneuver("U U")
'U2'
>>> Maneuver("R L R")
'R2 L'
>>> Maneuver("F S' B2 F")
'S z2'
>>> Maneuver("F S' B2 F", reduce=False)  # do not reduce
"F S' B2 F"

Inverse maneuver.

>>> Maneuver("R U R' U'").inverse
"U R U' R'"

Container operations.

>>> maneuver = Maneuver("U F2 R'")
>>> maneuver[0]
Move.U1
>>> maneuver[:2]
'U F2'
>>> [move for move in maneuver]
[Move.U1, Move.F2, Move.R3]
>>> list(maneuver)
[Move.U1, Move.F2, Move.R3]
>>> Move.U1 in maneuver
True

Numeric operations.

>>> A = Maneuver("U R'")
>>> B = Maneuver("F'")
>>> -A     # '-' negation, same as A'
"R U'"
>>> A + B  # '+' addition, same as A B
"U R' F'"
>>> A - B  # '-' subtraction, same as A B'
"U R' F"
>>> 2 * A  # '*' scalar multiplication, same as A A
"U R' U R'"
>>> A * B  # '*' conjugation, same as A B A'
"U R' F' R U'"
>>> A @ B  # '@' commutator, same as A B A' B'
"U R' F' R U' F"
property inverse: Maneuver

Inverse maneuver.

Examples

>>> from cube_solver import Maneuver
>>> Maneuver("R U R' U'").inverse
"U R U' R'"
classmethod random(length=25)[source]

Generate a random maneuver.

Parameters:

length (int, optional) – Maneuver length. Default is 25.

Returns:

maneuver – Random maneuver of the specified length.

Return type:

Maneuver

Examples

>>> from cube_solver import Maneuver
>>> Maneuver.random(10)  # result might differ 
"D2 R2 L' B2 D L D F L D2"