用户:
游侠已退查看:4 回复:5 评论:4 创建时间:2021-02-10T14:04:04
https: //www. 2043 .cn/
(虽然网址是“2043”但其实是2048
)
沐夏_IMuXia这位大佬,你是不是有好的作品,但是没有地方投稿?
蓝色工作室招人啦!,急招萌新,无门槛!上限1000人,为工作室做出贡献可成为副室长!!!编程喵的粉丝们,快来吧!我们一起加油!!!(副室长只有10名额,快来吧),专门讨论编程问题!
点赞0
评论
KIHIO我居然用PYTHON写了一个2048
import random
h=[]
i=0
while i<16:
h.append(0)
i+=1
l=random.randint(0,15)
l2=random.randint(0,15)
while l2==l:
l2=random.randint(0,15)
h[l]=2
h[l2]=2
win=0
while True:
i=0
pzf=' '
while i<16:
if (i+1)%4==1:
pzf=str(h[i])
else:
pzf=pzf+str(h[i])
if (i+1)%4==0:
print(pzf)
else:
j=0
while j<5-(len(str(h[i]))):
pzf=pzf+' '
j+=1
i+=1
i=0
while i<16:
if h[i]==2048:
print("你组合出了2048!!!你赢了!!!")
win=1
break
i+=1
if win==1:
break
i=0
xh=1
while i<16:
if h[i]==0:
xh=0
break
i+=1
if xh==1:
js=0
i=0
while i<16:
if i%4!=3:
if h[i]==h[i+1]:
js+=1
i+=1
i=0
while i<4:
j=0
while j<=8:
if h[i+j]==h[i+j+4]:
js+=1
j+=4
i=i+1
if js==0:
print("没法拼接了,你输了……")
break
try:
x=float(input("你要做什么决策?(1上2下3左4右):"))
except ValueError:
print("ERROR:你的输入为字符串")
break
if x-(float(int(x)))>0:
print("ERROR:你的输入为小数")
break
x=int(x)
if x==1:
i=4
while i<16:
f=i
if h[i]!=0:
while f>=0:
if h[f]!=0 and f!=i:
if h[f]==h[i]:
h[f]+=h[i]
h[i]=0
else:
if f!=i-4:
h[f+4]=h[i]
h[i]=0
break
f-=4
if h[f+4]==0 and f<0:
h[f+4]=h[i]
h[i]=0
i+=1
i=0
g=0
while i<16:
if h[i]==0:
g=1
break
i+=1
if g==1:
l=random.randint(0,15)
while h[l]!=0:
l=random.randint(0,15)
js=random.randint(1,2)
h[l]=js*2
elif x==2:
i=11
while i>=0:
f=i
if h[i]!=0:
while f<=15:
if h[f]!=0 and f!=i:
if h[f]==h[i]:
h[f]+=h[i]
h[i]=0
else:
if f!=i+4:
h[f-4]=h[i]
h[i]=0
break
f+=4
if h[f-4]==0 and f>15:
h[f-4]=h[i]
h[i]=0
i-=1
i=0
g=0
while i<16:
if h[i]==0:
g=1
break
i+=1
if g==1:
l=random.randint(0,15)
while h[l]!=0:
l=random.randint(0,15)
js=random.randint(1,2)
h[l]=js*2
elif x==4:
i=15
while i>=0:
if i%4!=3:
f=i
if h[i]!=0:
while f<=((int(i/4))*4+3):
if h[f]!=0 and f!=i:
if h[f]==h[i]:
h[f]+=h[i]
h[i]=0
else:
if f!=i+1:
h[f-1]=h[i]
h[i]=0
break
f+=1
if h[f-1]==0 and f>((int(i/4))*4+3):
h[f-1]=h[i]
h[i]=0
i-=1
i=0
g=0
while i<16:
if h[i]==0:
g=1
break
i-=1
if g==1:
l=random.randint(0,15)
while h[l]!=0:
l=random.randint(0,15)
js=random.randint(1,2)
h[l]=js*2
elif x==3:
i=1
while i<16:
if i%4!=0:
f=i
if h[i]!=0:
while f>=((int(i/4))*4):
if h[f]!=0 and f!=i:
if h[f]==h[i]:
h[f]+=h[i]
h[i]=0
else:
if f!=i-1:
h[f+1]=h[i]
h[i]=0
break
f-=1
if h[f+1]==0 and f<((int(i/4))*4):
h[f+1]=h[i]
h[i]=0
i+=1
i=0
g=0
while i<16:
if h[i]==0:
g=1
break
i+=1
if g==1:
l=random.randint(0,15)
while h[l]!=0:
l=random.randint(0,15)
js=random.randint(1,2)
h[l]=js*2
else:
print("ERROR:你输入的整数不合理")
break点赞0
评论