#导入easygui模块
import easygui as eg
#得到每一面的颜色分布(里面说的图片在下面)
b = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为蓝面的颜色(如图 蓝.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
g = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为绿面的颜色(如图 绿.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
o = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为橙面的颜色(如图 橙.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
r = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为红面的颜色(如图 红.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
y = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为黄面的颜色(如图 黄.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
w = eg.multenterbox("请按从上到下,从左到右的顺序输入中心点为白面的颜色(如图 白.png 所示):","输入",["1","2","3","4","5","6","7","8","9"])
b1 = b[:];g1 = g[:];o1 = o[:];r1 = r[:];y1 = y[:];w1 = w[:]
b0 = b[:];g0 = g[:];o0 = o[:];r0 = r[:];y0 = y[:];w0 = w[:]
#定义转动魔方的函数(用改变每一面的列表的元素的方式)(函数名直接沿用魔方公式的字母,详见下面的图)
def U():
global b;global b1;global g;global g1;global o;global o1;global r;global r1;global y;global y1
o[0:3] = b1[0:3];g[0:3] = o1[0:3];r[0:3] = g1[0:3];b[0:3] = r1[0:3]
y[0] = y1[6];y[1] = y1[3];y[2] = y1[0];y[3] = y1[7];y[5] = y1[1];y[6] = y1[8];y[7] = y1[5];y[8] = y1[2]
b1 = b[:];g1 = g[:];o1 = o[:];r1 = r[:];y1 = y[:]
def U1():
global b;global b1;global g;global g1;global o;global o1;global r;global r1;global y;global y1
b[0:3] = o1[0:3];o[0:3] = g1[0:3];g[0:3] = r1[0:3];r[0:3] = b1[0:3]
y[0] = y1[2];y[1] = y1[5];y[2] = y1[8];y[3] = y1[1];y[5] = y1[7];y[6] = y1[0];y[7] = y1[3];y[8] = y1[6]
b1 = b[:];g1 = g[:];o1 = o[:];r1 = r[:];y1 = y[:]
def R():
global b;global b1;global g;global g1;global w;global w1;global r;global r1;global y;global y1
b[2] = w1[2];b[5] = w1[5];b[8] = w1[8]
y[2] = b1[2];y[5] = b1[5];y[8] = b1[8]
g[0] = y1[8];g[3] = y1[5];g[6] = y1[2]
w[2] = g1[6];w[5] = g1[3];w[8] = g1[0]
r[0] = r1[6];r[1] = r1[3];r[2] = r1[0];r[3] = r1[7];r[5] = r1[1];r[6] = r1[8];r[7] = r1[5];r[8] = r1[2]
b1 = b[:];g1 = g[:];w1 = w[:];r1 = r[:];y1 = y[:]
def R1():
global b;global b1;global g;global g1;global w;global w1;global r;global r1;global y;global y1
w[2] = b1[2];w[5] = b1[5];w[8] = b1[8]
b[2] = y1[2];b[5] = y1[5];b[8] = y1[8]
y[8] = g1[0];y[5] = g1[3];y[2] = g1[6]
g[0] = w1[8];g[3] = w1[5];g[6] = w1[2]
r[0] = r1[2];r[1] = r1[5];r[2] = r1[8];r[3] = r1[1];r[5] = r1[7];r[6] = r1[0];r[7] = r1[3];r[8] = r1[6]
b1 = b[:];g1 = g[:];w1 = w[:];r1 = r[:];y1 = y[:]
def F():
global b;global b1;global o;global o1;global w;global w1;global r;global r1;global y;global y1
y[6] = o1[8];y[7] = o1[5];y[8] = o1[2]
r[0] = y1[6];r[3] = y1[7];r[6] = y1[8]
w[0] = r1[6];w[1] = r1[3];w[2] = r1[0]
o[2] = w1[0];o[5] = w1[1];o[8] = w1[2]
b[0] = b1[6];b[1] = b1[3];b[2] = b1[0];b[3] = b1[7];b[5] = b1[1];b[6] = b1[8];b[7] = b1[5];b[8] = b1[2]
b1 = b[:];o1 = o[:];w1 = w[:];r1 = r[:];y1 = y[:]
def F1():
global b;global b1;global o;global o1;global w;global w1;global r;global r1;global y;global y1
o[8] = y1[6];o[5] = y1[7];o[2] = y1[8]
y[6] = r1[0];y[7] = r1[3];y[8] = r1[6]
r[0] = w1[2];r[3] = w1[1];r[6] = w1[0]
w[0] = o1[2];w[1] = o1[5];w[2] = o1[8]
b[0] = b1[2];b[1] = b1[5];b[2] = b1[8];b[3] = b1[1];b[5] = b1[7];b[6] = b1[0];b[7] = b1[3];b[8] = b1[6]
b1 = b[:];o1 = o[:];w1 = w[:];r1 = r[:];y1 = y[:]
def D():
global b;global b1;global g;global g1;global o;global o1;global r;global r1;global w;global w1
b[6:9] = o1[6:9];o[6:9] = g1[6:9];g[6:9] = r1[6:9];r[6:9] = b1[6:9]
w[0] = w1[6];w[1] = w1[3];w[2] = w1[0];w[3] = w1[7];w[5] = w1[1];w[6] = w1[8];w[7] = w1[5];w[8] = w1[2]
b1 = b[:];g1 = g[:];o1 = o[:];r1 = r[:];w1 = w[:]
def D1():
global b;global b1;global g;global g1;global o;global o1;global r;global r1;global w;global w1
o[6:9] = b1[6:9];g[6:9] = o1[6:9];r[6:9] = g1[6:9];b[6:9] = r1[6:9]
w[0] = w1[2];w[1] = w1[5];w[2] = w1[8];w[3] = w1[1];w[5] = w1[7];w[6] = w1[0];w[7] = w1[3];w[8] = w1[6]
b1 = b[:];g1 = g[:];o1 = o[:];r1 = r[:];w1 = w[:]
def L():
global b;global b1;global g;global g1;global w;global w1;global o;global o1;global y;global y1
w[0] = b1[0];w[3] = b1[3];w[6] = b1[6]
b[0] = y1[0];b[3] = y1[3];b[6] = y1[6]
y[0] = g1[8];y[3] = g1[5];y[6] = g1[2]
g[2] = w1[6];g[5] = w1[3];g[8] = w1[0]
o[0] = o1[6];o[1] = o1[3];o[2] = o1[0];o[3] = o1[7];o[5] = o1[1];o[6] = o1[8];o[7] = o1[5];o[8] = o1[2]
b1 = b[:];g1 = g[:];w1 = w[:];o1 = o[:];y1 = y[:]
def L1():
global b;global b1;global g;global g1;global w;global w1;global o;global o1;global y;global y1
b[0] = w1[0];b[3] = w1[3];b[6] = w1[6]
y[0] = b1[0];y[3] = b1[3];y[6] = b1[6]
g[2] = y1[6];g[5] = y1[3];g[8] = y1[0]
w[0] = g1[8];w[3] = g1[5];w[6] = g1[2]
o[0] = o1[2];o[1] = o1[5];o[2] = o1[8];o[3] = o1[1];o[5] = o1[7];o[6] = o1[0];o[7] = o1[3];o[8] = o1[6]
b1 = b[:];g1 = g[:];w1 = w[:];o1 = o[:];y1 = y[:]
def B():
global g;global g1;global o;global o1;global w;global w1;global r;global r1;global y;global y1
y[0] = r1[2];y[1] = r1[5];y[2] = r1[8]
r[2] = w1[8];r[5] = w1[7];r[8] = w1[6]
w[8] = o1[6];w[7] = o1[3];w[6] = o1[0]
o[0] = y1[2];o[3] = y1[1];o[6] = y1[0]
g[0] = g1[6];g[1] = g1[3];g[2] = g1[0];g[3] = g1[7];g[5] = g1[1];g[6] = g1[8];g[7] = g1[5];g[8] = g1[2]
g1 = g[:];o1 = o[:];w1 = w[:];r1 = r[:];y1 = y[:]
def B1():
global g;global g1;global o;global o1;global w;global w1;global r;global r1;global y;global y1
y[0] = o1[6];y[1] = o1[3];y[2] = o1[0]
r[2] = y1[0];r[5] = y1[1];r[8] = y1[2]
w[8] = r1[2];w[7] = r1[5];w[6] = r1[8]
o[0] = w1[6];o[3] = w1[7];o[6] = w1[8]
g[6] = g1[0];g[3] = g1[1];g[0] = g1[2];g[7] = g1[3];g[1] = g1[5];g[8] = g1[6];g[5] = g1[7];g[2] = g1[8]
g1 = g[:];o1 = o[:];w1 = w[:];r1 = r[:];y1 = y[:]
#制作一个生成器,参数list1是一个列表,每次给最后一个元素+1,并返回新列表;当一个元素等于12时,改为向前一个元素+1
def main(list1):
n = 0
list1.reverse()
for i in list1.:
while i <= 12:
list1[n] = i
yield list1
i += 1
n += 1
if __name__ == "__main__":
off = 0
#按步骤从小到大的顺序尝试还原方法
for j in range(1,183): #这里的183是因为本人算过,三阶魔方最多用182步还原
list0 = []
#生成一个元素数量为步骤数的列表,每一项均为一
while j:
list0.append(1)
j -= 1
for k in main(list0):
#按照列表的步骤拧魔方,看看能不能还原
for m in k:
if m == 1:
U()
elif m == 2:
U1()
elif m == 3:
R()
elif m == 4:
R1()
elif m == 5:
F()
elif m == 6:
F1()
elif m == 7:
D()
elif m == 8:
D1()
elif m == 9:
L()
elif m == 10:
L1()
elif m == 11:
B()
elif m == 12:
B1()
#如果能还原,就把列表里的数值转换成人话
if b[0] == b[1] == b[2] == b[3] == b[4] == b[5] == b[6] == b[7] == b[8] and g[0] == g[1] == g[2] == g[3] == g[4] == g[5] == g[6] == g[7] == g[8] and o[0] == o[1] == o[2] == o[3] == o[4] == o[5] == o[6] == o[7] == o[8] and r[0] == r[1] == r[2] == r[3] == r[4] == r[5] == r[6] == r[7] == r[8] and y[0] == y[1] == y[2] == y[3] == y[4] == y[5] == y[6] == y[7] == y[8] and w[0] == w[1] == w[2] == w[3] == w[4] == w[5] == w[6] == w[7] == w[8]:
ret = ""
for p in k:
if p == 1:
ret += "U "
elif p == 2:
ret += "U" "
elif p == 3:
ret += "R "
elif p == 4:
ret += "R" "
elif p == 5:
ret += "F "
elif p == 6:
ret += "F" "
elif p == 7:
ret += "D "
elif p == 8:
ret += "D" "
elif p == 9:
ret += "L "
elif p == 10:
ret += "L" "
elif p == 11:
ret += "B "
elif p == 12:
ret += "B" "
off = 1
break
if off:
break
#输出s
if ret:
eg.msgbox("还原:" + ret,"输出")
else:
eg.msgbox("无法还原!","输出")
D:\python文件\练习\魔方公式图解.png