# utilitaires.py

Created by ph-moutou

Created on June 14, 2018

1.79 KB

fonctions utiles au jeu 2048

```def move(t):
moved=0
if t[3]==t[2] and t[3]!=0:
t[3]=1+t[2]
if t[1]==t[0] and t[1]!=0:
t[2]=1+t[1]
t[1]=0
moved+=2**t[2]
elif t[1]==0:t[2]=t[0]
else:#t[1]!=0
t[2]=t[1]
t[1]=t[0]
moved+=2**t[3]
elif t[3]!=0:
if t[2]==t[1] and t[2]!=0:
t[2]=1+t[2]
t[1]=t[0]
moved+=t[2]
elif t[1]==0 and t[2]!=0:
if t[2]==t[0]:
t[2]=1+t[2]
moved+=2**t[2]
else:#t[2]!=t[0]
t[1]=t[0]
elif t[2]!=0 and t[1]==t[0] and t[1]!=0:
t[1]=1+t[1]
moved+=2**t[1]
elif t[2]==0:
if t[1]==t[3]:
t[3]=1+t[3]
t[2]=t[0]
moved+=2**t[3]
elif t[1]!=0 :
if t[1]==t[0]:
t[2]=1+t[1]
t[1]=0
moved+=2**t[2]
else:#t[1]!=t[0]
t[2]=t[1]
t[1]=t[0]
else:#t[1]==0
if t[0]==t[3]:
t[3]=1+t[3]
moved+=2**t[3]
else:#t[0]!=t[3]
t[2]=t[0]
else:moved=-1
elif t[3]==0:
if t[2]!=0 :
if t[2]==t[1]:
t[3]=1+t[2]
t[2]=t[0]
t[1]=0
moved+=2**t[3]
else:#t[2]!=t[1]
if t[1]==t[0] and t[1]!=0 :
t[3]=t[2]
t[2]=1+t[1]
t[1]=0
moved+=2**t[1]
elif t[1]!=t[0] and t[1]!=0:
t[3]=t[2]
t[2]=t[1]
t[1]=t[0]
elif t[1]==0:
if t[0]==t[2]:
t[3]=1+t[2]
moved+=2**t[3]
else:#t[0]!=t[2]
t[3]=t[2]
t[2]=t[0]
else:#t[2]==0
if t[1]==t[0] and t[1]!=0 :
t[3]=1+t[1]
t[1]=0
moved+=2**t[3]
elif t[1]!=t[0] and t[1]!=0 :
t[3]=t[1]
t[2]=t[0]
t[1]=0
elif t[0]!=0:
t[3]=t[0]
if moved>=0:t[0]=0
return t,moved```