PyCuber icon indicating copy to clipboard operation
PyCuber copied to clipboard

Array representation of cube?

Open PAK90 opened this issue 8 years ago • 2 comments

I have need of an array representation of the cube, either as a flat array or an array of six arrays for each face. I haven't found anything existing to do this, so I've come up with my own hacky method, but this feels like something that should be part of the Cube class. Here's what I did:

def cubeAsArray(cube):
    faces = ["L", "R", "U", "D", "B", "F"]
    cubeArray = []
    for face in faces:
        face = cube.get_face(face)  # get face, iterate over all squares.
        for x in [0,1,2]:
            for y in [0,1,2]:
                cubeArray.append(str(face[x][y]))
    return cubeArray

PAK90 avatar Feb 19 '17 00:02 PAK90

Hi @PAK90, although this kind of usage might be useful, I wouldn't consider this "should be" a part of the Cube class, because the design of Cube class is to use "cubie" as component of the cube instead of six faces. Though if you'd like to contribute to this project, you can add this function into pycuber/helpers.py and submit a pull request!

adrianliaw avatar Feb 19 '17 16:02 adrianliaw

Hi, here is a function I use to convert a cube to an ndarray, this is especially useful for ML applications

def cube2np(mycube):
    # transform cube object to np array
    # works around the weird data type used
    global faces
    global colors
    cube_np = np.zeros((6,3,3))
    for i,face in enumerate(faces):
        face_tmp = mycube.get_face(face)
        for j in range(3):
            for k in range(len(face_tmp[j])):
                caca = face_tmp[j][k]
                cube_np[i,j,k] = colors.index(str(caca))
    return cube_np

jerpint avatar Sep 05 '17 18:09 jerpint