Skip to content

Error When Rotating Connected Face ? #2

@mdavis0505

Description

@mdavis0505

Hi Ben -

Thanks for sharing this solver. I enjoy creating 3D visualizations using Blender. I have used your solver as inspiration to model and animate scrambling and solving a Rubiks cube.

Rubiks Cube Image V2

While I was doing this, I noticed that the code that rotates the connected faces occasionally produces an incorrect result. I confirmed this using both my visualization and my actual cube. I've corrected the errors with the following changes -

Horizontal -

#Rotating connected face
if direction == 0: #Twist left

            if row == 0:
                self.cube[0] = [list(x) for x in zip(*reversed(self.cube[0]))] #Transpose top
            elif row == len(self.cube[0]) - 1:
                # =========================================================================================
                #self.cube[5] = [list(x) for x in zip(*reversed(self.cube[5]))] #Transpose bottom
                # =========================================================================================
                
                temp1 = [list(x) for x in zip(*reversed(self.cube[5]))][::-1]   #Transpose bottom
                for i in range(3):
                    self.cube[5][i] = list(reversed(temp1[i]))
                                    
        elif direction == 1: #Twist right
            
            if row == 0:
                self.cube[0] = [list(x) for x in zip(*self.cube[0])][::-1] #Transpose top
            elif row == len(self.cube[0]) - 1:
                # =========================================================================================
                #self.cube[5] = [list(x) for x in zip(*self.cube[5])][::-1] #Transpose bottom
                # =========================================================================================
                self.cube[5] = [list(x) for x in zip(*reversed(self.cube[5]))] #Transpose bottom   

Vertical -

#Rotating connected face
if direction == 0: #Twist down
if column == 0:
# =================================================================================
#self.cube[1] = [list(x) for x in zip(*self.cube[1])][::-1] #Transpose left
# =================================================================================

                self.cube[1] = [list(x) for x in zip(*reversed(self.cube[1]))] #Transpose left
                # =================================================================================
                
            elif column == len(self.cube[0]) - 1:
                self.cube[3] = [list(x) for x in zip(*self.cube[3])][::-1] #Transpose right
        elif direction == 1: #Twist up
            if column == 0:
                # =================================================================================
                #self.cube[1] = [list(x) for x in zip(*reversed(self.cube[1]))] #Transpose left
                # =================================================================================
                
                temp1 = [list(x) for x in zip(*reversed(self.cube[1]))][::-1]   #Transpose left
                for i in range(3):
                    self.cube[1][i] = list(reversed(temp1[i]))
                
                # =================================================================================

Side -

#Rotating connected face
if direction == 0: #Twist down

            if column == 0:
                self.cube[4] = [list(x) for x in zip(*reversed(self.cube[4]))] #Transpose back
            elif column == len(self.cube[0]) - 1:
                # =================================================================================
                #self.cube[2] = [list(x) for x in zip(*reversed(self.cube[2]))] #Transpose top
                # =================================================================================
                
                temp1 = [list(x) for x in zip(*reversed(self.cube[2]))][::-1]   #Transpose front
                for i in range(3):
                    self.cube[2][i] = list(reversed(temp1[i]))
                
                # =================================================================================
            
        elif direction == 1: #Twist up
            
            if column == 0:
                self.cube[4] = [list(x) for x in zip(*self.cube[4])][::-1] #Transpose back
            elif column == len(self.cube[0]) - 1:
                # =================================================================================
                #self.cube[2] = [list(x) for x in zip(*self.cube[2])][::-1] #Transpose top
                # =================================================================================
                self.cube[2] = [list(x) for x in zip(*reversed(self.cube[2]))] #Transpose front

Some of my code is not very pythonian, but it works.

Thanks again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions