Python练手项目:计算机自动还原魔方(5)最后一步

20 篇文章 3 订阅
17 篇文章 2 订阅

最后一步实际上有两个步骤,第一步是先还原顶部四个棱角,然后还原顶部四个棱块,然后魔方得以全部还原。

万事开头难,越到后面越简单。这两个步骤分别用两个公式即可完成,而且状态也特别简单,算法如下:

def 顶部4棱角到位():
    c1=(cube_list[3][5][0] == cube_list[4][4][0]) and (cube_list[3][6][0] == cube_list[4][7][0])
    c2 = (cube_list[3][3][0] == cube_list[4][4][0]) and (cube_list[3][2][0] == cube_list[4][1][0])
    c3 = (cube_list[3][0][0] == cube_list[4][1][0]) and (cube_list[3][11][0] == cube_list[4][10][0])
    c4 = (cube_list[3][8][0] == cube_list[4][7][0]) and (cube_list[3][9][0] == cube_list[4][10][0])
    if c1 and c2 and c3 and c4:
        return True
    else:
        return False
def 当前棱角到位():
    if (cube_list[3][5][0] == cube_list[4][4][0]) and (cube_list[3][6][0] == cube_list[4][7][0]):
        return True
    else:
        return False
def 还原顶部4棱角():
    while not 顶部4棱角到位():
        if not 当前棱角到位():
            formula_cmd(["R", "U","U","Rp","Up", "R", "U","U","Lp","U", "Rp", "Up", "L"])
        left()

def 顶部四棱块到位():
    pass
    e1=cube_list[3][4][0]==cube_list[4][4][0]
    e2 = cube_list[3][1][0] == cube_list[4][1][0]
    e3 = cube_list[4][7][0] == cube_list[3][7][0]
    e4 = cube_list[4][10][0] == cube_list[3][10][0]
    if e1 and e2 and e3 and e4:
        return True
    else:
        return False

def 最后一步():
    while not 顶部四棱块到位():
        if cube_list[3][4][0]!=cube_list[4][4][0] and cube_list[3][7][0]!=cube_list[4][7][0] and cube_list[3][1][0]!=cube_list[4][1][0]:
            formula_cmd(['F','F','U','L','Rp','F','F','R','Lp','U','F','F'])
        else:
            left()

运行结果如下:

先前状态,还原到顶部出现绿面:

还原顶部四个棱角

 还原顶部四棱块

 --end

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值