[Python] I'm stuck at a algo which solve the RUBIC cube cross for the first layer

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    as color check , matches the adjacent of white edge and flip to the center white to create cross, solve white edges solve the edges to the bottom and the last functions makes these two function work significantly.

    def color_check(self , i , j):
    for _ in range(5):
    if (i , j) == (0 , 1):
    center = self.cube["F"][1][1]
    if center == self.cube["F"][2][1]:
    self.apply_moves("F2")

    if (i , j) == (1 , 2):
    center = self.cube["R"][1][1]
    if center == self.cube["R"][2][1]:
    self.apply_moves("R2")

    if (i , j) == (2 , 1):
    center = self.cube["B"][1][1]
    if center == self.cube["B"][2][1]:
    self.apply_moves("B2")

    if (i , j) == (1 , 0):
    center = self.cube["L"][1][1]
    if center == self.cube["L"][2][1]:
    self.apply_moves("L2")
    self.apply_moves("D")



    def solve_white_cross(self):
    print("Bringing white edge pieces to bottom...")

    visited = set()

    while True:
    found = False
    for face, grid in self.cube.items():
    for i in range(3):
    for j in range(3):
    if (face, i, j) in visited:
    continue
    if grid[j] == "W" and ((i == 1 and j in [0, 2]) or (j == 1 and i in [0, 2])):
    print(f"White found on edge: ({i}, {j}, {face})")
    self.solve_white_edge(face, i, j)
    self.color_check(i , j)
    visited.add((face, i, j))
    found = True
    break
    if found:
    break
    if found:
    break
    if not found:
    break


    def solve_white_edge(self, face , i , j):
    if face == "F":#
    if (i , j) == (1,2): self.apply_moves("R")
    if (i , j) == (1,0): self.apply_moves("L'")
    if (i , j) == (0,1): self.apply_moves("F R' D'")
    if (i , j) == (2,1): self.apply_moves("F L D' L'")


    if face == "L":#
    if (i , j) == (1,2): self.apply_moves("D' F' D")
    if (i , j) == (1,0): self.apply_moves("D' B D")
    if (i , j) == (0,1): self.apply_moves("L F' L'")
    if (i , j) == (2,1): self.apply_moves("L B")

    if face == "R":
    if (i , j) == (1,2): self.apply_moves("B' D B")
    if (i , j) == (1,0): self.apply_moves("F D' F'")
    if (i , j) == (0,1): self.apply_moves("R B' D D B")
    if (i , j) == (2,1): self.apply_moves("R' B' R")

    if face == "B":
    if (i , j) == (1,2): self.apply_moves("B2 R B' B'")
    if (i , j) == (1,0): self.apply_moves("D R D'")
    if (i , j) == (0,1): self.apply_moves("B L' D L")
    if (i , j) == (2,1): self.apply_moves("B' D L' D'")


    I want to make the cross at the top I mean of white , but when I try to make all the edges to be at bottom and match the edge of the face with the white's alternate so that it can match , after 2-3 whites all messed as it cannot provide all the whites to be at correct position.

    Continue reading...

Compartilhe esta Página