rubix_cube.cube_game module¶
Rubix Cube_Game
class Module
Module Description¶
Collection of methods that define the main Rubix Cube Game
class and how it manipulates a Cube
object, prints to console, logs a history of both moves and re-orientations,
scrambles the state of the cube, times game-play, and performs file-system
loading and saving of games.
Module Contents¶
Cube_Game
details code for manipulatingRubix Cube(s)
.Todo
Implement file I/O operations (loading and saving games).
Implement scramble cube functions.
Implement color changing functions.
Implement game clock functions.
-
class
rubix_cube.cube_game.
Cube_Game
(cube: rubix_cube.cube.Cube = None, player_name: str = None, game_name: str = None, game_log: Dict = None, scramble: bool = False, verbose: bool = False)[source]¶ Bases:
object
Class in charge of directly interacting with and logging changes to an instance of the
Cube
class.-
__game_log
¶ Historical record of all moves, rotations, and other game events that manipulate the
game_cube
.- Type
-
CUBE_FUNCS
= {'B': <function Cube.move_back>, 'Bi': <function Cube.move_back_inverse>, 'D': <function Cube.move_down>, 'Di': <function Cube.move_down_inverse>, 'E': <function Cube.move_equator>, 'Ei': <function Cube.move_equator_inverse>, 'F': <function Cube.move_front>, 'Fi': <function Cube.move_front_inverse>, 'L': <function Cube.move_left>, 'Li': <function Cube.move_left_inverse>, 'M': <function Cube.move_middle>, 'Mi': <function Cube.move_middle_inverse>, 'R': <function Cube.move_right>, 'Ri': <function Cube.move_right_inverse>, 'S': <function Cube.move_standing>, 'Si': <function Cube.move_standing_inverse>, 'U': <function Cube.move_up>, 'Ui': <function Cube.move_up_inverse>, 'X': <function Cube.rotate_pitch>, 'Xi': <function Cube.rotate_pitch_inverse>, 'Y': <function Cube.rotate_yaw>, 'Yi': <function Cube.rotate_yaw_inverse>, 'Z': <function Cube.rotate_roll>, 'Zi': <function Cube.rotate_roll_inverse>}¶
-
EVENT_TYPES
= ['<<__NEW_GAME__>>', 'F', 'Fi', 'B', 'Bi', 'L', 'Li', 'R', 'Ri', 'U', 'Ui', 'D', 'Di', 'M', 'Mi', 'E', 'Ei', 'S', 'Si', 'X', 'Xi', 'Y', 'Yi', 'Z', 'Zi', '<<__START_SCRAMBLE__>>', '<<__END_SCRAMBLE__>>', '<<__COLOR_CHANGE__>>', '<<__SAVE_GAME__>>', '<<__LOAD_GAME__>>', '<<__PAUSE_GAME__>>', '<<__RESUME_GAME__>>', '<<__SOLVE_CUBE__>>', '<<__CUBE_SOLVED__>>', '<<__QUIT_GAME__>>']
-
INVERSE_FUNCS
= {'B': 'Bi', 'Bi': 'B', 'D': 'Di', 'Di': 'D', 'E': 'Ei', 'Ei': 'E', 'F': 'Fi', 'Fi': 'F', 'L': 'Li', 'Li': 'L', 'M': 'Mi', 'Mi': 'M', 'R': 'Ri', 'Ri': 'R', 'S': 'Si', 'Si': 'S', 'U': 'Ui', 'Ui': 'U', 'X': 'Xi', 'Xi': 'X', 'Y': 'Yi', 'Yi': 'Y', 'Z': 'Zi', 'Zi': 'Z'}¶
-
__init__
(cube: rubix_cube.cube.Cube = None, player_name: str = None, game_name: str = None, game_log: Dict = None, scramble: bool = False, verbose: bool = False)[source]¶ Cube_Game
class constructor- Parameters
cube (Cube, optional) –
Cube
that will be directly manipulated throughout gameplay.player_name (str, optional) – Name of current actor playing with
Cube
.game_name (str, optional) – Name of the current game being played.
game_log (Dict, optional) – Dictionary that contains a history of moves and other game events.
scramble (bool, optional) – Whether or not the game should scramble the
__game_cube
upon initialization. Default value isFalse
.verbose (bool, optional) – [DEBUG]-style console output. Default value is
False
.
-
compute_inverse_log_sequence
() → List[str][source]¶ Computes the inverse sequence of moves from the
game_log
thatSHOULD
lead to theRubix Cube
being solved!- Returns
sequence - A list of cube manipulation function str(s) for use with
manipulate_cube()
function.- Return type
List[str]
-
property
game_cube
¶ Rubix Cube
object being manipulated in game.
-
property
game_log
¶ JSON-style
dict
recording all actions done to thegame_cube
stored under theevents
key which is a list of :class`dict` objects each of which has atype
key with a value found inEVENT_TYPES
.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
EVENT_TYPES = ['<<__NEW_GAME__>>', 'F', 'Fi', 'B', 'Bi', 'L', 'Li', 'R', 'Ri', 'U', 'Ui', 'D', 'Di', 'M', 'Mi', 'E', 'Ei', 'S', 'Si', 'X', 'Xi', 'Y', 'Yi', 'Z', 'Zi', '<<__START_SCRAMBLE__>>', '<<__END_SCRAMBLE__>>', '<<__COLOR_CHANGE__>>', '<<__SAVE_GAME__>>', '<<__LOAD_GAME__>>', '<<__PAUSE_GAME__>>', '<<__RESUME_GAME__>>', '<<__SOLVE_CUBE__>>', '<<__QUIT_GAME__>>']
1 2 3 4 5
game_log = {'events' : [{'type' : '<<__NEW_GAME__>>', 'name' : '...'}, {'type' : ...}, ..., {'type' : ...}]}
-
property
game_name
¶ Name of the Game
-
get_scramble_sequence
(cube_funcs: List[str] = None) → List[str][source]¶ Compiles a sequence of moves for scrambling the
game_cube
attribute for applying a sequence ofn_steps
semi-randomly selected cube manipulations using a defined a provided sub-set of cube functionscube_funcs
.- Parameters
n_steps (int, optional) –
The number of
Rubix Cube
manipulations to be applied to thegame_cube
.Note
Valid range of values, 0 <
n_steps
<= 500. Won’t call anyCube
function(s) if not in range.cube_funcs (List[str], optional) – Sub-list of
CUBE_FUNCS
that defines the options for manipulating the cube. Default value isNone
which allows all functions inCUBE_FUNCS
to be selected.
- Returns
sequence - A list of cube manipulation function str(s) for use with
manipulate_cube()
function.- Return type
List[str]
Note
Won’t perform the following sequences:
<<ACTION>>
,<<ACTION_INVERSE>>
<<ACTION>>
,<<ACTION>>
,<<ACTION>>
,<<ACTION>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
INVERSE_FUNCS = {'U' : 'Ui', 'Ui' : 'U', 'D' : 'Di', 'Di' : 'D', 'L' : 'Li', 'Li' : 'L', 'R' : 'Ri', 'Ri' : 'R', 'F' : 'Fi', 'Fi' : 'F', 'B' : 'Bi', 'Bi' : 'B', 'M' : 'Mi', 'Mi' : 'M', 'E' : 'Ei', 'Ei' : 'E', 'S' : 'Si', 'Si' : 'S', 'X' : 'Xi', 'Xi' : 'X', 'Y' : 'Yi', 'Yi' : 'Y', 'Z' : 'Zi', 'Zi' : 'Z'}
-
manipulate_cube
(cube_func: str)[source]¶ Function that interfaces the
Cube_Game
class with theCube
class to turn the layers or rotate the orientation.- Parameters
cube_func (str) – Look-up key to recover the proper
Cube
method to call fromCUBE_FUNCS
class attribute to call a move using thegame_cube
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
CUBE_FUNCS = {'U' : Cube.move_up, 'Ui' : Cube.move_up_inverse, 'D' : Cube.move_down, 'Di' : Cube.move_down_inverse, 'L' : Cube.move_left, 'Li' : Cube.move_left_inverse, 'R' : Cube.move_right, 'Ri' : Cube.move_right_inverse, 'F' : Cube.move_front, 'Fi' : Cube.move_front_inverse, 'B' : Cube.move_back, 'Bi' : Cube.move_back_inverse, 'M' : Cube.move_middle, 'Mi' : Cube.move_middle_inverse, 'E' : Cube.move_equator, 'Ei' : Cube.move_equator_inverse, 'S' : Cube.move_standing, 'Si' : Cube.move_standing_inverse, 'X' : Cube.rotate_pitch, 'Xi' : Cube.rotate_pitch_inverse, 'Y' : Cube.rotate_yaw, 'Yi' : Cube.rotate_yaw_inverse, 'Z' : Cube.rotate_roll, 'Zi' : Cube.rotate_roll_inverse}
-
property
player_name
¶ Name of actor playing game.
-
property
verbose
¶ [DEBUG]-style console output. Default value is
False
.
-