大佬们帮忙看一下,python解三阶魔方有沒有更快的方法
本人做了一个解三阶魔方的程序,但是步骤稍微多一点就用时较长,麻烦各位帮忙看一下有没有更高效的方法下面是代码#导入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 = b1;g = o1;r = g1;b = r1
y = y1;y = y1;y = y1;y = y1;y = y1;y = y1;y = y1;y = y1
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 = o1;o = g1;g = r1;r = b1
y = y1;y = y1;y = y1;y = y1;y = y1;y = y1;y = y1;y = y1
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 = w1;b = w1;b = w1
y = b1;y = b1;y = b1
g = y1;g = y1;g = y1
w = g1;w = g1;w = g1
r = r1;r = r1;r = r1;r = r1;r = r1;r = r1;r = r1;r = r1
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 = b1;w = b1;w = b1
b = y1;b = y1;b = y1
y = g1;y = g1;y = g1
g = w1;g = w1;g = w1
r = r1;r = r1;r = r1;r = r1;r = r1;r = r1;r = r1;r = r1
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 = o1;y = o1;y = o1
r = y1;r = y1;r = y1
w = r1;w = r1;w = r1
o = w1;o = w1;o = w1
b = b1;b = b1;b = b1;b = b1;b = b1;b = b1;b = b1;b = b1
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 = y1;o = y1;o = y1
y = r1;y = r1;y = r1
r = w1;r = w1;r = w1
w = o1;w = o1;w = o1
b = b1;b = b1;b = b1;b = b1;b = b1;b = b1;b = b1;b = b1
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 = o1;o = g1;g = r1;r = b1
w = w1;w = w1;w = w1;w = w1;w = w1;w = w1;w = w1;w = w1
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 = b1;g = o1;r = g1;b = r1
w = w1;w = w1;w = w1;w = w1;w = w1;w = w1;w = w1;w = w1
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 = b1;w = b1;w = b1
b = y1;b = y1;b = y1
y = g1;y = g1;y = g1
g = w1;g = w1;g = w1
o = o1;o = o1;o = o1;o = o1;o = o1;o = o1;o = o1;o = o1
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 = w1;b = w1;b = w1
y = b1;y = b1;y = b1
g = y1;g = y1;g = y1
w = g1;w = g1;w = g1
o = o1;o = o1;o = o1;o = o1;o = o1;o = o1;o = o1;o = o1
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 = r1;y = r1;y = r1
r = w1;r = w1;r = w1
w = o1;w = o1;w = o1
o = y1;o = y1;o = y1
g = g1;g = g1;g = g1;g = g1;g = g1;g = g1;g = g1;g = g1
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 = o1;y = o1;y = o1
r = y1;r = y1;r = y1
w = r1;w = r1;w = r1
o = w1;o = w1;o = w1
g = g1;g = g1;g = g1;g = g1;g = g1;g = g1;g = g1;g = g1
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 = 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 == b == b == b == b == b == b == b == b and g == g == g == g == g == g == g == g == g and o == o == o == o == o == o == o == o == o and r == r == r == r == r == r == r == r == r and y == y == y == y == y == y == y == y == y and w == w == w == w == w == w == w == w == w:
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
D:\蓝.png
D:\绿.png
D:\橙.png
D:\红.png
D:\黄.png
D:\白.png 图看得见吗 哦我知道为什么了,程序有bug对不起,已经改完了 hh138 发表于 2019-7-8 21:17
图看得见吗
想问下,这个代码输入的时候,比如蓝面1至9后面分别输入啥 鱼妹酱 发表于 2020-1-20 18:20
想问下,这个代码输入的时候,比如蓝面1至9后面分别输入啥
颜色用啥表示都可以,只要同种颜色用同一个字符串表示就行 这不是python的问题把。。。
这是解魔方的问题。cfop貌似正常不到100步吧,角先似乎更少,就是没人用。数学上似乎最少能够到26步。
你可以去魔方论坛问问那些sub10的大神都是用的什么方法。。。 刚刚试了一盘cfop是72步 - 无法看到你的图片,不明白怎么操作程序
新鱼油参照下面链接贴图:
<font color="red">[已解决]</font>帖子怎么添加图片?
https://fishc.com.cn/thread-143565-1-1.html
(出处: 鱼C论坛)
https://imgchr.com/i/1ZtVv6 https://imgchr.com/i/1ZtkCR https://imgchr.com/i/1ZtA81 https://imgchr.com/i/1ZtCE4 https://imgchr.com/i/1ZteKK https://imgchr.com/i/1ZtmDO https://imgchr.com/i/1ZtnbD图片好了 图片好了https://s2.ax1x.com/2020/01/24/1ZtVv6.png https://s2.ax1x.com/2020/01/24/1ZtkCR.png https://s2.ax1x.com/2020/01/24/1ZtA81.png https://s2.ax1x.com/2020/01/24/1ZtCE4.png https://s2.ax1x.com/2020/01/24/1ZteKK.png https://s2.ax1x.com/2020/01/24/1ZtmDO.png https://s2.ax1x.com/2020/01/24/1ZtnbD.png 白色面的https://s2.ax1x.com/2020/01/24/1ZtVv6.png 定义一个魔方类 这个是不是有点儿问题
页:
[1]