Skip to content

Library that implements a representation of a Rubik's Cube. The purpose of this implementation is to use it for research purposes.

License

Notifications You must be signed in to change notification settings

framunoz/Rubiks-Cube

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rubiks-Cube

Library that implements a representation of a Rubik's Cube. The purpose of this implementation is to use it for research purposes.

How to use it?

The easiest way to create a Rubik's Cube is with the RubikCube class. Here is an example:

from rubiks_cube.cube import RubikCube
rc = RubikCube.from_dims((3, 2, 1))
print(rc)

Noting that a RubikCube instance is a hashable and immutable object (with the current methods).

Representation of a Rubik's Cube of 3x2x1.

Making move on the Rubik's Cube

If you want to make a move on the Rubik's Cube, you can do it like the example:

from rubiks_cube.cube import RubikCube
from rubiks_cube.movements import CubeMove

rc = RubikCube.from_dims((3, 2, 1))
rc = rc.make_movements(CubeMove.L2)
print(rc)

img.png

You can make a series of movements with a list of CubeMove:

from rubiks_cube.cube import RubikCube
from rubiks_cube.movements import CubeMove

rc = RubikCube.from_dims((3, 2, 1))
rc = rc.make_movements([CubeMove.L2, CubeMove.U2])
print(rc)

img.png

Or with a string with the representation of CubeMove:

from rubiks_cube.cube import RubikCube

rc = RubikCube.from_dims((3, 2, 1))
rc = rc.make_movements("L2 U2")
print(rc)

img.png

Making the Graph

Given a set of permitted movements (where the permitted movements are operations over the group of Rubik's Cube), for example, . We expect to create a graph where and The described graph can be computed with the following instructions:

from matplotlib import pyplot as plt

from rubiks_cube.graph import make_graph
from rubiks_cube.movements import CubeMove as CM
from rubiks_cube.plotters import GraphPlotter

g = make_graph(
    dims=(3, 2, 1),
    permitted_movements={CM.R2, CM.D2, CM.U2}
)
gp = GraphPlotter(g)
gp.compute_kamada_kawai_layout()
gp.find_bipartite()
gp.draw()
plt.show()

And it plots the following graph: A graph

About

Library that implements a representation of a Rubik's Cube. The purpose of this implementation is to use it for research purposes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages