#!/usr/bin/python3 # Author: Georg Seegerer <7rk (at) gmx (point) de> # Copyright: public domain # date: 16 mai 2021 # version 1.1 # usage: cat example_cube.cub | python3 cub_2_rubik_pattern.py | rubiks_dikcube -p # take a saved cube (*.cub) from cube.exe and put it into the solver "rubiks_dikcube" # In MINT Linux 20.1 this file is part of the package "Rubiks", see # http://manpages.ubuntu.com/manpages/xenial/man1/rubiks_dikcube.1.html # Output examples: # F1: turn front side CW (as seen from top of this side) # F2: turn front side 180° # F3: turn front side CCW # B1: turn back side CW (as seen from top of the back side) # CW: clock wise # CCW: counter clock wise ################# # version history # # v1.1 (16 mai 2021) # description of the rubiks_dikcube output format corrected (twists were mirrored) # color number of Cube.exe to letter of rubiks_dikcube mapping: now works for non-default color definition in Cube.ini # v1.0 (9 mai 2021) # initial release ################# # cube.exe: https://www.heise.de/download/product/cube-50629 # # file format of saved *.cub File of cube.exe: # line face in cube.exe face name # with F7-default as used in # orientation rubiks_dikcube # 1-9 up U # 10-18 down D (this face is named "down" on purpose) # 19-27 left L # 28-36 front F # 37-45 right R # 46-54 back B (attention: B is "backside" not "bottom"!) import sys num_elements=54 # there are 6 faces with 9 elements each cub_num_list=[-1] * (num_elements+1) # Init List rub= [0] * (num_elements+1) linecnt=1 # Element with index zero is unused on purpose for line in sys.stdin: #print(line) if line[0].isnumeric(): # first character of the line is a number? cub_num_list[linecnt]=int(line[0]) # put first char of the line into the list + convert to integer linecnt=linecnt+1 else: continue # with this, being robust against empty lines, headlines, lines with comments, etc. if linecnt > num_elements: # read max 54 lines, even if there are more break if linecnt!=(num_elements+1): sys.stderr.write("****** too less lines in the input:") sys.stderr.write(str(linecnt)) sys.stderr.write(" ******") exit # mapping: color to face cub2char_list = ["-","-","-","-","-","-"] # now: this are only dummy values # index number of the center piece of each face: 5 = offset of center piece of that face / [0..5]*9 = all 6 faces cub2char_list[cub_num_list[5+0*9]]="U" # this is the color number for UP cub2char_list[cub_num_list[5+1*9]]="D" # this is the color number for DOWN cub2char_list[cub_num_list[5+2*9]]="L" # this is the color number for LEFT cub2char_list[cub_num_list[5+3*9]]="F" # this is the color number for FRONT cub2char_list[cub_num_list[5+4*9]]="R" # this is the color number for RIGHT cub2char_list[cub_num_list[5+5*9]]="B" # this is the color number for BACK # print (cub2char_list) # debugging # ToDo: sanity check: all 6 elements of cub2char_list got a letter # replace the numbers of the *.cub file with the letters for the faces for index in range(len(cub_num_list)): rub[index]=cub2char_list[cub_num_list[index]] # generate the output: pattern for rubiks_dikcube needs to look like this: # BBB # BBB # BBB # LLLUUURRRDDD # LLLUUURRRDDD # LLLUUURRRDDD # FFF # FFF # FFF print(" ", rub[54],rub[53],rub[52], sep='') print(" ", rub[51],rub[50],rub[49], sep='') print(" ", rub[48],rub[47],rub[46], sep='') print(rub[25],rub[22],rub[19], rub[ 1],rub[ 2],rub[ 3], rub[39],rub[42],rub[45], rub[18],rub[17],rub[16], sep='') print(rub[26],rub[23],rub[20], rub[ 4],rub[ 5],rub[ 6], rub[38],rub[41],rub[44], rub[15],rub[14],rub[13], sep='') print(rub[27],rub[24],rub[21], rub[ 7],rub[ 8],rub[ 9], rub[37],rub[40],rub[43], rub[12],rub[11],rub[10], sep='') print(" ", rub[28],rub[29],rub[30], sep='') print(" ", rub[31],rub[32],rub[33], sep='') print(" ", rub[34],rub[35],rub[36], sep='') #print (linecnt) #print(cub_num_list) #print(rub)