您的当前位置:首页正文

二阶魔方旋转 魔方可以对它的6个面自由旋转。 我们来操作一个2阶魔方(python版):

2024-11-30 来源:个人技术集锦

def ROL(List,n,m):
    lidd = List[m-n:m]
    lidd.extend(List)
    lidd = lidd[0:m]
    return lidd 
    
    
class MOF():
    def __init__(self):
        self.Xa = '绿' 
        self.Xb = '绿' 
        self.Xc = '绿' 
        self.Xd = '绿' 
        self.X_a = '蓝' 
        self.X_b = '蓝' 
        self.X_c = '蓝'
        self.X_d = '蓝' 
        
        self.Ya = '红' 
        self.Yb = '红' 
        self.Yc = '红' 
        self.Yd = '红' 
        self.Y_a = '橙' 
        self.Y_b = '橙' 
        self.Y_c = '橙'
        self.Y_d = '橙'
        
        
        self.Za = '白' 
        self.Zb = '白' 
        self.Zc = '白' 
        self.Zd = '白' 
        self.Z_a = '黄' 
        self.Z_b = '黄' 
        self.Z_c = '黄'
        self.Z_d = '黄'
    def pprr(self):
        print(self.Xd+self.Yb+self.Zc)
    def zhaun_X(self):
        limm = [self.Za,self.Zc,self.Yb,self.Ya,self.Z_c,self.Z_a,self.Y_a,self.Y_b]
        [self.Za,self.Zc,self.Yb,self.Ya,self.Z_c,self.Z_a,self.Y_a,self.Y_b] = ROL(limm,2,8)
        limn = [self.Xa,self.Xb,self.Xd,self.Xc]
        [self.Xa,self.Xb,self.Xd,self.Xc] = ROL(limn,1,4)
    def zhaun_Y(self): 
        limm = [self.Zc,self.Zd,self.X_d,self.X_c,self.Z_d,self.Z_c,self.Xc,self.Xd]
        [self.Zc,self.Zd,self.X_d,self.X_c,self.Z_d,self.Z_c,self.Xc,self.Xd] = ROL(limm,2,8)
        limn = [self.Ya,self.Yb,self.Yd,self.Yc]
        [self.Ya,self.Yb,self.Yd,self.Yc] = ROL(limn,1,4)
    def zhaun_Z(self):
        limm = [self.Xd,self.Xb,self.Y_b,self.Y_d,self.X_b,self.X_d,self.Yd,self.Yb]
        [self.Xd,self.Xb,self.Y_b,self.Y_d,self.X_b,self.X_d,self.Yd,self.Yb] = ROL(limm,2,8)
        limn = [self.Za,self.Zb,self.Zd,self.Zc]
        [self.Za,self.Zb,self.Zd,self.Zc] = ROL(limn,1,4)
        
mofang = MOF()
print("在初始状态,应该输出:")
mofang.pprr()
X = input("在初始状态,如果用户输入:\n")
print("则应该输出:")
for i in X:
    if i == 'x':
        mofang.zhaun_X()
    
    if i == 'y':
        mofang.zhaun_Y()
      
    if i == 'z':
        mofang.zhaun_Z()

    else:
        continue
mofang.pprr()
mofang = MOF()
X = input("在初始状态,如果用户输入:\n")
print("则应该输出:")
for i in X:
    if i == 'x':
        mofang.zhaun_X()
        
    elif i == 'y':
        mofang.zhaun_Y()
      
    elif i == 'z':
        mofang.zhaun_Z()

    else:
        break
mofang.pprr()

显示全文