diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6119e28..41e5543 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,6 +8,13 @@ repos: - id: end-of-file-fixer - repo: local hooks: + - id: autopep + name: autopep + entry: "autopep8 --exit-code --diff --recursive ." + language: system + types: [python] + require_serial: true + args: [] - id: pylint name: pylint entry: pylint diff --git a/.pylintrc b/.pylintrc index 63a4be7..b1dfb33 100644 --- a/.pylintrc +++ b/.pylintrc @@ -424,7 +424,8 @@ disable=raw-checker-failed, too-many-locals, too-many-instance-attributes, too-many-arguments, - duplicate-code + duplicate-code, + too-many-return-statements # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/examples/cube3x3.py b/examples/cube3x3.py index df8a15b..c8952c2 100644 --- a/examples/cube3x3.py +++ b/examples/cube3x3.py @@ -1,7 +1,8 @@ import magiccube # Create the cube in solved state -cube = magiccube.Cube(3,"YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW") +cube = magiccube.Cube( + 3, "YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW") # Print the cube print(cube) @@ -13,7 +14,8 @@ print(cube) # Create the cube with a fixed state -cube = magiccube.Cube(3, "YYYYYYGGGGGWRRRRRROOOGGWGGWYBBOOOOOORRRYBBYBBWWBWWBWWB") +cube = magiccube.Cube( + 3, "YYYYYYGGGGGWRRRRRROOOGGWGGWYBBOOOOOORRRYBBYBBWWBWWBWWB") # Reset to the initial position cube.reset() diff --git a/examples/cube4x4.py b/examples/cube4x4.py index c2e262a..4d0284c 100644 --- a/examples/cube4x4.py +++ b/examples/cube4x4.py @@ -1,7 +1,7 @@ import magiccube # Create the cube -cube = magiccube.Cube(4,state=""" +cube = magiccube.Cube(4, state=""" YYYYYYYYYYYYGGGG GGGWRRRRRRRRRRRR OOOOGGGWGGGWGGGW diff --git a/magiccube/cube.py b/magiccube/cube.py index ffa7cd5..816e4c7 100644 --- a/magiccube/cube.py +++ b/magiccube/cube.py @@ -1,5 +1,5 @@ """Rubik Cube implementation""" -from typing import Dict,List, Tuple +from typing import Dict, List, Tuple import random import numpy as np from magiccube.cube_base import Color, CubeException, Face @@ -7,15 +7,16 @@ from magiccube.cube_move import CubeMove, CubeMoveType from magiccube.cube_print import CubePrintStr + class Cube: """Rubik Cube implementation""" - __slots__=("size","_store_history","_cube_face_indexes","_cube_piece_indexes", - "_cube_piece_indexes_inv","cube","_history") + __slots__ = ("size", "_store_history", "_cube_face_indexes", "_cube_piece_indexes", + "_cube_piece_indexes_inv", "cube", "_history") - def __init__(self, size: int=3, state=None, hist=True): + def __init__(self, size: int = 3, state=None, hist=True): - if size<=1: + if size <= 1: raise CubeException("Cube size must be >= 2") self.size = size @@ -23,46 +24,47 @@ def __init__(self, size: int=3, state=None, hist=True): # record the indexes of every cube face self._cube_face_indexes = [ - [[(0,y,z) for z in range(self.size)] - for y in reversed(range(self.size))], #L - [[(self.size-1,y,z) for z in reversed(range(self.size))] - for y in reversed(range(self.size))], #R - [[(x,0,z) for x in range(self.size)] - for z in reversed(range(self.size))], #D + [[(0, y, z) for z in range(self.size)] + for y in reversed(range(self.size))], # L + [[(self.size-1, y, z) for z in reversed(range(self.size))] + for y in reversed(range(self.size))], # R + [[(x, 0, z) for x in range(self.size)] + for z in reversed(range(self.size))], # D [[(x, self.size-1, z) for x in range(self.size)] - for z in range(self.size)], #U - [[(x,y,0) for x in reversed(range(self.size))] - for y in reversed(range(self.size))], #B - [[(x,y,self.size-1) for x in range(self.size)] - for y in reversed(range(self.size))], #F + for z in range(self.size)], # U + [[(x, y, 0) for x in reversed(range(self.size))] + for y in reversed(range(self.size))], # B + [[(x, y, self.size-1) for x in range(self.size)] + for y in reversed(range(self.size))], # F ] # record the indexes of every cube piece self._cube_piece_indexes = [ - (x,y,z) + (x, y, z) for z in range(self.size) for y in range(self.size) for x in range(self.size) - if self._is_outer_position(x,y,z) + if self._is_outer_position(x, y, z) ] - self._cube_piece_indexes_inv={v:idx for idx,v in enumerate(self._cube_piece_indexes)} + self._cube_piece_indexes_inv = { + v: idx for idx, v in enumerate(self._cube_piece_indexes)} if state is None: self.reset() else: self.set(state) - def _is_outer_position(self,_x:int,_y:int,_z:int)->bool: + def _is_outer_position(self, _x: int, _y: int, _z: int) -> bool: """Test if the coordinates indicate and outer cube position""" - return _x==0 or _x==self.size-1 \ - or _y==0 or _y==self.size-1 \ - or _z==0 or _z==self.size-1 # dont include center pieces + return _x == 0 or _x == self.size-1 \ + or _y == 0 or _y == self.size-1 \ + or _z == 0 or _z == self.size-1 # dont include center pieces def reset(self): """Reset the cube to the initial configuration""" initial_cube = [ [[CubePiece(self.size, (x, y, z)) - if self._is_outer_position(x,y,z) else None + if self._is_outer_position(x, y, z) else None for x in range(self.size)] for y in range(self.size)] for z in range(self.size) @@ -70,7 +72,7 @@ def reset(self): self.cube = np.array(initial_cube, dtype=np.object_) self._history = [] - def set(self, image:str): + def set(self, image: str): """Sets the cube state. Parameters @@ -87,46 +89,47 @@ def set(self, image:str): image = image.replace("\n", "") if len(image) != 6*self.size*self.size: - raise CubeException("Cube state has an invalid size. Should be: " + str(6*self.size*self.size)) + raise CubeException( + "Cube state has an invalid size. Should be: " + str(6*self.size*self.size)) img = [Color.create(x) for x in image] self.reset() - for i,color in enumerate(img): + for i, color in enumerate(img): face = i // (self.size**2) - remain = i%(self.size**2) - if face ==0: #U - _x=remain%self.size + remain = i % (self.size**2) + if face == 0: # U + _x = remain % self.size _y = self.size-1 - _z=remain//self.size - self.get_piece((_x,_y,_z)).set_piece_color(1,color) - elif face == 5: #D - _x=remain%self.size + _z = remain//self.size + self.get_piece((_x, _y, _z)).set_piece_color(1, color) + elif face == 5: # D + _x = remain % self.size _y = 0 - _z=self.size-(remain//self.size)-1 - self.get_piece((_x,_y,_z)).set_piece_color(1,color) - elif face == 1: #L + _z = self.size-(remain//self.size)-1 + self.get_piece((_x, _y, _z)).set_piece_color(1, color) + elif face == 1: # L _x = 0 - _y=self.size-(remain//self.size)-1 - _z=remain%self.size - self.get_piece((_x,_y,_z)).set_piece_color(0,color) - elif face == 3: #R + _y = self.size-(remain//self.size)-1 + _z = remain % self.size + self.get_piece((_x, _y, _z)).set_piece_color(0, color) + elif face == 3: # R _x = self.size-1 - _y=self.size-(remain//self.size)-1 - _z=self.size-(remain%self.size)-1 - self.get_piece((_x,_y,_z)).set_piece_color(0,color) - elif face == 4: #B - _x=self.size-(remain%self.size)-1 _y = self.size-(remain//self.size)-1 - _z=0 - self.get_piece((_x,_y,_z)).set_piece_color(2,color) - elif face == 2: #F - _x=remain%self.size - _y=self.size-(remain//self.size)-1 - _z=self.size-1 - self.get_piece((_x,_y,_z)).set_piece_color(2,color) - - def scramble(self, num_steps:int=50, wide=None) -> List[CubeMove]: + _z = self.size-(remain % self.size)-1 + self.get_piece((_x, _y, _z)).set_piece_color(0, color) + elif face == 4: # B + _x = self.size-(remain % self.size)-1 + _y = self.size-(remain//self.size)-1 + _z = 0 + self.get_piece((_x, _y, _z)).set_piece_color(2, color) + elif face == 2: # F + _x = remain % self.size + _y = self.size-(remain//self.size)-1 + _z = self.size-1 + self.get_piece((_x, _y, _z)).set_piece_color(2, color) + + def scramble(self, num_steps: int = 50, wide=None) -> List[CubeMove]: """Scramble the cube with random moves. By default scramble only uses wide moves to cubes with size >=4.""" @@ -134,118 +137,120 @@ def scramble(self, num_steps:int=50, wide=None) -> List[CubeMove]: self.rotate(movements) return movements - def generate_random_moves(self, num_steps:int=50, wide=None) -> List[CubeMove]: + def generate_random_moves(self, num_steps: int = 50, wide=None) -> List[CubeMove]: """Generate a list of random moves (but don't apply them). By default scramble only uses wide moves to cubes with size >=4.""" - if wide is None and self.size<=3: - wide=False - elif wide is None and self.size>3: - wide=True + if wide is None and self.size <= 3: + wide = False + elif wide is None and self.size > 3: + wide = True possible_moves = [ - CubeMoveType.L,CubeMoveType.R, #CubeMoveType.M, - CubeMoveType.D,CubeMoveType.U, #CubeMoveType.E, - CubeMoveType.B,CubeMoveType.F, #CubeMoveType.S, + CubeMoveType.L, CubeMoveType.R, # CubeMoveType.M, + CubeMoveType.D, CubeMoveType.U, # CubeMoveType.E, + CubeMoveType.B, CubeMoveType.F, # CubeMoveType.S, ] movements = [CubeMove( random.choice(possible_moves), - random.choice([False,True]), #reversed - random.choice([False,True]) if wide else False, # wide - random.randint(1,self.size//2) if wide else 1 #layer - ) + random.choice([False, True]), # reversed + random.choice([False, True]) if wide else False, # wide + random.randint(1, self.size//2) if wide else 1 # layer + ) for _ in range(num_steps)] return movements - def find_piece(self, colors:str) -> Tuple[Coordinates, CubePiece]: + def find_piece(self, colors: str) -> Tuple[Coordinates, CubePiece]: """Find the piece with given colors""" colors = "".join(sorted(colors)) for coord, piece in self.get_all_pieces().items(): if colors == piece.get_piece_colors_str(no_loc=True): - return coord,piece + return coord, piece raise CubeException("piece not found " + colors) - def get_face(self, face:Face)->List[List[Color]]: + def get_face(self, face: Face) -> List[List[Color]]: """Get face colors in a multi-dim array""" face_indexes = self._cube_face_indexes[face.value] res = [] for line in face_indexes: - line_color = [self.cube[index].get_piece_color(face.get_axis()) for index in line] + line_color = [self.cube[index].get_piece_color( + face.get_axis()) for index in line] res.append(line_color) return res - def get_face_flat(self, face:Face)->List[Color]: + def get_face_flat(self, face: Face) -> List[Color]: """Get face colors in a flat array""" res = self.get_face(face) res = list(np.array(res).flatten()) return res - def get_all_faces(self) -> Dict[Face,List[List[Color]]]: + def get_all_faces(self) -> Dict[Face, List[List[Color]]]: """Get the CubePiece of all cube faces""" - faces = {f:self.get_face(f) for f in Face} + faces = {f: self.get_face(f) for f in Face} return faces def get_piece(self, coordinates: Coordinates) -> CubePiece: """Get the CubePiece at a given coordinate""" return self.cube[coordinates] - def get_all_pieces(self)->Dict[Coordinates,CubePiece]: + def get_all_pieces(self) -> Dict[Coordinates, CubePiece]: """Return a dictionary of coordinates:CubePiece""" res = [self.cube[x] for x in self._cube_piece_indexes] res = { - (xi,yi,zi): piece - for xi,x in enumerate(self.cube) - for yi,y in enumerate(x) - for zi,piece in enumerate(y) - if xi==0 or xi==self.size-1 - or yi==0 or yi==self.size-1 - or zi==0 or zi==self.size-1 # dont include center pieces + (xi, yi, zi): piece + for xi, x in enumerate(self.cube) + for yi, y in enumerate(x) + for zi, piece in enumerate(y) + if xi == 0 or xi == self.size-1 + or yi == 0 or yi == self.size-1 + or zi == 0 or zi == self.size-1 # dont include center pieces } return res - def _move_to_slice(self, move:CubeMove)->slice: + def _move_to_slice(self, move: CubeMove) -> slice: """return the slices affected by a given CubeMove""" - if not(move.layer>=1 and move.layer<=self.size): + if not (move.layer >= 1 and move.layer <= self.size): raise CubeException("invalid layer " + str(move.layer)) if move.type in (CubeMoveType.R, CubeMoveType.U, CubeMoveType.F): if move.wide: - return slice(self.size - move.layer,self.size) + return slice(self.size - move.layer, self.size) - return slice(self.size - move.layer,self.size - move.layer+1) + return slice(self.size - move.layer, self.size - move.layer+1) if move.type in (CubeMoveType.L, CubeMoveType.D, CubeMoveType.B): if move.wide: - return slice(0,move.layer) + return slice(0, move.layer) - return slice(move.layer-1,move.layer) + return slice(move.layer-1, move.layer) if move.type in (CubeMoveType.M, CubeMoveType.E, CubeMoveType.S): - if self.size%2 != 1: - raise CubeException("M,E,S moves not allowed for even size cubes") + if self.size % 2 != 1: + raise CubeException( + "M,E,S moves not allowed for even size cubes") - return slice(self.size//2,self.size//2+1) + return slice(self.size//2, self.size//2+1) # move.type in (CubeMoveType.X, CubeMoveType.Y, CubeMoveType.Z): - return slice(0,self.size) + return slice(0, self.size) - def _get_direction(self,move:CubeMove)->int: + def _get_direction(self, move: CubeMove) -> int: """get the rotation direction for a give CubeMove""" - if move.type in (CubeMoveType.R,CubeMoveType.D,CubeMoveType.F, CubeMoveType.E, CubeMoveType.S, CubeMoveType.X, CubeMoveType.Z): + if move.type in (CubeMoveType.R, CubeMoveType.D, CubeMoveType.F, CubeMoveType.E, CubeMoveType.S, CubeMoveType.X, CubeMoveType.Z): direction = -1 - elif move.type in (CubeMoveType.L,CubeMoveType.U,CubeMoveType.B,CubeMoveType.M, CubeMoveType.Y): + elif move.type in (CubeMoveType.L, CubeMoveType.U, CubeMoveType.B, CubeMoveType.M, CubeMoveType.Y): direction = 1 else: raise CubeException("invalid move face " + str(move.type)) if move.is_reversed: - direction=direction*-1 + direction = direction*-1 return direction - def _rotate_once(self, move:CubeMove): + def _rotate_once(self, move: CubeMove): """Make one cube movement""" if self._store_history: self._history.append(move) @@ -256,8 +261,9 @@ def _rotate_once(self, move:CubeMove): count = move.count for _ in range(count): - rotation_plane=tuple(slice(None) if i!=axis else slices for i in range(3)) - rotation_axes=tuple(i for i in range(3) if i!=axis) + rotation_plane = tuple( + slice(None) if i != axis else slices for i in range(3)) + rotation_axes = tuple(i for i in range(3) if i != axis) plane = self.cube[rotation_plane] rotated_plane = np.rot90(plane, direction, axes=rotation_axes) @@ -266,18 +272,18 @@ def _rotate_once(self, move:CubeMove): if piece is not None: piece.rotate_piece(axis) - def rotate(self, movements)->None: + def rotate(self, movements) -> None: """Make multiple cube movements""" if isinstance(movements, str): - movements_list = [CubeMove.create(move_str) for move_str in movements.split(" ") if move_str != ""] + movements_list = [CubeMove.create( + move_str) for move_str in movements.split(" ") if move_str != ""] else: - movements_list=movements + movements_list = movements for move in movements_list: self._rotate_once(move) - - def is_done(self)->bool: + def is_done(self) -> bool: """Returns True if the Cube is done""" for face_name in Face: face = self.get_face_flat(face_name) @@ -285,12 +291,13 @@ def is_done(self)->bool: return False return True - def check_consistency(self)->bool: + def check_consistency(self) -> bool: """Check the cube for internal consistency""" for face_name in Face: face = self.get_face_flat(face_name) if any((x is None for x in face)): - raise CubeException("cube is not consistent on face "+ str(face_name)) + raise CubeException( + "cube is not consistent on face " + str(face_name)) return True def history(self, to_str=False): diff --git a/magiccube/cube_base.py b/magiccube/cube_base.py index 595de0a..db3fd14 100644 --- a/magiccube/cube_base.py +++ b/magiccube/cube_base.py @@ -3,31 +3,33 @@ from enum import Enum from typing import Optional, Tuple + class CubeException(Exception): pass + class Face(Enum): """Representation of a Cube Face""" - L=0 - R=1 - D=2 - U=3 - B=4 - F=5 - - def get_axis(self)->int: + L = 0 + R = 1 + D = 2 + U = 3 + B = 4 + F = 5 + + def get_axis(self) -> int: """Return axis of movement (x=0, y=1, z=2)""" - if self in (Face.L,Face.R): + if self in (Face.L, Face.R): return 0 if self in (Face.D, Face.U): return 1 if self in (Face.B, Face.F): return 2 - raise CubeException("invalid face") #pragma: no cover + raise CubeException("invalid face") # pragma: no cover @staticmethod - def create(face_str:str): + def create(face_str: str): """Create a CubeFace""" if face_str == "L": return Face.L @@ -43,20 +45,21 @@ def create(face_str:str): return Face.F raise CubeException("invalid face " + str(face_str)) + class Color(Enum): """Representation of the color of a Cube Piece""" - R=0 - O=1 - W=2 - Y=3 - B=4 - G=5 + R = 0 + O = 1 + W = 2 + Y = 3 + B = 4 + G = 5 def __lt__(self, other): return self.name < other.name @staticmethod - def create(color_str:str): + def create(color_str: str): """Create a CubeColor""" if color_str == "R": return Color.R @@ -72,14 +75,16 @@ def create(color_str:str): return Color.G raise CubeException("invalid color " + str(color_str)) -Coordinates=Tuple[int,int,int] -ColorOrientation = Tuple[Optional[Color],Optional[Color],Optional[Color]] +Coordinates = Tuple[int, int, int] + +ColorOrientation = Tuple[Optional[Color], Optional[Color], Optional[Color]] """Defines the color orientation of a given CubePiece""" + class PieceType(Enum): """Type of piece""" - CORNER=3 - EDGE=2 - CENTER=1 - INNER=0 + CORNER = 3 + EDGE = 2 + CENTER = 1 + INNER = 0 diff --git a/magiccube/cube_move.py b/magiccube/cube_move.py index d0f1122..5501ba9 100644 --- a/magiccube/cube_move.py +++ b/magiccube/cube_move.py @@ -4,22 +4,23 @@ from magiccube.cube_base import CubeException + class CubeMoveType(Enum): - L="L" - R="R" - D="D" - U="U" - B="B" - F="F" - X="X" - Y="Y" - Z="Z" - M="M" - E="E" - S="S" + L = "L" + R = "R" + D = "D" + U = "U" + B = "B" + F = "F" + X = "X" + Y = "Y" + Z = "Z" + M = "M" + E = "E" + S = "S" @staticmethod - def create(move_str:str): + def create(move_str: str): # pylint: disable=too-many-return-statements """Create a CubeMoveType""" if move_str == "L": @@ -50,76 +51,82 @@ def create(move_str:str): def get_axis(self): """Return axis of movement (x=0, y=1, z=2)""" - if self in (CubeMoveType.L,CubeMoveType.R,CubeMoveType.M,CubeMoveType.X): + if self in (CubeMoveType.L, CubeMoveType.R, CubeMoveType.M, CubeMoveType.X): return 0 - if self in (CubeMoveType.D, CubeMoveType.U,CubeMoveType.E,CubeMoveType.Y): + if self in (CubeMoveType.D, CubeMoveType.U, CubeMoveType.E, CubeMoveType.Y): return 1 - if self in (CubeMoveType.B, CubeMoveType.F,CubeMoveType.S,CubeMoveType.Z): + if self in (CubeMoveType.B, CubeMoveType.F, CubeMoveType.S, CubeMoveType.Z): return 2 - raise CubeException("invalid CubeMoveType" + str(self.value)) #pragma: no cover + raise CubeException("invalid CubeMoveType" + + str(self.value)) # pragma: no cover def is_cube_rotation(self): return self in (CubeMoveType.X, CubeMoveType.Y, CubeMoveType.Z) + class CubeMove(): """Cube movement class Ex: F B' 2R 3Rw' """ - __slots__ = ('type','is_reversed', 'wide','layer', 'count') + __slots__ = ('type', 'is_reversed', 'wide', 'layer', 'count') - regex_pattern = re.compile("^(?:([0-9]*)(([LRDUBF])([w]?)|([XYZMES]))([']?)([0-9]?))$") + regex_pattern = re.compile( + "^(?:([0-9]*)(([LRDUBF])([w]?)|([XYZMES]))([']?)([0-9]?))$") - def __init__(self, move_type:CubeMoveType, is_reversed:bool=False, wide:bool=False, layer:int=1): - self.type=move_type - self.is_reversed=is_reversed - self.wide=wide - self.layer=layer - self.count=1 + def __init__(self, move_type: CubeMoveType, is_reversed: bool = False, wide: bool = False, layer: int = 1): + self.type = move_type + self.is_reversed = is_reversed + self.wide = wide + self.layer = layer + self.count = 1 @staticmethod - def create(move_str:str): + def _create_move(result, special_move): + if special_move is not None: + is_reversed = result[-2] == "'" + if special_move == "X": + return CubeMove(CubeMoveType.X, is_reversed) + if special_move == "Y": + return CubeMove(CubeMoveType.Y, is_reversed) + if special_move == "Z": + return CubeMove(CubeMoveType.Z, is_reversed) + if special_move == "M": + return CubeMove(CubeMoveType.M, is_reversed) + if special_move == "E": + return CubeMove(CubeMoveType.E, is_reversed) + if special_move == "S": + return CubeMove(CubeMoveType.S, is_reversed) + + raise CubeException( + "Invalid special move") # pragma: no cover + move_type = CubeMoveType.create(result[2]) + wide = result[3] == "w" + is_reversed = result[-2] == "'" + + if result[0] == "" and not wide: + layer = 1 + elif result[0] == "" and wide: + layer = 2 + else: + layer = int(result[0]) + + move = CubeMove(move_type, is_reversed, wide, layer) + return move + + @staticmethod + def create(move_str: str): """Create a CubeMove from string representation""" # pylint: disable=too-many-return-statements result = CubeMove.regex_pattern.match(move_str) if result is None: raise CubeException("invalid movement " + str(move_str)) - result=result.groups() - special_move = result[4] + result = result.groups() + special_move = result[4] move_count = result[-1] - def _create_move(): - if special_move is not None: - is_reversed=(result[-2]=="'") - if special_move=="X": - return CubeMove(CubeMoveType.X, is_reversed) - elif special_move=="Y": - return CubeMove(CubeMoveType.Y, is_reversed) - elif special_move=="Z": - return CubeMove(CubeMoveType.Z, is_reversed) - if special_move=="M": - return CubeMove(CubeMoveType.M, is_reversed) - elif special_move=="E": - return CubeMove(CubeMoveType.E, is_reversed) - elif special_move=="S": - return CubeMove(CubeMoveType.S, is_reversed) - else: - raise CubeException("Invalid special move") # pragma: no cover - else: - type=CubeMoveType.create(result[2]) - wide=(result[3]=="w") - is_reversed=(result[-2]=="'") - - if result[0]=="" and not wide: - layer=1 - elif result[0] == "" and wide: - layer=2 - else: - layer=int(result[0]) - - move=CubeMove(type, is_reversed, wide, layer) - return move - move = _create_move() + + move = CubeMove._create_move(result, special_move) move.count = int(move_count) if move_count else 1 return move @@ -128,18 +135,17 @@ def reverse(self): return CubeMove(self.type, not self.is_reversed, self.wide, self.layer) def __str__(self): - if (self.wide and self.layer==2)\ - or (not self.wide and self.layer==1): - layer="" + if (self.wide and self.layer == 2)\ + or (not self.wide and self.layer == 1): + layer = "" else: - layer=self.layer #pragma: no cover - wide="w" if self.wide else "" - reversed_move="'" if self.is_reversed else "" + layer = self.layer # pragma: no cover + wide = "w" if self.wide else "" + reversed_move = "'" if self.is_reversed else "" return f"{layer}{self.type.name}{wide}{reversed_move}" def __repr__(self): - return str(self) #pragma: no cover - + return str(self) # pragma: no cover def __eq__(self, other): if isinstance(other, CubeMove): @@ -150,4 +156,4 @@ def __eq__(self, other): return False def __hash__(self): - return hash(tuple([self.type,self.is_reversed,self.wide,self.layer])) + return hash(tuple([self.type, self.is_reversed, self.wide, self.layer])) diff --git a/magiccube/cube_piece.py b/magiccube/cube_piece.py index dcab4f1..efd6440 100644 --- a/magiccube/cube_piece.py +++ b/magiccube/cube_piece.py @@ -3,30 +3,32 @@ import numpy as np from magiccube.cube_base import Color, ColorOrientation, Coordinates, CubeException, PieceType + class CubePiece: """Piece of the Cube (aka Cubelet)""" __slots__ = ('_colors',) - def __init__(self, cube_size: Optional[int]=None, position:Optional[Coordinates]=None, - colors:Optional[List[Optional[Color]]]=None): + def __init__(self, cube_size: Optional[int] = None, position: Optional[Coordinates] = None, + colors: Optional[List[Optional[Color]]] = None): if cube_size is not None and position is not None: self._colors = self._build_piece_colors(cube_size, position) - elif colors is not None and len(colors)==3: + elif colors is not None and len(colors) == 3: self._colors = np.array(colors) else: - raise CubeException("Can't create CubePiece. Either position or color must be specified.") + raise CubeException( + "Can't create CubePiece. Either position or color must be specified.") - def _build_piece_colors(self, cube_size:int, position:Coordinates) ->np.ndarray: + def _build_piece_colors(self, cube_size: int, position: Coordinates) -> np.ndarray: """Creates the default piece colors""" - (_z,_y,_x)=position + (_z, _y, _x) = position if _x == 0: x_color = Color.R elif _x == cube_size-1: x_color = Color.O else: - x_color=None + x_color = None if _y == 0: y_color = Color.W @@ -42,26 +44,26 @@ def _build_piece_colors(self, cube_size:int, position:Coordinates) ->np.ndarray: else: z_color = None - colors = [x_color,y_color, z_color] - colors = np.array(colors) + colors = [x_color, y_color, z_color] + colors = np.array(colors) return colors - def get_piece_color(self, axis)->Color: + def get_piece_color(self, axis) -> Color: """Return the CuberPiece color of a given axis""" return self._colors[axis] - def get_piece_colors_str(self, no_loc=False)->str: + def get_piece_colors_str(self, no_loc=False) -> str: """Return a string with the colors for xyz axis""" colors = self.get_piece_colors(no_loc=no_loc) colors = [c.name for c in colors if c is not None] return "".join(colors) - def get_piece_colors(self, no_loc=False)->ColorOrientation: + def get_piece_colors(self, no_loc=False) -> ColorOrientation: """Return CubeColors of the piece. Order is XYZ""" x_color = self.get_piece_color(0) y_color = self.get_piece_color(1) z_color = self.get_piece_color(2) - colors = [x_color,y_color,z_color] + colors = [x_color, y_color, z_color] if no_loc: colors = [c for c in colors if c is not None] @@ -69,34 +71,34 @@ def get_piece_colors(self, no_loc=False)->ColorOrientation: return tuple(colors) - def set_piece_color(self, axis:int, color:Color): + def set_piece_color(self, axis: int, color: Color): """Set the piece colors""" - self._colors[axis]=color + self._colors[axis] = color - def rotate_piece(self, axis:int) -> None: + def rotate_piece(self, axis: int) -> None: """Rotate the piece colors according to a given movement""" - if axis==0: #LR - indexes = [0,2,1] + if axis == 0: # LR + indexes = [0, 2, 1] self._colors = self._colors[indexes] - elif axis==1: #DU - indexes = [2,1,0] + elif axis == 1: # DU + indexes = [2, 1, 0] self._colors = self._colors[indexes] - elif axis==2: #BF - indexes = [1,0,2] + elif axis == 2: # BF + indexes = [1, 0, 2] self._colors = self._colors[indexes] else: raise CubeException("bad rotation type") - def get_piece_type(self)->PieceType: + def get_piece_type(self) -> PieceType: """Return the piece type (ex: EDGE, CORNER, CENTER)""" sides = [c for c in self._colors if c is not None] num_sides = len(sides) - if num_sides==3: + if num_sides == 3: return PieceType.CORNER - if num_sides==2: + if num_sides == 2: return PieceType.EDGE - if num_sides==1: + if num_sides == 1: return PieceType.CENTER raise CubeException("Invalid Piece with num_sides="+str(num_sides)) @@ -104,7 +106,7 @@ def __repr__(self): return str(self.get_piece_colors_str()) def __str__(self): - return str(self.get_piece_colors_str()) #pragma:no cover + return str(self.get_piece_colors_str()) # pragma:no cover def __lt__(self, other): - return self._colors < other._colors #pragma:no cover + return self._colors < other._colors # pragma:no cover diff --git a/magiccube/cube_print.py b/magiccube/cube_print.py index 89269c1..6f6bfb0 100644 --- a/magiccube/cube_print.py +++ b/magiccube/cube_print.py @@ -1,15 +1,16 @@ """Stdout Cube Print implementation""" import os from enum import Enum -from magiccube.cube_base import Color,Face +from magiccube.cube_base import Color, Face -C_RESET="\x1b[0;0m" +C_RESET = "\x1b[0;0m" # C_BG="\x1b[48;5;231m" class Terminal(Enum): - default=0 - x256=1 + default = 0 + x256 = 1 + class CubePrintStr: """Prints a cube to stdout""" @@ -24,22 +25,24 @@ class CubePrintStr: def __init__(self, cube): self.cube = cube - self.term = Terminal.x256 if os.environ.get("TERM")=="xterm-256color" else Terminal.default + self.term = Terminal.x256 if os.environ.get( + "TERM") == "xterm-256color" else Terminal.default - def _format_color(self, color:Color): + def _format_color(self, color: Color): """Format color to TTY Only print colors on supported terminals (xterm-256color) """ formated_color = " " + color.name + " " if self.term == Terminal.x256: - formated_color = CubePrintStr._xterm256_color_map.get(color, "") + formated_color + C_RESET + formated_color = CubePrintStr._xterm256_color_map.get( + color, "") + formated_color + C_RESET return formated_color def _print_top_down_face(self, cube, face): - result ="" - for index,color in enumerate(cube.get_face_flat(face)): + result = "" + for index, color in enumerate(cube.get_face_flat(face)): if index % cube.size == 0: result += (" " * ((3*cube.size))) @@ -62,8 +65,8 @@ def print_cube(self): result = self._print_top_down_face(cube, Face.U) # MID for line in print_order_mid: - for line_index,face_line in enumerate(line): - for face_line_index,color in enumerate(face_line): + for line_index, face_line in enumerate(line): + for face_line_index, color in enumerate(face_line): result += self._format_color(color) if face_line_index % cube.size == cube.size-1: diff --git a/magiccube/optimizer/move_optimizer.py b/magiccube/optimizer/move_optimizer.py index ba6459f..655a001 100644 --- a/magiccube/optimizer/move_optimizer.py +++ b/magiccube/optimizer/move_optimizer.py @@ -3,101 +3,107 @@ from magiccube.cube_move import CubeMove # Cube rotation config -_cube_rotations={ - "Y":{ - "F":"R", - "R":"B", - "B":"L", - "L":"F", - "U":"U", - "D":"D", - "M":"S", - "E":"E", - "S":"M'", +_cube_rotations = { + "Y": { + "F": "R", + "R": "B", + "B": "L", + "L": "F", + "U": "U", + "D": "D", + "M": "S", + "E": "E", + "S": "M'", }, - "Y'":{ - "F":"L", - "L":"B", - "B":"R", - "R":"F", - "U":"U", - "D":"D", - "M":"S'", - "E":"E", - "S":"M", + "Y'": { + "F": "L", + "L": "B", + "B": "R", + "R": "F", + "U": "U", + "D": "D", + "M": "S'", + "E": "E", + "S": "M", }, - "X":{ - "F":"D", - "D":"B", - "B":"U", - "U":"F", - "L":"L", - "R":"R", - "M":"M", - "E":"S'", - "S":"E", + "X": { + "F": "D", + "D": "B", + "B": "U", + "U": "F", + "L": "L", + "R": "R", + "M": "M", + "E": "S'", + "S": "E", }, - "X'":{ - "F":"U", - "U":"B", - "B":"D", - "D":"F", - "L":"L", - "R":"R", - "M":"M", - "E":"S", - "S":"E'", + "X'": { + "F": "U", + "U": "B", + "B": "D", + "D": "F", + "L": "L", + "R": "R", + "M": "M", + "E": "S", + "S": "E'", }, - "Z":{ - "U":"L", - "L":"D", - "D":"R", - "R":"U", - "F":"F", - "B":"B", - "M":"E", - "E":"M'", - "S":"S", + "Z": { + "U": "L", + "L": "D", + "D": "R", + "R": "U", + "F": "F", + "B": "B", + "M": "E", + "E": "M'", + "S": "S", }, - "Z'":{ - "U":"R", - "R":"D", - "D":"L", - "L":"U", - "F":"F", - "B":"B", - "M":"E'", - "E":"M", - "S":"S", + "Z'": { + "U": "R", + "R": "D", + "D": "L", + "L": "U", + "F": "F", + "B": "B", + "M": "E'", + "E": "M", + "S": "S", }, } + def _build_convertions(): """Build convertion structure""" def convert_moves(moves): return ( - {CubeMove.create(k):CubeMove.create(v) for k,v in moves.items()} | - {CubeMove.create(k).reverse():CubeMove.create(v).reverse() for k,v in moves.items()} + {CubeMove.create(k): CubeMove.create(v) for k, v in moves.items()} | + {CubeMove.create(k).reverse(): CubeMove.create(v).reverse() + for k, v in moves.items()} ) - convertions = {CubeMove.create(rot):convert_moves(moves) for rot,moves in _cube_rotations.items()} + convertions = {CubeMove.create(rot): convert_moves( + moves) for rot, moves in _cube_rotations.items()} return convertions + cube_rotations = _build_convertions() + class MoveOptimizer: """Optimizes a sequence of moves Removes reversed moves. Ex L R R' L' Converts tripple moves with an inverse. Ex: U U U -> U' Removes cube rotations. """ + def __init__(self): pass - def optimize(self, moves:List[CubeMove])->List[CubeMove]: + def optimize(self, moves: List[CubeMove]) -> List[CubeMove]: """Returns the optimized moves""" optimized_moves = [] - current_cube_rotations=[] + current_cube_rotations = [] for move in moves: if move.type.is_cube_rotation(): @@ -108,9 +114,9 @@ def optimize(self, moves:List[CubeMove])->List[CubeMove]: cube_rotation = cube_rotations[rot] move = cube_rotation[move] - if len(optimized_moves)>0 and move.reverse()==optimized_moves[-1]: + if len(optimized_moves) > 0 and move.reverse() == optimized_moves[-1]: optimized_moves.pop() - elif len(optimized_moves)>1 and move==optimized_moves[-1] and move==optimized_moves[-2]: + elif len(optimized_moves) > 1 and move == optimized_moves[-1] and move == optimized_moves[-2]: optimized_moves.pop() optimized_moves.pop() optimized_moves.append(move.reverse()) diff --git a/magiccube/solver/basic/basic_solver.py b/magiccube/solver/basic/basic_solver.py index 77b817c..8c40cd0 100644 --- a/magiccube/solver/basic/basic_solver.py +++ b/magiccube/solver/basic/basic_solver.py @@ -3,8 +3,8 @@ from magiccube.optimizer.move_optimizer import MoveOptimizer from magiccube.solver.basic.solver_base import SolverException, SolverStage from magiccube.solver.basic.solver_stages import ConditionAction, stage_recenter_down, stage_recenter_front, stage_white_cross, \ - stage_white_corner, stage_2nd_layer, stage_top_cross, stage_order_top_cross, \ - stage_order_top_corners, stage_turn_top_corners + stage_white_corner, stage_2nd_layer, stage_top_cross, stage_order_top_cross, \ + stage_order_top_corners, stage_turn_top_corners stages = { @@ -38,52 +38,57 @@ "stage_2nd_layer_br": (("BR",), stage_2nd_layer), "stage_recenter_front_g3": (("G",), stage_recenter_front), - "stage_top_cross": (("YG","YR","YB","YO"), stage_top_cross), + "stage_top_cross": (("YG", "YR", "YB", "YO"), stage_top_cross), - "stage_order_top_cross": (("YG","YR","YB","YO"), stage_order_top_cross), - "stage_order_top_corners": (("YRG","YRB","YBO","YGO"), stage_order_top_corners), - "stage_turn_top_corners": (("YRG","YRB","YBO","YGO"), stage_turn_top_corners), + "stage_order_top_cross": (("YG", "YR", "YB", "YO"), stage_order_top_cross), + "stage_order_top_corners": (("YRG", "YRB", "YBO", "YGO"), stage_order_top_corners), + "stage_turn_top_corners": (("YRG", "YRB", "YBO", "YGO"), stage_turn_top_corners), } + class BasicSolver: - def __init__(self, cube:Cube, init_stages=None): - if cube.size!=3: + def __init__(self, cube: Cube, init_stages=None): + if cube.size != 3: raise SolverException("Solver only works with 3x3x3 cube") self.cube = cube - self.stages:List[SolverStage]=[] - self.default_debug =False - self.max_iterations_per_stage=12 + self.stages: List[SolverStage] = [] + self.default_debug = False + self.max_iterations_per_stage = 12 if init_stages is None: - for name,stage in stages.items(): - self.add(name=name,target_colors=stage[0], pattern_condition_actions=stage[1], debug=self.default_debug) + for name, stage in stages.items(): + self.add( + name=name, target_colors=stage[0], pattern_condition_actions=stage[1], debug=self.default_debug) else: for init_stage in init_stages: - self.add(name=init_stage,target_colors=stages[init_stage][0], - pattern_condition_actions=stages[init_stage][1], debug=self.default_debug) + self.add(name=init_stage, target_colors=stages[init_stage][0], + pattern_condition_actions=stages[init_stage][1], debug=self.default_debug) - def _solve_pattern_stage(self, stage:SolverStage)-> List[str]: + def _solve_pattern_stage(self, stage: SolverStage) -> List[str]: """Solve one stage of the cube""" full_actions = [] - iteration=0 + iteration = 0 while iteration < self.max_iterations_per_stage: - iteration+=1 - target_pieces = [self.cube.find_piece(target_color) for target_color in stage.target_colors] + iteration += 1 + target_pieces = [self.cube.find_piece( + target_color) for target_color in stage.target_colors] - if stage.debug:#pragma:no cover - print("solve_stage start:", stage.name, stage.target_colors, target_pieces) + if stage.debug: # pragma:no cover + print("solve_stage start:", stage.name, + stage.target_colors, target_pieces) print(self.cube) - actions,is_continue = stage.get_moves(target_pieces) + actions, is_continue = stage.get_moves(target_pieces) self.cube.rotate(actions) full_actions += actions - if stage.debug:#pragma:no cover - print("solve_stage end:", stage.name,target_pieces, actions, is_continue) + if stage.debug: # pragma:no cover + print("solve_stage end:", stage.name, + target_pieces, actions, is_continue) print(self.cube) if not is_continue: @@ -98,10 +103,10 @@ def _solve_pattern_stage(self, stage:SolverStage)-> List[str]: def solve(self, optimize=True): """Solve the cube by running all the registered pattern stages""" try: - full_actions=[] + full_actions = [] for stage in self.stages: - if stage.debug:#pragma:no cover - print("starting stage",stage) + if stage.debug: # pragma:no cover + print("starting stage", stage) actions = self._solve_pattern_stage(stage) full_actions += actions @@ -112,8 +117,8 @@ def solve(self, optimize=True): except CubeException as e: raise SolverException("unable to solve cube", e) from e - - def add(self,name, target_colors:Tuple[str,...], pattern_condition_actions:Tuple[ConditionAction, ...], debug=False): + def add(self, name, target_colors: Tuple[str, ...], pattern_condition_actions: Tuple[ConditionAction, ...], debug=False): """Add a stage to the solver.""" - self.stages.append(SolverStage(target_colors, pattern_condition_actions, name=name,debug=debug)) + self.stages.append(SolverStage( + target_colors, pattern_condition_actions, name=name, debug=debug)) return self diff --git a/magiccube/solver/basic/solver_base.py b/magiccube/solver/basic/solver_base.py index 91768f5..82215da 100644 --- a/magiccube/solver/basic/solver_base.py +++ b/magiccube/solver/basic/solver_base.py @@ -4,6 +4,7 @@ from magiccube.cube_move import CubeMove from magiccube.cube_piece import CubePiece + class SolverException(Exception): pass @@ -17,16 +18,15 @@ class Condition: The color condition may be '*' to indicate any color """ @staticmethod - def position_to_coord(position:int) -> Coordinates: + def position_to_coord(position: int) -> Coordinates: """Convert integer position to CubeCoordinates""" - x=position//100 + x = position//100 y = (position - x*100)//10 z = position-x*100-y*10 - return (x,y,z) - + return (x, y, z) - def __init__(self, position:int, accepted_colors_str:Tuple[str, ...]): - self.coordinate_condition=Condition.position_to_coord(position) + def __init__(self, position: int, accepted_colors_str: Tuple[str, ...]): + self.coordinate_condition = Condition.position_to_coord(position) color_condition = [] # build the pattern condition @@ -35,9 +35,9 @@ def __init__(self, position:int, accepted_colors_str:Tuple[str, ...]): None if color_str == "*" else Color.create(color_str) for color_str in accepted_color ))) - self.color_condition:List[ColorOrientation]=color_condition + self.color_condition: List[ColorOrientation] = color_condition - def _is_color_match(self,orientation_pattern:ColorOrientation,color:ColorOrientation)->bool: + def _is_color_match(self, orientation_pattern: ColorOrientation, color: ColorOrientation) -> bool: """ Return True if the piece colors match the orientation pattern """ filtered_color = [c for c in color if c is not None] @@ -48,13 +48,13 @@ def _is_color_match(self,orientation_pattern:ColorOrientation,color:ColorOrienta return False return True - - def is_match(self, target_coordinates:Coordinates, target_piece:CubePiece): + def is_match(self, target_coordinates: Coordinates, target_piece: CubePiece): """ Return True if the the piece coordinates and color orientation match the PatternCondition """ - assert len(self.color_condition[0]) == target_piece.get_piece_type().value + assert len(self.color_condition[0] + ) == target_piece.get_piece_type().value - if target_coordinates!= self.coordinate_condition: + if target_coordinates != self.coordinate_condition: return False for accepted_color in self.color_condition: @@ -62,53 +62,59 @@ def is_match(self, target_coordinates:Coordinates, target_piece:CubePiece): return True return False - def __str__(self):#pragma:no cover + def __str__(self): # pragma:no cover return f"PatternCondition: {self.coordinate_condition} {self.color_condition}" + @dataclass class ConditionAction: """Defines a list of actions to be triggered when the conditions are matched""" - def __init__(self,conditions:Tuple[Condition, ...],action:str,is_continue:bool): - self.conditions=conditions + def __init__(self, conditions: Tuple[Condition, ...], action: str, is_continue: bool): + self.conditions = conditions - action_list=action.split(" ") - action_list = [CubeMove.create(a) for a in action_list if a!=""] + action_list = action.split(" ") + action_list = [CubeMove.create(a) for a in action_list if a != ""] - self.action=action_list - self.is_continue=is_continue + self.action = action_list + self.is_continue = is_continue - def _is_any_match(self, coordinates:Coordinates, piece:CubePiece): + def _is_any_match(self, coordinates: Coordinates, piece: CubePiece): """Return True if the piece coordinates+color orientation match any of the conditions""" - result = any((condition.is_match(coordinates, piece) for condition in self.conditions)) + result = any((condition.is_match(coordinates, piece) + for condition in self.conditions)) return result - def is_match(self, pieces:List[Tuple[Coordinates, CubePiece]]): + def is_match(self, pieces: List[Tuple[Coordinates, CubePiece]]): """Return True if the given pieces match the pattern conditions""" - assert len(pieces)==len(self.conditions) - result = not any((not self._is_any_match(coord,piece) for coord,piece in pieces)) + assert len(pieces) == len(self.conditions) + result = not any((not self._is_any_match(coord, piece) + for coord, piece in pieces)) return result + class SolverStage: """Defines an individual solver stage. target_colors describe the pieces in which the conditions (cond_actions) are going to be checked against. """ - def __init__(self, target_colors:Tuple[str,...], cond_actions:Tuple[ConditionAction, ...],name=None, debug=False): - self.target_colors=target_colors - self.cond_actions=cond_actions - self.debug=debug - self.name=name - def get_moves(self, target_pieces:List[Tuple[Coordinates, CubePiece]]) -> Tuple[List[CubeMove],bool]: + def __init__(self, target_colors: Tuple[str, ...], cond_actions: Tuple[ConditionAction, ...], name=None, debug=False): + self.target_colors = target_colors + self.cond_actions = cond_actions + self.debug = debug + self.name = name + + def get_moves(self, target_pieces: List[Tuple[Coordinates, CubePiece]]) -> Tuple[List[CubeMove], bool]: """Run through the stage conditions and check for match. Return the matched action.""" for p_cond_action in self.cond_actions: if p_cond_action.is_match(target_pieces): - return p_cond_action.action,p_cond_action.is_continue - raise SolverException(f"{self.name}: no valid conditions found for the pieces: {target_pieces}")#pragma:no cover + return p_cond_action.action, p_cond_action.is_continue + raise SolverException( + f"{self.name}: no valid conditions found for the pieces: {target_pieces}") # pragma:no cover - def __str__(self):#pragma:no cover + def __str__(self): # pragma:no cover return f"Stage:{self.name} | {self.target_colors}" - def __repr__(self):#pragma:no cover + def __repr__(self): # pragma:no cover return f"Stage:{self.name} | {self.target_colors}" diff --git a/magiccube/solver/basic/solver_stages.py b/magiccube/solver/basic/solver_stages.py index 033e000..fc54f18 100644 --- a/magiccube/solver/basic/solver_stages.py +++ b/magiccube/solver/basic/solver_stages.py @@ -1,445 +1,445 @@ -from magiccube.solver.basic.solver_base import Condition,ConditionAction +from magiccube.solver.basic.solver_base import Condition, ConditionAction stage_recenter_down = ( ConditionAction(( - Condition(101,("*",)), - ),"", False), + Condition(101, ("*",)), + ), "", False), ConditionAction(( - Condition(121,("*",)), - ),"X X", False), + Condition(121, ("*",)), + ), "X X", False), ConditionAction(( - Condition(110,("*",)), - ),"X", False), + Condition(110, ("*",)), + ), "X", False), ConditionAction(( - Condition(112,("*",)), - ),"X'", False), + Condition(112, ("*",)), + ), "X'", False), ConditionAction(( - Condition( 11,("*",)), - ),"Z'", False), + Condition(11, ("*",)), + ), "Z'", False), ConditionAction(( - Condition(211,("*",)), - ),"Z", False), + Condition(211, ("*",)), + ), "Z", False), ) stage_recenter_front = ( ConditionAction(( - Condition(110,("*",)), - ),"Y Y", False), + Condition(110, ("*",)), + ), "Y Y", False), ConditionAction(( - Condition(112,("*",)), - ),"", False), + Condition(112, ("*",)), + ), "", False), ConditionAction(( - Condition( 11,("*",)), - ),"Y'", False), + Condition(11, ("*",)), + ), "Y'", False), ConditionAction(( - Condition(211,("*",)), - ),"Y", False), + Condition(211, ("*",)), + ), "Y", False), ) stage_white_cross = ( ConditionAction(( - Condition(100,("W*",)), - ),"", False), + Condition(100, ("W*",)), + ), "", False), ConditionAction(( - Condition(100,("*W",)), - ),"B D' R D", False), + Condition(100, ("*W",)), + ), "B D' R D", False), ConditionAction(( - Condition(201,("W*",)), - ),"R' B'", False), + Condition(201, ("W*",)), + ), "R' B'", False), ConditionAction(( - Condition(201,("*W",)), - ),"R' D' R D", False), + Condition(201, ("*W",)), + ), "R' D' R D", False), ConditionAction(( - Condition(102,("W*",)), - ),"F F U U B B", False), + Condition(102, ("W*",)), + ), "F F U U B B", False), ConditionAction(( - Condition(102,("*W",)), - ),"F' D' R' D", False), + Condition(102, ("*W",)), + ), "F' D' R' D", False), ConditionAction(( - Condition(1 ,("W*",)), - ),"L B", False), + Condition(1, ("W*",)), + ), "L B", False), ConditionAction(( - Condition(1 ,("*W",)), - ),"L D L' D'", False), + Condition(1, ("*W",)), + ), "L D L' D'", False), ConditionAction(( - Condition(210,("*W",)), - ),"D' R D", False), + Condition(210, ("*W",)), + ), "D' R D", False), ConditionAction(( - Condition(210,("W*",)), - ),"B'", False), + Condition(210, ("W*",)), + ), "B'", False), ConditionAction(( - Condition(212,("*W",)), - ),"D' R' D", False), + Condition(212, ("*W",)), + ), "D' R' D", False), ConditionAction(( - Condition(212,("W*",)), - ),"D D F D D", False), + Condition(212, ("W*",)), + ), "D D F D D", False), ConditionAction(( - Condition(12 ,("*W",)), - ),"D L D'", False), + Condition(12, ("*W",)), + ), "D L D'", False), ConditionAction(( - Condition(12 ,("W*",)), - ),"D D F' D D", False), + Condition(12, ("W*",)), + ), "D D F' D D", False), ConditionAction(( - Condition(10 ,("*W",)), - ),"D L' D'", False), + Condition(10, ("*W",)), + ), "D L' D'", False), ConditionAction(( - Condition(10 ,("W*",)), - ),"B", False), + Condition(10, ("W*",)), + ), "B", False), ConditionAction(( - Condition(120,("W*",)), - ),"B B", False), + Condition(120, ("W*",)), + ), "B B", False), ConditionAction(( - Condition(120,("*W",)), - ),"B' D' R D", False), + Condition(120, ("*W",)), + ), "B' D' R D", False), ConditionAction(( - Condition(221,("W*",)), - ),"U' B D L' D'", False), + Condition(221, ("W*",)), + ), "U' B D L' D'", False), ConditionAction(( - Condition(221,("*W",)), - ),"U' B B", False), + Condition(221, ("*W",)), + ), "U' B B", False), ConditionAction(( - Condition(122,("W*",)), - ),"U U B B", False), + Condition(122, ("W*",)), + ), "U U B B", False), ConditionAction(( - Condition(122,("*W",)), - ),"U' D' R D B'", False), + Condition(122, ("*W",)), + ), "U' D' R D B'", False), ConditionAction(( - Condition(21 ,("W*",)), - ),"U B D L' D'", False), + Condition(21, ("W*",)), + ), "U B D L' D'", False), ConditionAction(( - Condition(21 ,("*W",)), - ),"U B B", False), + Condition(21, ("*W",)), + ), "U B B", False), ) stage_white_corner = ( ConditionAction(( - Condition( 20,("W**",)), - ),"F' U U F", True), + Condition(20, ("W**",)), + ), "F' U U F", True), ConditionAction(( - Condition( 20,("*W*",)), - ),"U U R U' R' ", True), + Condition(20, ("*W*",)), + ), "U U R U' R' ", True), ConditionAction(( - Condition( 20,("**W",)), - ),"R U U R'", True), + Condition(20, ("**W",)), + ), "R U U R'", True), ConditionAction(( - Condition(220,("W**",)), - ),"U' R U U R'", True), + Condition(220, ("W**",)), + ), "U' R U U R'", True), ConditionAction(( - Condition(220,("*W*",)), - ),"U R U' R' ", True), + Condition(220, ("*W*",)), + ), "U R U' R' ", True), ConditionAction(( - Condition(220,("**W",)), - ),"F' U F", True), + Condition(220, ("**W",)), + ), "F' U F", True), ConditionAction(( - Condition(222,("W**",)), - ),"U' F' U F", True), + Condition(222, ("W**",)), + ), "U' F' U F", True), ConditionAction(( - Condition(222,("*W*",)), - ),"R U' R' ", True), + Condition(222, ("*W*",)), + ), "R U' R' ", True), ConditionAction(( - Condition(222,("**W",)), - ),"U R U' R'", True), + Condition(222, ("**W",)), + ), "U R U' R'", True), ConditionAction(( - Condition( 22,("W**",)), - ),"R U' R'", True), + Condition(22, ("W**",)), + ), "R U' R'", True), ConditionAction(( - Condition( 22,("*W*",)), - ),"U' R U' R'", True), + Condition(22, ("*W*",)), + ), "U' R U' R'", True), ConditionAction(( - Condition( 22,("**W",)), - ),"U F' U U F", True), + Condition(22, ("**W",)), + ), "U F' U U F", True), ConditionAction(( - Condition( 0,("W**",)), - ),"B' U B ", True), + Condition(0, ("W**",)), + ), "B' U B ", True), ConditionAction(( - Condition( 0,("*W*",)), - ),"B' U' B U ", True), + Condition(0, ("*W*",)), + ), "B' U' B U ", True), ConditionAction(( - Condition( 0,("**W",)), - ),"B' U' B U ", True), + Condition(0, ("**W",)), + ), "B' U' B U ", True), ConditionAction(( - Condition(200,("W**",)), - ),"R' U' R ", True), + Condition(200, ("W**",)), + ), "R' U' R ", True), ConditionAction(( - Condition(200,("*W*",)), - ),"B U B' ", True), + Condition(200, ("*W*",)), + ), "B U B' ", True), ConditionAction(( - Condition(200,("**W",)), - ),"B U B' ", True), + Condition(200, ("**W",)), + ), "B U B' ", True), ConditionAction(( - Condition(202,("W**",)), - ),"R U R'", True), + Condition(202, ("W**",)), + ), "R U R'", True), ConditionAction(( - Condition(202,("*W*",)), - ),"", False), + Condition(202, ("*W*",)), + ), "", False), ConditionAction(( - Condition(202,("**W",)), - ),"R U' R'", True), + Condition(202, ("**W",)), + ), "R U' R'", True), ConditionAction(( - Condition( 2,("W**",)), - ),"L' U' L ", True), + Condition(2, ("W**",)), + ), "L' U' L ", True), ConditionAction(( - Condition( 2,("*W*",)), - ),"L' U' L ", True), + Condition(2, ("*W*",)), + ), "L' U' L ", True), ConditionAction(( - Condition( 2,("**W",)), - ),"L' U L ", True), + Condition(2, ("**W",)), + ), "L' U L ", True), ) stage_2nd_layer = ( ConditionAction(( - Condition(221,("OB","GO","RG","BR")), - #),"Y' U U U' L' U L U F U' F' Y", True), - ),"Y' U U U R U' R' U' F' U F Y", True), + Condition(221, ("OB", "GO", "RG", "BR")), + # ),"Y' U U U' L' U L U F U' F' Y", True), + ), "Y' U U U R U' R' U' F' U F Y", True), ConditionAction(( - Condition(221,("BO","OG","GR","RB")), - ),"U", True), + Condition(221, ("BO", "OG", "GR", "RB")), + ), "U", True), ConditionAction(( - Condition(120,("OB","GO","RG","BR")), - ),"U U", True), + Condition(120, ("OB", "GO", "RG", "BR")), + ), "U U", True), ConditionAction(( - Condition(120,("BO","OG","GR","RB")), - ),"Y' U' U R U' R' U' F' U F Y", True), + Condition(120, ("BO", "OG", "GR", "RB")), + ), "Y' U' U R U' R' U' F' U F Y", True), ConditionAction(( - Condition( 21,("OB","GO","RG","BR")), - ),"Y' U R U' R' U' F' U F Y", True), + Condition(21, ("OB", "GO", "RG", "BR")), + ), "Y' U R U' R' U' F' U F Y", True), ConditionAction(( - Condition( 21,("BO","OG","GR","RB")), - ),"U'", True), + Condition(21, ("BO", "OG", "GR", "RB")), + ), "U'", True), ConditionAction(( - Condition(122,("BO","OG","GR","RB")), - ),"U' L' U L U F U' F'", True), + Condition(122, ("BO", "OG", "GR", "RB")), + ), "U' L' U L U F U' F'", True), ConditionAction(( - Condition(122,("OB","GO","RG","BR")), - ),"U' L' U L U F U' F'", False), + Condition(122, ("OB", "GO", "RG", "BR")), + ), "U' L' U L U F U' F'", False), ConditionAction(( - Condition(212,("BO","OB","OG","GO","GR","RG","RB","BR")), - ),"U R U' R' U' F' U F", True), + Condition(212, ("BO", "OB", "OG", "GO", "GR", "RG", "RB", "BR")), + ), "U R U' R' U' F' U F", True), ConditionAction(( - Condition( 12,("BO","OG","GR","RB")), - ),"U' L' U L U F U' F'", True), + Condition(12, ("BO", "OG", "GR", "RB")), + ), "U' L' U L U F U' F'", True), ConditionAction(( - Condition( 12,("OB","GO","RG","BR")), - ),"", False), + Condition(12, ("OB", "GO", "RG", "BR")), + ), "", False), ConditionAction(( - Condition( 10,("BO","OB","OG","GO","GR","RG","RB","BR")), - ),"Y' U' L' U L U F U' F' Y", True), + Condition(10, ("BO", "OB", "OG", "GO", "GR", "RG", "RB", "BR")), + ), "Y' U' L' U L U F U' F' Y", True), ConditionAction(( - Condition(210,("BO","OB","OG","GO","GR","RG","RB","BR")), - ),"Y U R U' R' U' F' U F Y'", True), + Condition(210, ("BO", "OB", "OG", "GO", "GR", "RG", "RB", "BR")), + ), "Y U R U' R' U' F' U F Y'", True), ) stage_top_cross = ( ConditionAction(( - Condition(120,("Y*",)), # B - OK=Y* - Condition(221,("*Y",)), # R - OK=*Y - Condition(122,("Y*",)), # F - OK=Y* - Condition( 21,("*Y",)), # L - OK=*Y - ),"", False), - ConditionAction(( - Condition(120,("Y*",)), # B - OK=Y* - Condition(221,("*Y",)), # R - OK=*Y - Condition(122,("*Y",)), # F - OK=Y* NOK - Condition( 21,("Y*",)), # L - OK=*Y NOK - ),"U'", True), - ConditionAction(( - Condition(120,("*Y",)), # B - OK=Y* NOK - Condition(221,("*Y",)), # R - OK=*Y - Condition(122,("Y*",)), # F - OK=Y* - Condition( 21,("Y*",)), # L - OK=*Y NOK - ),"U U", True), - ConditionAction(( - Condition(120,("*Y",)), # B - OK=Y* NOK - Condition(221,("Y*",)), # R - OK=*Y NOK - Condition(122,("Y*",)), # F - OK=Y* - Condition( 21,("*Y",)), # L - OK=*Y - ),"U", True), - ConditionAction(( # L shape - Condition(120,("Y*",)), # B - OK=Y* - Condition(221,("Y*",)), # R - OK=*Y NOK - Condition(122,("*Y",)), # F - OK=Y* NOK - Condition( 21,("*Y",)), # L - OK=*Y - ),"F R U R' U' F'", True), - ConditionAction(( - Condition(120,("Y*",)), # B - OK=Y* - Condition(221,("Y*",)), # R - OK=*Y NOK - Condition(122,("Y*",)), # F - OK=Y* - Condition( 21,("Y*",)), # L - OK=*Y NOK - ),"U", True), - ConditionAction(( # LINE shape - Condition(120,("*Y",)), # B - OK=Y* NOK - Condition(221,("*Y",)), # R - OK=*Y - Condition(122,("*Y",)), # F - OK=Y* NOK - Condition( 21,("*Y",)), # L - OK=*Y - ),"F R U R' U' F'", False), - ConditionAction(( # NONE - Condition(120,("*Y",)), # B - OK=Y* NOK - Condition(221,("Y*",)), # R - OK=*Y - Condition(122,("*Y",)), # F - OK=Y* NOK - Condition( 21,("Y*",)), # L - OK=*Y - ),"F R U R' U' F'", True), + Condition(120, ("Y*",)), # B - OK=Y* + Condition(221, ("*Y",)), # R - OK=*Y + Condition(122, ("Y*",)), # F - OK=Y* + Condition(21, ("*Y",)), # L - OK=*Y + ), "", False), + ConditionAction(( + Condition(120, ("Y*",)), # B - OK=Y* + Condition(221, ("*Y",)), # R - OK=*Y + Condition(122, ("*Y",)), # F - OK=Y* NOK + Condition(21, ("Y*",)), # L - OK=*Y NOK + ), "U'", True), + ConditionAction(( + Condition(120, ("*Y",)), # B - OK=Y* NOK + Condition(221, ("*Y",)), # R - OK=*Y + Condition(122, ("Y*",)), # F - OK=Y* + Condition(21, ("Y*",)), # L - OK=*Y NOK + ), "U U", True), + ConditionAction(( + Condition(120, ("*Y",)), # B - OK=Y* NOK + Condition(221, ("Y*",)), # R - OK=*Y NOK + Condition(122, ("Y*",)), # F - OK=Y* + Condition(21, ("*Y",)), # L - OK=*Y + ), "U", True), + ConditionAction(( # L shape + Condition(120, ("Y*",)), # B - OK=Y* + Condition(221, ("Y*",)), # R - OK=*Y NOK + Condition(122, ("*Y",)), # F - OK=Y* NOK + Condition(21, ("*Y",)), # L - OK=*Y + ), "F R U R' U' F'", True), + ConditionAction(( + Condition(120, ("Y*",)), # B - OK=Y* + Condition(221, ("Y*",)), # R - OK=*Y NOK + Condition(122, ("Y*",)), # F - OK=Y* + Condition(21, ("Y*",)), # L - OK=*Y NOK + ), "U", True), + ConditionAction(( # LINE shape + Condition(120, ("*Y",)), # B - OK=Y* NOK + Condition(221, ("*Y",)), # R - OK=*Y + Condition(122, ("*Y",)), # F - OK=Y* NOK + Condition(21, ("*Y",)), # L - OK=*Y + ), "F R U R' U' F'", False), + ConditionAction(( # NONE + Condition(120, ("*Y",)), # B - OK=Y* NOK + Condition(221, ("Y*",)), # R - OK=*Y + Condition(122, ("*Y",)), # F - OK=Y* NOK + Condition(21, ("Y*",)), # L - OK=*Y + ), "F R U R' U' F'", True), ) stage_order_top_cross = ( ConditionAction(( - Condition(120,("YB",)), # B - OK=Y* - Condition(221,("OY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("RY",)), # L - OK=*Y - ),"", False), - ConditionAction(( - Condition(120,("YB",)), # B - OK=Y* - Condition(221,("OY",)), # R - OK=*Y - Condition(122,("GY",)), # F - OK=Y* - Condition( 21,("YR",)), # L - OK=*Y - ),"R U R' U R U U R' U", False), + Condition(120, ("YB",)), # B - OK=Y* + Condition(221, ("OY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("RY",)), # L - OK=*Y + ), "", False), + ConditionAction(( + Condition(120, ("YB",)), # B - OK=Y* + Condition(221, ("OY",)), # R - OK=*Y + Condition(122, ("GY",)), # F - OK=Y* + Condition(21, ("YR",)), # L - OK=*Y + ), "R U R' U R U U R' U", False), ConditionAction(( - Condition(120,("YR",)), # B - OK=Y* - Condition(221,("BY",)), # R - OK=*Y - Condition(122,("GY",)), # F - OK=Y* - Condition( 21,("YO",)), # L - OK=*Y - ),"R U R' U R U U R' U U'", False), + Condition(120, ("YR",)), # B - OK=Y* + Condition(221, ("BY",)), # R - OK=*Y + Condition(122, ("GY",)), # F - OK=Y* + Condition(21, ("YO",)), # L - OK=*Y + ), "R U R' U R U U R' U U'", False), ConditionAction(( - Condition(120,("YO",)), # B - OK=Y* - Condition(221,("BY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("RY",)), # L - OK=*Y - ),"U U R U R' U R U U R' U U U", False), + Condition(120, ("YO",)), # B - OK=Y* + Condition(221, ("BY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("RY",)), # L - OK=*Y + ), "U U R U R' U R U U R' U U U", False), ConditionAction(( - Condition(120,("YR",)), # B - OK=Y* - Condition(221,("OY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("BY",)), # L - OK=*Y - ),"U' R U R' U R U U R' U U", False), + Condition(120, ("YR",)), # B - OK=Y* + Condition(221, ("OY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("BY",)), # L - OK=*Y + ), "U' R U R' U R U U R' U U", False), ConditionAction(( - Condition(120,("YO",)), # B - OK=Y* - Condition(221,("RY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("BY",)), # L - OK=*Y - ),"U R U R' U R U U R' U", False), + Condition(120, ("YO",)), # B - OK=Y* + Condition(221, ("RY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("BY",)), # L - OK=*Y + ), "U R U R' U R U U R' U", False), ConditionAction(( - Condition(120,("YR",)), # B - OK=Y* - Condition(221,("BY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("OY",)), # L - OK=*Y - ),"R U R' U R U U R' U U'", False), + Condition(120, ("YR",)), # B - OK=Y* + Condition(221, ("BY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("OY",)), # L - OK=*Y + ), "R U R' U R U U R' U U'", False), ConditionAction(( - Condition(120,("YB",)), # B - OK=Y* - Condition(221,("RY",)), # R - OK=*Y - Condition(122,("YG",)), # F - OK=Y* - Condition( 21,("OY",)), # L - OK=*Y - ),"R U R' U R U U R' U", True), + Condition(120, ("YB",)), # B - OK=Y* + Condition(221, ("RY",)), # R - OK=*Y + Condition(122, ("YG",)), # F - OK=Y* + Condition(21, ("OY",)), # L - OK=*Y + ), "R U R' U R U U R' U", True), ConditionAction(( - Condition(120,("YG",)), # B - OK=Y* - Condition(221,("**",)), # R - OK=*Y - Condition(122,("**",)), # F - OK=Y* - Condition( 21,("**",)), # L - OK=*Y - ),"U U", True), - ConditionAction(( - Condition(120,("**",)), # B - OK=Y* - Condition(221,("GY",)), # R - OK=*Y - Condition(122,("**",)), # F - OK=Y* - Condition( 21,("**",)), # L - OK=*Y - ),"U", True), - ConditionAction(( - Condition(120,("**",)), # B - OK=Y* - Condition(221,("**",)), # R - OK=*Y - Condition(122,("**",)), # F - OK=Y* - Condition( 21,("GY",)), # L - OK=*Y - ),"U'", True), + Condition(120, ("YG",)), # B - OK=Y* + Condition(221, ("**",)), # R - OK=*Y + Condition(122, ("**",)), # F - OK=Y* + Condition(21, ("**",)), # L - OK=*Y + ), "U U", True), + ConditionAction(( + Condition(120, ("**",)), # B - OK=Y* + Condition(221, ("GY",)), # R - OK=*Y + Condition(122, ("**",)), # F - OK=Y* + Condition(21, ("**",)), # L - OK=*Y + ), "U", True), + ConditionAction(( + Condition(120, ("**",)), # B - OK=Y* + Condition(221, ("**",)), # R - OK=*Y + Condition(122, ("**",)), # F - OK=Y* + Condition(21, ("GY",)), # L - OK=*Y + ), "U'", True), ) stage_order_top_corners = ( ConditionAction(( - Condition( 20,("RYB","BRY","YBR",)), - Condition(220,("OYB","BOY","YBO",)), - Condition(222,("OYG","GOY","YGO",)), - Condition( 22,("RYG","GRY","YGR",)), - ),"", False), + Condition(20, ("RYB", "BRY", "YBR",)), + Condition(220, ("OYB", "BOY", "YBO",)), + Condition(222, ("OYG", "GOY", "YGO",)), + Condition(22, ("RYG", "GRY", "YGR",)), + ), "", False), ConditionAction(( - Condition( 20,("RYB","BRY","YBR",)), - Condition(220,("***",)), - Condition(222,("***",)), - Condition( 22,("***",)), - ),"Y Y U R U' L' U R' U' L Y Y", True), + Condition(20, ("RYB", "BRY", "YBR",)), + Condition(220, ("***",)), + Condition(222, ("***",)), + Condition(22, ("***",)), + ), "Y Y U R U' L' U R' U' L Y Y", True), ConditionAction(( - Condition( 20,("***",)), - Condition(220,("OYB","BOY","YBO",)), - Condition(222,("***",)), - Condition( 22,("***",)), - ),"Y U R U' L' U R' U' L Y'", True), + Condition(20, ("***",)), + Condition(220, ("OYB", "BOY", "YBO",)), + Condition(222, ("***",)), + Condition(22, ("***",)), + ), "Y U R U' L' U R' U' L Y'", True), ConditionAction(( - Condition( 20,("***",)), - Condition(220,("***",)), - Condition(222,("OYG","GOY","YGO",)), - Condition( 22,("***",)), - ),"U R U' L' U R' U' L", True), + Condition(20, ("***",)), + Condition(220, ("***",)), + Condition(222, ("OYG", "GOY", "YGO",)), + Condition(22, ("***",)), + ), "U R U' L' U R' U' L", True), ConditionAction(( - Condition( 20,("***",)), - Condition(220,("***",)), - Condition(222,("***",)), - Condition( 22,("RYG","GRY","YGR",)), - ),"Y' U R U' L' U R' U' L Y", True), + Condition(20, ("***",)), + Condition(220, ("***",)), + Condition(222, ("***",)), + Condition(22, ("RYG", "GRY", "YGR",)), + ), "Y' U R U' L' U R' U' L Y", True), ConditionAction(( - Condition( 20,("***",)), - Condition(220,("***",)), - Condition(222,("***",)), - Condition(22,("***",)), - ),"U R U' L' U R' U' L", True), + Condition(20, ("***",)), + Condition(220, ("***",)), + Condition(222, ("***",)), + Condition(22, ("***",)), + ), "U R U' L' U R' U' L", True), ) stage_turn_top_corners = ( ConditionAction(( - Condition( 20,("RYB",)), - Condition(220,("OYB",)), - Condition(222,("OYG",)), - Condition( 22,("RYG",)), - ),"", False), - ConditionAction(( - Condition( 20,("BYO",)), - Condition(220,("GYO",)), - Condition(222,("GYR",)), - Condition( 22,("BYR",)), - ),"U", False), - ConditionAction(( - Condition( 20,("OYG",)), - Condition(220,("RYG",)), - Condition(222,("RYB",)), - Condition( 22,("OYB",)), - ),"U U", False), - ConditionAction(( - Condition( 20,("GYR",)), - Condition(220,("BYR",)), - Condition(222,("BYO",)), - Condition( 22,("GYO",)), - ),"U'", False), - ConditionAction(( - Condition( 20,("***",)), - Condition(220,("***",)), - Condition(222,("*B*","*R*","*G*","*O*",)), - Condition( 22,("***",)), - ),"R' D' R D R' D' R D", True), - ConditionAction(( - Condition( 20,("***",)), - Condition(220,("***",)), - Condition(222,("*Y*",)), - Condition( 22,("***",)), - ),"U", True), + Condition(20, ("RYB",)), + Condition(220, ("OYB",)), + Condition(222, ("OYG",)), + Condition(22, ("RYG",)), + ), "", False), + ConditionAction(( + Condition(20, ("BYO",)), + Condition(220, ("GYO",)), + Condition(222, ("GYR",)), + Condition(22, ("BYR",)), + ), "U", False), + ConditionAction(( + Condition(20, ("OYG",)), + Condition(220, ("RYG",)), + Condition(222, ("RYB",)), + Condition(22, ("OYB",)), + ), "U U", False), + ConditionAction(( + Condition(20, ("GYR",)), + Condition(220, ("BYR",)), + Condition(222, ("BYO",)), + Condition(22, ("GYO",)), + ), "U'", False), + ConditionAction(( + Condition(20, ("***",)), + Condition(220, ("***",)), + Condition(222, ("*B*", "*R*", "*G*", "*O*",)), + Condition(22, ("***",)), + ), "R' D' R D R' D' R D", True), + ConditionAction(( + Condition(20, ("***",)), + Condition(220, ("***",)), + Condition(222, ("*Y*",)), + Condition(22, ("***",)), + ), "U", True), ) diff --git a/test/test_base.py b/test/test_base.py index 77a00b5..90a76f8 100644 --- a/test/test_base.py +++ b/test/test_base.py @@ -3,6 +3,7 @@ from magiccube.cube_base import Face from magiccube.cube_piece import Color + def test_face_create(): assert Face.create("F") == Face.F assert Face.create("B") == Face.B @@ -14,16 +15,18 @@ def test_face_create(): with pytest.raises(CubeException): Face.create("X") + def test_color_create(): - assert Color.create("R")==Color.R - assert Color.create("O")==Color.O - assert Color.create("B")==Color.B - assert Color.create("G")==Color.G - assert Color.create("Y")==Color.Y - assert Color.create("W")==Color.W + assert Color.create("R") == Color.R + assert Color.create("O") == Color.O + assert Color.create("B") == Color.B + assert Color.create("G") == Color.G + assert Color.create("Y") == Color.Y + assert Color.create("W") == Color.W with pytest.raises(CubeException): Color.create("X") -if __name__ == "__main__" : + +if __name__ == "__main__": pytest.main() diff --git a/test/test_cube.py b/test/test_cube.py index 044bc51..f47022e 100644 --- a/test/test_cube.py +++ b/test/test_cube.py @@ -9,6 +9,7 @@ from magiccube.solver.basic.basic_solver import BasicSolver, SolverException + def test_cube_size_1(): with pytest.raises(CubeException): Cube(1) @@ -22,6 +23,7 @@ def test_reset(): c.reset() assert c.is_done() + def test_12_moves(): c = Cube(3) c.check_consistency() @@ -30,6 +32,7 @@ def test_12_moves(): c.check_consistency() assert c.is_done() + def test_12_moves_2d(): c = Cube(2) c.check_consistency() @@ -45,6 +48,7 @@ def test_all_rotations(): c.check_consistency() assert c.is_done() + def test_rotations_4x(): c = Cube(4) c.rotate("R R'") @@ -53,30 +57,32 @@ def test_rotations_4x(): c.rotate("2R") c.check_consistency() - assert c.get_face_flat(Face.F)==[ - Color.G,Color.G,Color.W,Color.G, - Color.G,Color.G,Color.W,Color.G, - Color.G,Color.G,Color.W,Color.G, - Color.G,Color.G,Color.W,Color.G, - ] + assert c.get_face_flat(Face.F) == [ + Color.G, Color.G, Color.W, Color.G, + Color.G, Color.G, Color.W, Color.G, + Color.G, Color.G, Color.W, Color.G, + Color.G, Color.G, Color.W, Color.G, + ] c.reset() c.rotate("Uw") - assert c.get_face_flat(Face.F)==[ - Color.O,Color.O,Color.O,Color.O, - Color.O,Color.O,Color.O,Color.O, - Color.G,Color.G,Color.G,Color.G, - Color.G,Color.G,Color.G,Color.G, - ] + assert c.get_face_flat(Face.F) == [ + Color.O, Color.O, Color.O, Color.O, + Color.O, Color.O, Color.O, Color.O, + Color.G, Color.G, Color.G, Color.G, + Color.G, Color.G, Color.G, Color.G, + ] c.check_consistency() + def test_all_rotations_2d(): c = Cube(2) c.rotate("R R' L L' B B' F F' U U' D D'") c.check_consistency() assert c.is_done() + def test_is_done(): c = Cube(3) assert c.is_done() @@ -85,40 +91,48 @@ def test_is_done(): c.reset() assert c.is_done() + def test_print_pattern1(): c = Cube(3) c.rotate("R R L' L' B B F' F' U U D' D'") c.check_consistency() print(c) + def test_print_pattern2(): c = Cube(3) c.rotate("R' L U D' F B' R' L") c.check_consistency() print(c) + def test_print_2d(): c = Cube(2) c.check_consistency() print(c) + def test_print_4d(): c = Cube(4) c.check_consistency() print(c) + def test_history_str(): c = Cube(3) moves = "R' L U D' F B' R' L" c.rotate(moves) assert c.history(to_str=True) == moves + def test_history(): c = Cube(5) - moves = [CubeMove(CubeMoveType.R, False),CubeMove(CubeMoveType.F, True), CubeMove(CubeMoveType.D, False, wide=True, layer=2)] + moves = [CubeMove(CubeMoveType.R, False), CubeMove( + CubeMoveType.F, True), CubeMove(CubeMoveType.D, False, wide=True, layer=2)] c.rotate(moves) assert c.history() == moves + def test_reverse(): c = Cube(3) moves = "R' L U D' F B' R' L" @@ -127,135 +141,157 @@ def test_reverse(): c.rotate(c.reverse_history()) assert c.is_done() + def test_scramble_3x3(): c = Cube(3) c.scramble(num_steps=50) print(c) assert not c.is_done() + def test_scramble_2x2(): c = Cube(2) c.scramble(num_steps=50) print(c) assert not c.is_done() + def test_scramble_4x4(): c = Cube(4) c.scramble(num_steps=50) # print(c) assert not c.is_done() + def test_get_piece(): c = Cube(3) - piece = c.get_piece((2,0,0)) - assert piece.get_piece_color(Face.R.get_axis())==Color.O - assert piece.get_piece_color(Face.D.get_axis())==Color.W - assert piece.get_piece_color(Face.B.get_axis())==Color.B + piece = c.get_piece((2, 0, 0)) + assert piece.get_piece_color(Face.R.get_axis()) == Color.O + assert piece.get_piece_color(Face.D.get_axis()) == Color.W + assert piece.get_piece_color(Face.B.get_axis()) == Color.B - piece = c.get_piece((0,2,2)) - assert piece.get_piece_color(Face.L.get_axis())==Color.R - assert piece.get_piece_color(Face.U.get_axis())==Color.Y - assert piece.get_piece_color(Face.F.get_axis())==Color.G + piece = c.get_piece((0, 2, 2)) + assert piece.get_piece_color(Face.L.get_axis()) == Color.R + assert piece.get_piece_color(Face.U.get_axis()) == Color.Y + assert piece.get_piece_color(Face.F.get_axis()) == Color.G def test_get_all_faces(): c = Cube(3) faces = c.get_all_faces() - assert np.all(np.array(faces[Face.F]).flatten()==Color.G) - assert np.all(np.array(faces[Face.B]).flatten()==Color.B) - assert np.all(np.array(faces[Face.L]).flatten()==Color.R) - assert np.all(np.array(faces[Face.R]).flatten()==Color.O) - assert np.all(np.array(faces[Face.U]).flatten()==Color.Y) - assert np.all(np.array(faces[Face.D]).flatten()==Color.W) + assert np.all(np.array(faces[Face.F]).flatten() == Color.G) + assert np.all(np.array(faces[Face.B]).flatten() == Color.B) + assert np.all(np.array(faces[Face.L]).flatten() == Color.R) + assert np.all(np.array(faces[Face.R]).flatten() == Color.O) + assert np.all(np.array(faces[Face.U]).flatten() == Color.Y) + assert np.all(np.array(faces[Face.D]).flatten() == Color.W) + def test_get_all_pieces(): - c=Cube(3) + c = Cube(3) pieces = c.get_all_pieces() assert len(pieces) == 26 - c=Cube(4) + c = Cube(4) pieces = c.get_all_pieces() assert len(pieces) == 56 + def test_move(): c = Cube(3) c.rotate("L") - assert c.get_piece((1,0,0)).get_piece_colors()==(None,Color.W,Color.B) - assert c.get_piece((0,0,0)).get_piece_colors()==(Color.R,Color.G,Color.W) - assert c.get_piece((0,0,2)).get_piece_colors()==(Color.R,Color.G,Color.Y) + assert c.get_piece((1, 0, 0)).get_piece_colors() == ( + None, Color.W, Color.B) + assert c.get_piece((0, 0, 0)).get_piece_colors() == ( + Color.R, Color.G, Color.W) + assert c.get_piece((0, 0, 2)).get_piece_colors() == ( + Color.R, Color.G, Color.Y) + def test_move_special_rot(): c = Cube(3) c.rotate("X'") - assert c.get_piece((2,2,2)).get_piece_colors()==(Color.O,Color.B,Color.Y) + assert c.get_piece((2, 2, 2)).get_piece_colors() == ( + Color.O, Color.B, Color.Y) c.reset() c.rotate("Y") - assert c.get_piece((2,2,2)).get_piece_colors()==(Color.B,Color.Y,Color.O) + assert c.get_piece((2, 2, 2)).get_piece_colors() == ( + Color.B, Color.Y, Color.O) c.reset() c.rotate("Z") - assert c.get_piece((2,2,2)).get_piece_colors()==(Color.Y,Color.R,Color.G) + assert c.get_piece((2, 2, 2)).get_piece_colors() == ( + Color.Y, Color.R, Color.G) + def test_move_special_mid(): c = Cube(3) c.rotate("M") - assert c.get_piece((1,2,2)).get_piece_colors()==(None,Color.B,Color.Y) + assert c.get_piece((1, 2, 2)).get_piece_colors() == ( + None, Color.B, Color.Y) c.rotate("E'") - assert c.get_piece((2,1,2)).get_piece_colors()==(Color.B,None,Color.O) + assert c.get_piece((2, 1, 2)).get_piece_colors() == ( + Color.B, None, Color.O) c.rotate("S") - assert c.get_piece((2,2,1)).get_piece_colors()==(Color.Y,Color.R,None) + assert c.get_piece((2, 2, 1)).get_piece_colors() == ( + Color.Y, Color.R, None) + def test_move_noloc(): c = Cube(3) c.rotate("L") - assert c.get_piece((1,0,0)).get_piece_colors(no_loc=True)==(Color.B,Color.W) - assert c.get_piece((0,0,0)).get_piece_colors(no_loc=True)==(Color.G,Color.R,Color.W) - assert c.get_piece((0,0,2)).get_piece_colors(no_loc=True)==(Color.G,Color.R,Color.Y) - + assert c.get_piece((1, 0, 0)).get_piece_colors( + no_loc=True) == (Color.B, Color.W) + assert c.get_piece((0, 0, 0)).get_piece_colors( + no_loc=True) == (Color.G, Color.R, Color.W) + assert c.get_piece((0, 0, 2)).get_piece_colors( + no_loc=True) == (Color.G, Color.R, Color.Y) def test_move_outcome(): c = Cube(3) c.rotate("B'") print(c) - assert c.get_piece((0,2,0)).get_piece_colors_str()=='WRB' - assert c.get_piece((0,0,0)).get_piece_colors_str()=='WOB' + assert c.get_piece((0, 2, 0)).get_piece_colors_str() == 'WRB' + assert c.get_piece((0, 0, 0)).get_piece_colors_str() == 'WOB' c = Cube(3) c.rotate("F") print(repr(c)) print(c) - assert c.get_piece((2,0,2)).get_piece_colors_str()=='YOG' - assert c.get_piece((0,0,2)).get_piece_colors_str()=='WOG' + assert c.get_piece((2, 0, 2)).get_piece_colors_str() == 'YOG' + assert c.get_piece((0, 0, 2)).get_piece_colors_str() == 'WOG' c = Cube(3) c.rotate("R") - assert c.get_piece((2,0,0)).get_piece_colors_str()=='OBY' - assert c.get_piece((2,0,2)).get_piece_colors_str()=='OBW' + assert c.get_piece((2, 0, 0)).get_piece_colors_str() == 'OBY' + assert c.get_piece((2, 0, 2)).get_piece_colors_str() == 'OBW' c = Cube(3) c.rotate("L") - assert c.get_piece((0,0,1)).get_piece_colors_str()=='RG' - assert c.get_piece((0,0,0)).get_piece_colors_str()=='RGW' - assert c.get_piece((0,0,2)).get_piece_colors_str()=='RGY' + assert c.get_piece((0, 0, 1)).get_piece_colors_str() == 'RG' + assert c.get_piece((0, 0, 0)).get_piece_colors_str() == 'RGW' + assert c.get_piece((0, 0, 2)).get_piece_colors_str() == 'RGY' c = Cube(3) c.rotate("D") - assert c.get_piece((2,0,0)).get_piece_colors_str()=='GWO',c.get_piece((2,0,0)).get_piece_colors_str() - assert c.get_piece((2,0,2)).get_piece_colors_str()=='GWR' + assert c.get_piece((2, 0, 0)).get_piece_colors_str( + ) == 'GWO', c.get_piece((2, 0, 0)).get_piece_colors_str() + assert c.get_piece((2, 0, 2)).get_piece_colors_str() == 'GWR' c = Cube(3) c.rotate("U") - assert c.get_piece((0,2,0)).get_piece_colors_str()=='GYR' - assert c.get_piece((0,2,2)).get_piece_colors_str()=='GYO' + assert c.get_piece((0, 2, 0)).get_piece_colors_str() == 'GYR' + assert c.get_piece((0, 2, 2)).get_piece_colors_str() == 'GYO' + def test_find(): c = Cube(3) c.rotate("R") print(c) - coord,_=c.find_piece("GOY") - assert coord == (2,2,0) - coord,_=c.find_piece("BRW") - assert coord == (0,0,0) + coord, _ = c.find_piece("GOY") + assert coord == (2, 2, 0) + coord, _ = c.find_piece("BRW") + assert coord == (0, 0, 0) def test_print_simple_move(): @@ -267,6 +303,7 @@ def test_print_simple_move(): print(repr(c)) print(c) + def test_wide_move(): c = Cube(3) @@ -293,35 +330,44 @@ def test_scramble_wide_move(): c.rotate(c.reverse_history()) assert c.is_done() + def test_get_piece_type(): c = Cube(3) - assert c.get_piece(coordinates=(0,0,2)).get_piece_type()==PieceType.CORNER - assert c.get_piece(coordinates=(1,0,1)).get_piece_type()==PieceType.CENTER - assert c.get_piece(coordinates=(2,1,2)).get_piece_type()==PieceType.EDGE - inner = c.get_piece(coordinates=(1,1,1)) - assert inner is None or inner.get_piece_type()==PieceType.INNER + assert c.get_piece(coordinates=(0, 0, 2) + ).get_piece_type() == PieceType.CORNER + assert c.get_piece(coordinates=(1, 0, 1) + ).get_piece_type() == PieceType.CENTER + assert c.get_piece(coordinates=(2, 1, 2) + ).get_piece_type() == PieceType.EDGE + inner = c.get_piece(coordinates=(1, 1, 1)) + assert inner is None or inner.get_piece_type() == PieceType.INNER + def test_set_cube(): c = Cube(3) c.set("YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW") assert c.is_done() + def test_set_cube_invalid(): c = Cube(3) with pytest.raises(CubeException): c.set("YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWWYYYYYYYYYYYY") + def test_set_cube_4x(): c = Cube(4) c.set("YYYYYYYYYYYYYYYYRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGOOOOOOOOOOOOOOOOBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWW") assert c.is_done() + def test_set_cube_initial_state(): c = Cube(3, state="YYYYYYGGGGGWRRRRRROOOGGWGGWYBBOOOOOORRRYBBYBBWWBWWBWWB") c.rotate("U' R'") assert c.is_done() + def test_set_cube_initial_state_4X(): c = Cube(4, state=""" YYYYYYYYYYYYGGGG @@ -335,6 +381,7 @@ def test_set_cube_initial_state_4X(): assert c.is_done() + def test_set_cube_not_done(): c = Cube(3) c.set(""" @@ -349,6 +396,7 @@ def test_set_cube_not_done(): assert c.is_done() + def test_set_cube_bad_cube(): c = Cube(3) c.set(""" @@ -363,23 +411,27 @@ def test_set_cube_bad_cube(): with pytest.raises(SolverException): solver.solve() + def test_inconsistent_cube(): c = Cube(3) - c.cube[0,0,0]=CubePiece(colors=[None,None,None]) + c.cube[0, 0, 0] = CubePiece(colors=[None, None, None]) with pytest.raises(CubeException): c.check_consistency() + def test_bad_direction(): c = Cube(3) with pytest.raises(CubeException): # pylint: disable=protected-access c._get_direction(CubeMove(None)) # type: ignore + def test_mes_move_even_cube(): c = Cube(4) with pytest.raises(CubeException): c.rotate("M") + def test_invalid_slice(): c = Cube(4) with pytest.raises(CubeException): @@ -390,16 +442,18 @@ def test_invalid_slice(): # pylint: disable=protected-access c._move_to_slice(CubeMove(CubeMoveType.L, layer=5)) + def test_rotate_twice(): c = Cube(3) c.rotate("U2") - assert c.get_face_flat(Face.F)==[ - Color.B,Color.B,Color.B, - Color.G,Color.G,Color.G, - Color.G,Color.G,Color.G, + assert c.get_face_flat(Face.F) == [ + Color.B, Color.B, Color.B, + Color.G, Color.G, Color.G, + Color.G, Color.G, Color.G, ] c.rotate("U'2") assert c.is_done() -if __name__ == "__main__" : + +if __name__ == "__main__": pytest.main() diff --git a/test/test_cube_move.py b/test/test_cube_move.py index 7810a1f..8736938 100644 --- a/test/test_cube_move.py +++ b/test/test_cube_move.py @@ -23,6 +23,7 @@ def test_create_move(): with pytest.raises(CubeException): CubeMoveType.create("A") + def test_create_move_str(): assert CubeMove.create("F") == CubeMove(CubeMoveType.F) assert CubeMove.create("B") == CubeMove(CubeMoveType.B) @@ -36,5 +37,5 @@ def test_create_move_str(): def test_move_eq(): - assert CubeMove.create("F")==CubeMove.create("F") - assert CubeMove.create("B")!=1 + assert CubeMove.create("F") == CubeMove.create("F") + assert CubeMove.create("B") != 1 diff --git a/test/test_cube_piece.py b/test/test_cube_piece.py index c4fde8f..1717d5d 100644 --- a/test/test_cube_piece.py +++ b/test/test_cube_piece.py @@ -8,25 +8,27 @@ def test_create_piece_nok(): with pytest.raises(CubeException): CubePiece() + def test_rotate(): - c = CubePiece(colors=[Color.O, Color.W,Color.B]) + c = CubePiece(colors=[Color.O, Color.W, Color.B]) c.rotate_piece(0) - assert(c.get_piece_colors()==(Color.O, Color.B,Color.W)) + assert (c.get_piece_colors() == (Color.O, Color.B, Color.W)) - c = CubePiece(colors=[Color.O, Color.W,Color.B]) + c = CubePiece(colors=[Color.O, Color.W, Color.B]) with pytest.raises(CubeException): c.rotate_piece(3) + def test_get_piece_type(): - c = CubePiece(colors=[Color.O, Color.W,Color.B]) - assert c.get_piece_type()==PieceType.CORNER + c = CubePiece(colors=[Color.O, Color.W, Color.B]) + assert c.get_piece_type() == PieceType.CORNER - c = CubePiece(colors=[Color.O, Color.W,None]) - assert c.get_piece_type()==PieceType.EDGE + c = CubePiece(colors=[Color.O, Color.W, None]) + assert c.get_piece_type() == PieceType.EDGE - c = CubePiece(colors=[Color.O,None,None]) - assert c.get_piece_type()==PieceType.CENTER + c = CubePiece(colors=[Color.O, None, None]) + assert c.get_piece_type() == PieceType.CENTER with pytest.raises(CubeException): - c = CubePiece(colors=[None,None,None]) + c = CubePiece(colors=[None, None, None]) c.get_piece_type() diff --git a/test/test_optimizer.py b/test/test_optimizer.py index 90d44ce..ff8604c 100644 --- a/test/test_optimizer.py +++ b/test/test_optimizer.py @@ -7,26 +7,29 @@ def test_optimize_rev(): moves = [CubeMove.create(m) for m in "F L L L' L' R".split(" ")] o_moves = MoveOptimizer().optimize(moves) o_moves = " ".join([str(m) for m in o_moves]) - assert o_moves=="F R" + assert o_moves == "F R" + def test_optimize_4x(): moves = [CubeMove.create(m) for m in "F L L L L R".split(" ")] o_moves = MoveOptimizer().optimize(moves) o_moves = " ".join([str(m) for m in o_moves]) - assert o_moves=="F R" + assert o_moves == "F R" + def test_optimize_3x(): moves = [CubeMove.create(m) for m in "F L L L R".split(" ")] o_moves = MoveOptimizer().optimize(moves) o_moves = " ".join([str(m) for m in o_moves]) - assert o_moves=="F L' R" + assert o_moves == "F L' R" + def test_optimize_cube_rot(): moves = [CubeMove.create(m) for m in "F Y L Z L".split(" ")] o_moves = MoveOptimizer().optimize(moves) o_moves = " ".join([str(m) for m in o_moves]) - assert o_moves=="F F D" + assert o_moves == "F F D" -if __name__ == "__main__" : +if __name__ == "__main__": pytest.main() diff --git a/test/test_solver.py b/test/test_solver.py index 2783c30..b2191bb 100644 --- a/test/test_solver.py +++ b/test/test_solver.py @@ -5,6 +5,7 @@ from magiccube.solver.basic.basic_solver import BasicSolver from magiccube.solver.basic.solver_base import SolverException + def test_solve(): cube = Cube(size=3) solver = BasicSolver(cube) @@ -15,6 +16,7 @@ def test_solve(): solver.solve() assert cube.is_done() + def test_solve_nok_size(): cube = Cube(size=2) with pytest.raises(SolverException): @@ -24,31 +26,33 @@ def test_solve_nok_size(): with pytest.raises(SolverException): BasicSolver(cube) + def test_solve_nok_max_iterations(): cube = Cube(size=3) random.seed(42) cube.scramble(num_steps=50, wide=False) solver = BasicSolver(cube) - solver.max_iterations_per_stage=2 + solver.max_iterations_per_stage = 2 with pytest.raises(SolverException): solver.solve() + def test_solve_nok_bad_cube(): - cube = Cube(size=3, state="RYYYYYYYYBRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW") + cube = Cube( + size=3, state="RYYYYYYYYBRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW") solver = BasicSolver(cube) with pytest.raises(SolverException): solver.solve() - def test_solve_white_cross(): - init_stages = ["stage_recenter_down","stage_recenter_front", - "stage_white_cross_bw","stage_recenter_front_o1", - "stage_white_cross_rw","stage_recenter_front_b1", - "stage_white_cross_gw","stage_recenter_front_r1", - "stage_white_cross_ow","stage_recenter_front_g1", - ] + init_stages = ["stage_recenter_down", "stage_recenter_front", + "stage_white_cross_bw", "stage_recenter_front_o1", + "stage_white_cross_rw", "stage_recenter_front_b1", + "stage_white_cross_gw", "stage_recenter_front_r1", + "stage_white_cross_ow", "stage_recenter_front_g1", + ] cube = Cube(hist=False, size=3) solver = BasicSolver(cube, init_stages=init_stages) @@ -59,33 +63,33 @@ def test_solve_white_cross(): solver.solve() # white cross - c,p=cube.find_piece("BW") - assert c==(1,0,0) , c - assert p.get_piece_colors_str()=="WB",p.get_piece_colors_str() + c, p = cube.find_piece("BW") + assert c == (1, 0, 0), c + assert p.get_piece_colors_str() == "WB", p.get_piece_colors_str() - c,p=cube.find_piece("GW") - assert c==(1,0,2) , c - assert p.get_piece_colors_str()=="WG",p.get_piece_colors_str() + c, p = cube.find_piece("GW") + assert c == (1, 0, 2), c + assert p.get_piece_colors_str() == "WG", p.get_piece_colors_str() - c,p=cube.find_piece("RW") - assert c==(0,0,1) , c - assert p.get_piece_colors_str()=="RW",p.get_piece_colors_str() - c,p=cube.find_piece("OW") - assert c==(2,0,1) , c - assert p.get_piece_colors_str()=="OW",p.get_piece_colors_str() + c, p = cube.find_piece("RW") + assert c == (0, 0, 1), c + assert p.get_piece_colors_str() == "RW", p.get_piece_colors_str() + c, p = cube.find_piece("OW") + assert c == (2, 0, 1), c + assert p.get_piece_colors_str() == "OW", p.get_piece_colors_str() def test_solve_white_corners(): - init_stages = ["stage_recenter_down","stage_recenter_front", -"stage_white_cross_bw","stage_recenter_front_o1", -"stage_white_cross_rw","stage_recenter_front_b1", -"stage_white_cross_gw","stage_recenter_front_r1", -"stage_white_cross_ow","stage_recenter_front_g1", -"stage_white_corner_gow","stage_recenter_front_o2", -"stage_white_corner_bow","stage_recenter_front_b2", -"stage_white_corner_brw","stage_recenter_front_r2", -"stage_white_corner_grw","stage_recenter_front_g2", - ] + init_stages = ["stage_recenter_down", "stage_recenter_front", + "stage_white_cross_bw", "stage_recenter_front_o1", + "stage_white_cross_rw", "stage_recenter_front_b1", + "stage_white_cross_gw", "stage_recenter_front_r1", + "stage_white_cross_ow", "stage_recenter_front_g1", + "stage_white_corner_gow", "stage_recenter_front_o2", + "stage_white_corner_bow", "stage_recenter_front_b2", + "stage_white_corner_brw", "stage_recenter_front_r2", + "stage_white_corner_grw", "stage_recenter_front_g2", + ] cube = Cube(hist=False, size=3) solver = BasicSolver(cube, init_stages=init_stages) @@ -96,55 +100,52 @@ def test_solve_white_corners(): solver.solve() # white cross - c,p=cube.find_piece("BW") - assert c==(1,0,0) , c - assert p.get_piece_colors_str()=="WB",p.get_piece_colors_str() + c, p = cube.find_piece("BW") + assert c == (1, 0, 0), c + assert p.get_piece_colors_str() == "WB", p.get_piece_colors_str() - c,p=cube.find_piece("GW") - assert c==(1,0,2) , c - assert p.get_piece_colors_str()=="WG",p.get_piece_colors_str() + c, p = cube.find_piece("GW") + assert c == (1, 0, 2), c + assert p.get_piece_colors_str() == "WG", p.get_piece_colors_str() - c,p=cube.find_piece("RW") - assert c==(0,0,1) , c - assert p.get_piece_colors_str()=="RW",p.get_piece_colors_str() - c,p=cube.find_piece("OW") - assert c==(2,0,1) , c - assert p.get_piece_colors_str()=="OW",p.get_piece_colors_str() + c, p = cube.find_piece("RW") + assert c == (0, 0, 1), c + assert p.get_piece_colors_str() == "RW", p.get_piece_colors_str() + c, p = cube.find_piece("OW") + assert c == (2, 0, 1), c + assert p.get_piece_colors_str() == "OW", p.get_piece_colors_str() # white corners - c,p=cube.find_piece("GOW") - assert c==(2,0,2) , c - assert p.get_piece_colors_str()=="OWG",p.get_piece_colors_str() - c,p=cube.find_piece("BOW") - assert c==(2,0,0) , c - assert p.get_piece_colors_str()=="OWB",p.get_piece_colors_str() - c,p=cube.find_piece("BRW") - assert c==(0,0,0) , c - assert p.get_piece_colors_str()=="RWB",p.get_piece_colors_str() - c,p=cube.find_piece("GRW") - assert c==(0,0,2) , c - assert p.get_piece_colors_str()=="RWG",p.get_piece_colors_str() - - - + c, p = cube.find_piece("GOW") + assert c == (2, 0, 2), c + assert p.get_piece_colors_str() == "OWG", p.get_piece_colors_str() + c, p = cube.find_piece("BOW") + assert c == (2, 0, 0), c + assert p.get_piece_colors_str() == "OWB", p.get_piece_colors_str() + c, p = cube.find_piece("BRW") + assert c == (0, 0, 0), c + assert p.get_piece_colors_str() == "RWB", p.get_piece_colors_str() + c, p = cube.find_piece("GRW") + assert c == (0, 0, 2), c + assert p.get_piece_colors_str() == "RWG", p.get_piece_colors_str() def test_solve_2nd_layer(): - init_stages = ["stage_recenter_down","stage_recenter_front", -"stage_white_cross_bw","stage_recenter_front_o1", -"stage_white_cross_rw","stage_recenter_front_b1", -"stage_white_cross_gw","stage_recenter_front_r1", -"stage_white_cross_ow","stage_recenter_front_g1", -"stage_white_corner_gow","stage_recenter_front_o2", -"stage_white_corner_bow","stage_recenter_front_b2", -"stage_white_corner_brw","stage_recenter_front_r2", -"stage_white_corner_grw","stage_recenter_front_g2", -"stage_2nd_layer_gr","stage_recenter_front_o3", -"stage_2nd_layer_go","stage_recenter_front_b3", -"stage_2nd_layer_bo","stage_recenter_front_r3", -"stage_2nd_layer_br","stage_recenter_front_g3", - ] + init_stages = ["stage_recenter_down", "stage_recenter_front", + "stage_white_cross_bw", "stage_recenter_front_o1", + "stage_white_cross_rw", "stage_recenter_front_b1", + "stage_white_cross_gw", "stage_recenter_front_r1", + "stage_white_cross_ow", "stage_recenter_front_g1", + "stage_white_corner_gow", "stage_recenter_front_o2", + "stage_white_corner_bow", "stage_recenter_front_b2", + "stage_white_corner_brw", "stage_recenter_front_r2", + "stage_white_corner_grw", "stage_recenter_front_g2", + "stage_2nd_layer_gr", "stage_recenter_front_o3", + "stage_2nd_layer_go", "stage_recenter_front_b3", + "stage_2nd_layer_bo", "stage_recenter_front_r3", + "stage_2nd_layer_br", "stage_recenter_front_g3", + ] cube = Cube(hist=False, size=3) solver = BasicSolver(cube, init_stages=init_stages) @@ -155,71 +156,71 @@ def test_solve_2nd_layer(): solver.solve() # white cross - c,p=cube.find_piece("BW") - assert c==(1,0,0) , c - assert p.get_piece_colors_str()=="WB",p.get_piece_colors_str() + c, p = cube.find_piece("BW") + assert c == (1, 0, 0), c + assert p.get_piece_colors_str() == "WB", p.get_piece_colors_str() - c,p=cube.find_piece("GW") - assert c==(1,0,2) , c - assert p.get_piece_colors_str()=="WG",p.get_piece_colors_str() + c, p = cube.find_piece("GW") + assert c == (1, 0, 2), c + assert p.get_piece_colors_str() == "WG", p.get_piece_colors_str() - c,p=cube.find_piece("RW") - assert c==(0,0,1) , c - assert p.get_piece_colors_str()=="RW",p.get_piece_colors_str() - c,p=cube.find_piece("OW") - assert c==(2,0,1) , c - assert p.get_piece_colors_str()=="OW",p.get_piece_colors_str() + c, p = cube.find_piece("RW") + assert c == (0, 0, 1), c + assert p.get_piece_colors_str() == "RW", p.get_piece_colors_str() + c, p = cube.find_piece("OW") + assert c == (2, 0, 1), c + assert p.get_piece_colors_str() == "OW", p.get_piece_colors_str() # white corners - c,p=cube.find_piece("GOW") - assert c==(2,0,2) , c - assert p.get_piece_colors_str()=="OWG",p.get_piece_colors_str() - c,p=cube.find_piece("BOW") - assert c==(2,0,0) , c - assert p.get_piece_colors_str()=="OWB",p.get_piece_colors_str() - c,p=cube.find_piece("BRW") - assert c==(0,0,0) , c - assert p.get_piece_colors_str()=="RWB",p.get_piece_colors_str() - c,p=cube.find_piece("GRW") - assert c==(0,0,2) , c - assert p.get_piece_colors_str()=="RWG",p.get_piece_colors_str() - + c, p = cube.find_piece("GOW") + assert c == (2, 0, 2), c + assert p.get_piece_colors_str() == "OWG", p.get_piece_colors_str() + c, p = cube.find_piece("BOW") + assert c == (2, 0, 0), c + assert p.get_piece_colors_str() == "OWB", p.get_piece_colors_str() + c, p = cube.find_piece("BRW") + assert c == (0, 0, 0), c + assert p.get_piece_colors_str() == "RWB", p.get_piece_colors_str() + c, p = cube.find_piece("GRW") + assert c == (0, 0, 2), c + assert p.get_piece_colors_str() == "RWG", p.get_piece_colors_str() # 2nd layer - c,p=cube.find_piece("BO") - assert c==(2,1,0) , c - assert p.get_piece_colors_str()=="OB",p.get_piece_colors_str() + c, p = cube.find_piece("BO") + assert c == (2, 1, 0), c + assert p.get_piece_colors_str() == "OB", p.get_piece_colors_str() + + c, p = cube.find_piece("GO") + assert c == (2, 1, 2), c + assert p.get_piece_colors_str() == "OG", p.get_piece_colors_str() - c,p=cube.find_piece("GO") - assert c==(2,1,2) , c - assert p.get_piece_colors_str()=="OG",p.get_piece_colors_str() + c, p = cube.find_piece("GR") + assert c == (0, 1, 2), c + assert p.get_piece_colors_str() == "RG", p.get_piece_colors_str() - c,p=cube.find_piece("GR") - assert c==(0,1,2) , c - assert p.get_piece_colors_str()=="RG",p.get_piece_colors_str() + c, p = cube.find_piece("BR") + assert c == (0, 1, 0), c + assert p.get_piece_colors_str() == "RB", p.get_piece_colors_str() - c,p=cube.find_piece("BR") - assert c==(0,1,0) , c - assert p.get_piece_colors_str()=="RB",p.get_piece_colors_str() def test_solve_top_cross(): # pylint: disable=too-many-statements - init_stages = ["stage_recenter_down","stage_recenter_front", -"stage_white_cross_bw","stage_recenter_front_o1", -"stage_white_cross_rw","stage_recenter_front_b1", -"stage_white_cross_gw","stage_recenter_front_r1", -"stage_white_cross_ow","stage_recenter_front_g1", -"stage_white_corner_gow","stage_recenter_front_o2", -"stage_white_corner_bow","stage_recenter_front_b2", -"stage_white_corner_brw","stage_recenter_front_r2", -"stage_white_corner_grw","stage_recenter_front_g2", -"stage_2nd_layer_gr","stage_recenter_front_o3", -"stage_2nd_layer_go","stage_recenter_front_b3", -"stage_2nd_layer_bo","stage_recenter_front_r3", -"stage_2nd_layer_br","stage_recenter_front_g3", -"stage_top_cross","stage_order_top_cross", - ] + init_stages = ["stage_recenter_down", "stage_recenter_front", + "stage_white_cross_bw", "stage_recenter_front_o1", + "stage_white_cross_rw", "stage_recenter_front_b1", + "stage_white_cross_gw", "stage_recenter_front_r1", + "stage_white_cross_ow", "stage_recenter_front_g1", + "stage_white_corner_gow", "stage_recenter_front_o2", + "stage_white_corner_bow", "stage_recenter_front_b2", + "stage_white_corner_brw", "stage_recenter_front_r2", + "stage_white_corner_grw", "stage_recenter_front_g2", + "stage_2nd_layer_gr", "stage_recenter_front_o3", + "stage_2nd_layer_go", "stage_recenter_front_b3", + "stage_2nd_layer_bo", "stage_recenter_front_r3", + "stage_2nd_layer_br", "stage_recenter_front_g3", + "stage_top_cross", "stage_order_top_cross", + ] cube = Cube(hist=False, size=3) solver = BasicSolver(cube, init_stages=init_stages) @@ -230,86 +231,86 @@ def test_solve_top_cross(): solver.solve() # white cross - c,p=cube.find_piece("BW") - assert c==(1,0,0) , c - assert p.get_piece_colors_str()=="WB",p.get_piece_colors_str() + c, p = cube.find_piece("BW") + assert c == (1, 0, 0), c + assert p.get_piece_colors_str() == "WB", p.get_piece_colors_str() - c,p=cube.find_piece("GW") - assert c==(1,0,2) , c - assert p.get_piece_colors_str()=="WG",p.get_piece_colors_str() + c, p = cube.find_piece("GW") + assert c == (1, 0, 2), c + assert p.get_piece_colors_str() == "WG", p.get_piece_colors_str() - c,p=cube.find_piece("RW") - assert c==(0,0,1) , c - assert p.get_piece_colors_str()=="RW",p.get_piece_colors_str() - c,p=cube.find_piece("OW") - assert c==(2,0,1) , c - assert p.get_piece_colors_str()=="OW",p.get_piece_colors_str() + c, p = cube.find_piece("RW") + assert c == (0, 0, 1), c + assert p.get_piece_colors_str() == "RW", p.get_piece_colors_str() + c, p = cube.find_piece("OW") + assert c == (2, 0, 1), c + assert p.get_piece_colors_str() == "OW", p.get_piece_colors_str() # white corners - c,p=cube.find_piece("GOW") - assert c==(2,0,2) , c - assert p.get_piece_colors_str()=="OWG",p.get_piece_colors_str() - c,p=cube.find_piece("BOW") - assert c==(2,0,0) , c - assert p.get_piece_colors_str()=="OWB",p.get_piece_colors_str() - c,p=cube.find_piece("BRW") - assert c==(0,0,0) , c - assert p.get_piece_colors_str()=="RWB",p.get_piece_colors_str() - c,p=cube.find_piece("GRW") - assert c==(0,0,2) , c - assert p.get_piece_colors_str()=="RWG",p.get_piece_colors_str() - + c, p = cube.find_piece("GOW") + assert c == (2, 0, 2), c + assert p.get_piece_colors_str() == "OWG", p.get_piece_colors_str() + c, p = cube.find_piece("BOW") + assert c == (2, 0, 0), c + assert p.get_piece_colors_str() == "OWB", p.get_piece_colors_str() + c, p = cube.find_piece("BRW") + assert c == (0, 0, 0), c + assert p.get_piece_colors_str() == "RWB", p.get_piece_colors_str() + c, p = cube.find_piece("GRW") + assert c == (0, 0, 2), c + assert p.get_piece_colors_str() == "RWG", p.get_piece_colors_str() # 2nd layer - c,p=cube.find_piece("BO") - assert c==(2,1,0) , c - assert p.get_piece_colors_str()=="OB",p.get_piece_colors_str() + c, p = cube.find_piece("BO") + assert c == (2, 1, 0), c + assert p.get_piece_colors_str() == "OB", p.get_piece_colors_str() - c,p=cube.find_piece("GO") - assert c==(2,1,2) , c - assert p.get_piece_colors_str()=="OG",p.get_piece_colors_str() + c, p = cube.find_piece("GO") + assert c == (2, 1, 2), c + assert p.get_piece_colors_str() == "OG", p.get_piece_colors_str() - c,p=cube.find_piece("GR") - assert c==(0,1,2) , c - assert p.get_piece_colors_str()=="RG",p.get_piece_colors_str() + c, p = cube.find_piece("GR") + assert c == (0, 1, 2), c + assert p.get_piece_colors_str() == "RG", p.get_piece_colors_str() - c,p=cube.find_piece("BR") - assert c==(0,1,0) , c - assert p.get_piece_colors_str()=="RB",p.get_piece_colors_str() + c, p = cube.find_piece("BR") + assert c == (0, 1, 0), c + assert p.get_piece_colors_str() == "RB", p.get_piece_colors_str() # TOP cross - p=cube.get_piece((1,2,2)) - assert p.get_piece_colors()==(None,Color.Y,Color.G),p.get_piece_colors_str() + p = cube.get_piece((1, 2, 2)) + assert p.get_piece_colors() == (None, Color.Y, Color.G), p.get_piece_colors_str() + + p = cube.get_piece((2, 2, 1)) + assert p.get_piece_colors() == (Color.O, Color.Y, None), p.get_piece_colors_str() - p=cube.get_piece((2,2,1)) - assert p.get_piece_colors()==(Color.O,Color.Y,None),p.get_piece_colors_str() + p = cube.get_piece((1, 2, 0)) + assert p.get_piece_colors() == (None, Color.Y, Color.B), p.get_piece_colors_str() - p=cube.get_piece((1,2,0)) - assert p.get_piece_colors()==(None,Color.Y,Color.B),p.get_piece_colors_str() + p = cube.get_piece((0, 2, 1)) + assert p.get_piece_colors() == (Color.R, Color.Y, None), p.get_piece_colors_str() - p=cube.get_piece((0,2,1)) - assert p.get_piece_colors()==(Color.R,Color.Y,None),p.get_piece_colors_str() def test_solve_top_corners(): # pylint: disable=too-many-statements - init_stages = ["stage_recenter_down","stage_recenter_front", -"stage_white_cross_bw","stage_recenter_front_o1", -"stage_white_cross_rw","stage_recenter_front_b1", -"stage_white_cross_gw","stage_recenter_front_r1", -"stage_white_cross_ow","stage_recenter_front_g1", -"stage_white_corner_gow","stage_recenter_front_o2", -"stage_white_corner_bow","stage_recenter_front_b2", -"stage_white_corner_brw","stage_recenter_front_r2", -"stage_white_corner_grw","stage_recenter_front_g2", -"stage_2nd_layer_gr","stage_recenter_front_o3", -"stage_2nd_layer_go","stage_recenter_front_b3", -"stage_2nd_layer_bo","stage_recenter_front_r3", -"stage_2nd_layer_br","stage_recenter_front_g3", -"stage_top_cross", -"stage_order_top_cross", -"stage_order_top_corners", -"stage_turn_top_corners", - ] + init_stages = ["stage_recenter_down", "stage_recenter_front", + "stage_white_cross_bw", "stage_recenter_front_o1", + "stage_white_cross_rw", "stage_recenter_front_b1", + "stage_white_cross_gw", "stage_recenter_front_r1", + "stage_white_cross_ow", "stage_recenter_front_g1", + "stage_white_corner_gow", "stage_recenter_front_o2", + "stage_white_corner_bow", "stage_recenter_front_b2", + "stage_white_corner_brw", "stage_recenter_front_r2", + "stage_white_corner_grw", "stage_recenter_front_g2", + "stage_2nd_layer_gr", "stage_recenter_front_o3", + "stage_2nd_layer_go", "stage_recenter_front_b3", + "stage_2nd_layer_bo", "stage_recenter_front_r3", + "stage_2nd_layer_br", "stage_recenter_front_g3", + "stage_top_cross", + "stage_order_top_cross", + "stage_order_top_corners", + "stage_turn_top_corners", + ] cube = Cube(hist=False, size=3) solver = BasicSolver(cube, init_stages=init_stages) @@ -321,89 +322,89 @@ def test_solve_top_corners(): assert cube.is_done() # white cross - c,p=cube.find_piece("BW") - assert c==(1,0,0) , c - assert p.get_piece_colors_str()=="WB",p.get_piece_colors_str() + c, p = cube.find_piece("BW") + assert c == (1, 0, 0), c + assert p.get_piece_colors_str() == "WB", p.get_piece_colors_str() - c,p=cube.find_piece("GW") - assert c==(1,0,2) , c - assert p.get_piece_colors_str()=="WG",p.get_piece_colors_str() + c, p = cube.find_piece("GW") + assert c == (1, 0, 2), c + assert p.get_piece_colors_str() == "WG", p.get_piece_colors_str() - c,p=cube.find_piece("RW") - assert c==(0,0,1) , c - assert p.get_piece_colors_str()=="RW",p.get_piece_colors_str() - c,p=cube.find_piece("OW") - assert c==(2,0,1) , c - assert p.get_piece_colors_str()=="OW",p.get_piece_colors_str() + c, p = cube.find_piece("RW") + assert c == (0, 0, 1), c + assert p.get_piece_colors_str() == "RW", p.get_piece_colors_str() + c, p = cube.find_piece("OW") + assert c == (2, 0, 1), c + assert p.get_piece_colors_str() == "OW", p.get_piece_colors_str() # white corners - c,p=cube.find_piece("GOW") - assert c==(2,0,2) , c - assert p.get_piece_colors_str()=="OWG",p.get_piece_colors_str() - c,p=cube.find_piece("BOW") - assert c==(2,0,0) , c - assert p.get_piece_colors_str()=="OWB",p.get_piece_colors_str() - c,p=cube.find_piece("BRW") - assert c==(0,0,0) , c - assert p.get_piece_colors_str()=="RWB",p.get_piece_colors_str() - c,p=cube.find_piece("GRW") - assert c==(0,0,2) , c - assert p.get_piece_colors_str()=="RWG",p.get_piece_colors_str() - + c, p = cube.find_piece("GOW") + assert c == (2, 0, 2), c + assert p.get_piece_colors_str() == "OWG", p.get_piece_colors_str() + c, p = cube.find_piece("BOW") + assert c == (2, 0, 0), c + assert p.get_piece_colors_str() == "OWB", p.get_piece_colors_str() + c, p = cube.find_piece("BRW") + assert c == (0, 0, 0), c + assert p.get_piece_colors_str() == "RWB", p.get_piece_colors_str() + c, p = cube.find_piece("GRW") + assert c == (0, 0, 2), c + assert p.get_piece_colors_str() == "RWG", p.get_piece_colors_str() # 2nd layer - c,p=cube.find_piece("BO") - assert c==(2,1,0) , c - assert p.get_piece_colors_str()=="OB",p.get_piece_colors_str() + c, p = cube.find_piece("BO") + assert c == (2, 1, 0), c + assert p.get_piece_colors_str() == "OB", p.get_piece_colors_str() - c,p=cube.find_piece("GO") - assert c==(2,1,2) , c - assert p.get_piece_colors_str()=="OG",p.get_piece_colors_str() + c, p = cube.find_piece("GO") + assert c == (2, 1, 2), c + assert p.get_piece_colors_str() == "OG", p.get_piece_colors_str() - c,p=cube.find_piece("GR") - assert c==(0,1,2) , c - assert p.get_piece_colors_str()=="RG",p.get_piece_colors_str() + c, p = cube.find_piece("GR") + assert c == (0, 1, 2), c + assert p.get_piece_colors_str() == "RG", p.get_piece_colors_str() - c,p=cube.find_piece("BR") - assert c==(0,1,0) , c - assert p.get_piece_colors_str()=="RB",p.get_piece_colors_str() + c, p = cube.find_piece("BR") + assert c == (0, 1, 0), c + assert p.get_piece_colors_str() == "RB", p.get_piece_colors_str() # TOP cross - p=cube.get_piece((1,2,2)) - assert p.get_piece_colors()==(None,Color.Y,Color.G),p.get_piece_colors_str() + p = cube.get_piece((1, 2, 2)) + assert p.get_piece_colors() == (None, Color.Y, Color.G), p.get_piece_colors_str() - p=cube.get_piece((2,2,1)) - assert p.get_piece_colors()==(Color.O,Color.Y,None),p.get_piece_colors_str() + p = cube.get_piece((2, 2, 1)) + assert p.get_piece_colors() == (Color.O, Color.Y, None), p.get_piece_colors_str() - p=cube.get_piece((1,2,0)) - assert p.get_piece_colors()==(None,Color.Y,Color.B),p.get_piece_colors_str() + p = cube.get_piece((1, 2, 0)) + assert p.get_piece_colors() == (None, Color.Y, Color.B), p.get_piece_colors_str() - p=cube.get_piece((0,2,1)) - assert p.get_piece_colors()==(Color.R,Color.Y,None),p.get_piece_colors_str() + p = cube.get_piece((0, 2, 1)) + assert p.get_piece_colors() == (Color.R, Color.Y, None), p.get_piece_colors_str() # TOP corners - c,p=cube.find_piece("RYB") - assert c==(0,2,0) , c - assert p.get_piece_colors_str(no_loc=True)=="BRY",p.get_piece_colors_str() - - c,p=cube.find_piece("OYB") - assert c==(2,2,0) , c - assert p.get_piece_colors_str(no_loc=True)=="BOY",p.get_piece_colors_str() - - c,p=cube.find_piece("OYG") - assert c==(2,2,2) , c - assert p.get_piece_colors_str(no_loc=True)=="GOY",p.get_piece_colors_str() - - c,p=cube.find_piece("RYG") - assert c==(0,2,2) , c - assert p.get_piece_colors_str(no_loc=True)=="GRY",p.get_piece_colors_str() + c, p = cube.find_piece("RYB") + assert c == (0, 2, 0), c + assert p.get_piece_colors_str( + no_loc=True) == "BRY", p.get_piece_colors_str() + c, p = cube.find_piece("OYB") + assert c == (2, 2, 0), c + assert p.get_piece_colors_str( + no_loc=True) == "BOY", p.get_piece_colors_str() + c, p = cube.find_piece("OYG") + assert c == (2, 2, 2), c + assert p.get_piece_colors_str( + no_loc=True) == "GOY", p.get_piece_colors_str() + c, p = cube.find_piece("RYG") + assert c == (0, 2, 2), c + assert p.get_piece_colors_str( + no_loc=True) == "GRY", p.get_piece_colors_str() -if __name__ == "__main__" : +if __name__ == "__main__": pytest.main() diff --git a/test/test_solver_efficiency.py b/test/test_solver_efficiency.py index f846105..0d18066 100644 --- a/test/test_solver_efficiency.py +++ b/test/test_solver_efficiency.py @@ -2,12 +2,13 @@ from magiccube.cube import Cube from magiccube.solver.basic.basic_solver import BasicSolver + def perf_test_cube(): random.seed(42) cube = Cube(hist=False, size=3) solver = BasicSolver(cube) - action_count_list=[] + action_count_list = [] for _ in range(1000): # Reset & Scramble the cube @@ -23,5 +24,5 @@ def perf_test_cube(): print("Min actions", min(action_count_list)) -if __name__ == "__main__" : +if __name__ == "__main__": perf_test_cube()