deepSubDiver
Regular
I am currently writing a tool to generate scrambles and give optimal cross solutions.
I bruteforce all possibilities (BFS) to find the shortest solution, taking ages to compute.
What I am asking for, are there any ideas how I could speed it up?
Below an excerpt of the code.
I bruteforce all possibilities (BFS) to find the shortest solution, taking ages to compute.
What I am asking for, are there any ideas how I could speed it up?
Below an excerpt of the code.
Code:
def get_moves(seq):
ret = []
for m in ["F ", "F2 ", "F' ", "B ", "B2 ", "B' ", "R ", "R2 ", "R' ", "L ", "L2 ", "L' ", "U ", "U2 ", "U' ", "D ", "D2 ", "D' "]:
if len(seq) > 0:
if m[0] == seq[:-1].rsplit(" ")[-1][0]:
continue
yield m
def seqlen(seq): return len(seq.rsplit(" ")) - 1
def brute(cube, mdepth = 8):
depth = 0
q = Queue()
q.put("")
while not q.empty():
seq = q.get()
if seqlen(seq) > depth:
depth = seqlen(seq)
print "depth: %d (qsize: %d)" % (depth, q.qsize())
cube.apply_sequence(seq)
if cube.cross_solved(): return seq
cube.undo()
if seqlen(seq) == mdepth: continue
for m in get_moves(seq):
q.put(seq + m)