• Welcome to SpeedSolving.com — the world’s largest puzzle community!

    You’re currently browsing as a guest, which means you have limited access to discussions, resources, member profiles, and community features.

    Join 50,000+ cubers and puzzle enthusiasts from around the world to ask questions, share solves, improve faster, and be part of the community.

    Registration is free, fast, and easy — create your account today.

    Already a member? Log in here to hide this message and start participating.

Python Cube Project

How do you guys think I should format sequences? I could do something where I just have a list with the moves, then I could just do something like:
Code:
for move in sequence:
     self.move(move)
Which would be really simple, but maybe some other way would be nicer.
All my code is messy, so I can't really help.
 
Ok, I think i'm just gonna go the list way for now. I think all I really need to do is code in other moves besides R, which shouldn't be that bad, and then I can do some funner stuff like alg genning.
Ya. If you run into problems with it in the future, it shouldn't take too long to change.
 
I think the thing I want to find how to do now is to make a function that converts a sequence (A list of move objects in my code) into a single move object. Then I only need to manually code x, y, and R to make all possible moves. Any ideas on how to do that? I'm clueless.
 
I think the thing I want to find how to do now is to make a function that converts a sequence (A list of move objects in my code) into a single move object. Then I only need to manually code x, y, and R to make all possible moves. Any ideas on how to do that? I'm clueless.
This splits by spaces:
Python:
alg = input('Alg:') #Input
print(alg.split()) #Output alg split into list
 
In my code for a similar purpose I have also numbered stickers on a cube.
And a sequence can be described as a list of numbers saying to which sticker a given sticker should move.
Sequence that changes nothing is [0, .., 24] for edges and corners respectively.
Each face turn can be described as 2 4-cycles of edges and 3 4-cycles of corners.
Code:
faces = {
     "R" : { "e": [[12,13,14,15], [1,19,9,5]], "c" :[[12,13,15,14], [5,1,18,9], [3,16,11,7]]},
     "U" : { "e": [[0,1,2,3], [20, 16, 12, 4]], "c" :[[0,1,3,2], [17,13,5,21], [16, 12, 4,20]]},
     "F" : { "e": [[4,5,6,7], [2, 15, 8, 21]], "c" :[[4,5,7,6], [2, 12, 9, 23], [3, 14, 8, 21]]},
     "L" : { "e": [[20,21,22,23], [3, 7, 11,17]], "c" :[[20, 21, 23, 22 ], [0, 4, 8, 19], [2, 6, 10, 17]]},
     "D" : { "e": [[8,9,10,11], [6,14,18,22]], "c" :[[8,9,11,10], [6, 14, 18, 22], [7, 15, 19, 23]]},
     "B" : { "e": [[16,17,18,19], [0,23,10,13]], "c" :[[16, 17, 19, 18], [1, 20, 10, 15], [0, 22, 11, 13]]},
and then you can apply those cycles to a sequence like this:
Code:
def apply4Cycle(target, cycle):
    c0,c1,c2,c3 = cycle
    t3 = target[c3]
    target[c3] = target[c2]
    target[c2] = target[c1]
    target[c1] = target[c0]
    target[c0] = t3

to achieve R' you can do R three times like this:
Code:
    edgeCycles = faces["R"]["e"]
    cornerCycles = faces["R"]["c"]
    edges = list(range(24))
    corners = list(range(24))
    for i in range(3):
        for ec in edgeCycles:
            apply4Cycle(edges, ec)
        for cc in cornerCycles:
            apply4Cycle(corners, cc)
 
In my code for a similar purpose I have also numbered stickers on a cube.
And a sequence can be described as a list of numbers saying to which sticker a given sticker should move.
Sequence that changes nothing is [0, .., 24] for edges and corners respectively.
Each face turn can be described as 2 4-cycles of edges and 3 4-cycles of corners.
Code:
faces = {
     "R" : { "e": [[12,13,14,15], [1,19,9,5]], "c" :[[12,13,15,14], [5,1,18,9], [3,16,11,7]]},
     "U" : { "e": [[0,1,2,3], [20, 16, 12, 4]], "c" :[[0,1,3,2], [17,13,5,21], [16, 12, 4,20]]},
     "F" : { "e": [[4,5,6,7], [2, 15, 8, 21]], "c" :[[4,5,7,6], [2, 12, 9, 23], [3, 14, 8, 21]]},
     "L" : { "e": [[20,21,22,23], [3, 7, 11,17]], "c" :[[20, 21, 23, 22 ], [0, 4, 8, 19], [2, 6, 10, 17]]},
     "D" : { "e": [[8,9,10,11], [6,14,18,22]], "c" :[[8,9,11,10], [6, 14, 18, 22], [7, 15, 19, 23]]},
     "B" : { "e": [[16,17,18,19], [0,23,10,13]], "c" :[[16, 17, 19, 18], [1, 20, 10, 15], [0, 22, 11, 13]]},
and then you can apply those cycles to a sequence like this:
Code:
def apply4Cycle(target, cycle):
    c0,c1,c2,c3 = cycle
    t3 = target[c3]
    target[c3] = target[c2]
    target[c2] = target[c1]
    target[c1] = target[c0]
    target[c0] = t3

to achieve R' you can do R three times like this:
Code:
    edgeCycles = faces["R"]["e"]
    cornerCycles = faces["R"]["c"]
    edges = list(range(24))
    corners = list(range(24))
    for i in range(3):
        for ec in edgeCycles:
            apply4Cycle(edges, ec)
        for cc in cornerCycles:
            apply4Cycle(corners, cc)
I was saying with my current move system, how would I turn a sequence, say R' B, into a single Move object, which I described earlier. I have a vague idea now, but it needs more work.
 
I was saying with my current move system, how would I turn a sequence, say R' B, into a single Move object, which I described earlier. I have a vague idea now, but it needs more work.
Here is a more complete version of the code:
Python:
alg = input('Alg:') #Input
algList = alg.split() #Split alg
for i in algList:
   self.move[i] #Apply move
self.move is just placeholder code for a move function.
 
Last edited:
Ok. I'm confused. I made a function that takes a sequence of moves, and turns it into a Move object. So that works fine, which is good, but something weird happened. The way I made the function was I made a new Cube object in the function called cube, and one of my steps was changing the elements of cube.state into tuples. Then I did some code that outputted a Move object. when I tested my code, I made a new cube object to see if the program correctly turned the sequence [R, R] into an R2.
Then when I printed out cube.state to see if it did it correctly, all the values were tuples, even I used a different cube object to test and to use in the function. i printed their id's as well and they were different. Here's my code:
Code:
SOLVED = ['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']



class Move:
    def __init__(self, pre_indices, post_indices):
        self.pre_indices = pre_indices
        self.post_indices = post_indices

    def inverted(self):
        return Move(self.post_indices, self.pre_indices)


class Cube():
    def __init__(self, state=SOLVED):
        self.state = state

    def move(self, move):
        cube = self.state
        pre_indices = move.pre_indices
        post_indices = move.post_indices
        next_cube = cube[:]
        for i in range(len(pre_indices)):
            next_cube[post_indices[i] - 1] = cube[pre_indices[i] - 1]
        self.state = next_cube[:]

    def sequence(self, sequence):
        for move in sequence:
            self.move(move)


def move_from_sequence(sequence):
    cube = Cube()
    print(id(cube))
    cycle=0
    new_pre_indices=[]
    new_post_indices=[]
    item=()
    for sticker in cube.state:
        cycle += 1
        cube.state[cycle-1]=(sticker,cycle)
    cube.sequence(sequence)
    cycle=0
    for sticker in cube.state:
        cycle += 1
        item=cube.state[cycle-1]
        if cycle != item[1]:
            new_post_indices.append(cycle)
            new_pre_indices.append(item[1])

    return(Move(new_pre_indices,new_post_indices))

R = Move([3, 6, 9, 21, 24, 27, 12, 15, 18, 43, 40, 37, 28, 30, 36, 34, 29, 33, 35, 31],
         [43, 40, 37, 3, 6, 9, 21, 24, 27, 12, 15, 18, 30, 36, 34, 28, 33, 35, 31, 29])
cube=Cube()
print(id(cube))
R2=move_from_sequence([R,R])
print(cube.state)

cube.move(R2)
print(cube.state)
 
Man I am just not as experienced in python as I thought LOL. Im familiar with Object-Oriented coding in python but some of this stuff is beyond me. It seems like you found a fix in the issue of your first/original post. Only thing I could probably add is using the debugger to see exactly how your variables/values are being treated. Super handy tool especially in an IDE like Pycharm like you said you're using.
 
Man I am just not as experienced in python as I thought LOL. Im familiar with Object-Oriented coding in python but some of this stuff is beyond me. It seems like you found a fix in the issue of your first/original post. Only thing I could probably add is using the debugger to see exactly how your variables/values are being treated. Super handy tool especially in an IDE like Pycharm like you said you're using.
oooh, i didn't know Pycharm had a fancy debugger, figures though, since its a professional IDE lol. I'll try that. Also, part of you not getting my code may come from me being in-concise and stuff. Other peoples code is always harder to understand than your own.
 
Python:
for sticker in cube.state:
        cycle += 1
        cube.state[cycle-1]=(sticker,cycle)

The problem might be here
You're generating a tuple
 
Python:
for sticker in cube.state:
        cycle += 1
        cube.state[cycle-1]=(sticker,cycle)

The problem might be here
You're generating a tuple
I meant to make a tuple. I thinm the problem is I set th e default cube state to the list SOLVED, not SOLVED[:]. So then whenever any cube object gets changed it changes the default. Edit: Never mind, I tried that and it did nothing. Now I'm very confuzzled.
 
Last edited:
I meant to make a tuple. I thinm the problem is I set th e default cube state to the list SOLVED, not SOLVED[:]. So then whenever any cube object gets changed it changes the default. Edit: Never mind, I tried that and it did nothing. Now I'm very confuzzled.
I would just go through the code and print it until it turns into a tuple.
 
Back
Top