栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/738184.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号