bellerb / RubiksCube_Solver

Rubik's cube solver written in python 3 for the console
MIT License
28 stars 17 forks source link

Error When Rotating Connected Face ? #2

Open mdavis0505 opened 1 year ago

mdavis0505 commented 1 year ago

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.

bellerb commented 1 year ago

Wanna create a push request and ill merge it in?

mdavis0505 commented 1 year ago

Doesn't look like I have the credentials needed to create a new branch to include in a pull request. No "New Branch" button presented to me.

potto216 commented 1 year ago

Just checking if there is a path for resolving the PR? Thanks @bellerb for the code and thanks @mdavis0505 for the fix

bellerb commented 1 year ago

Are you not able to make a pull request with the updated code? If not I can implement the changes myself when I get some free time.