Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Behind 2048 by Quandray
def move2048(state,move):
moved=False
if move=="up":
for x in range(4):
for y in range(3):
if not state[y][x]:
for i in range(y+1,4):
if state[i][x]:
state[y][x]=state[i][x]
state[i][x]=0
moved=True
break
if state[y][x]:
for i in range(y+1,4):
if state[i][x]==0: continue
if state[i][x]==state[y][x]:
state[i][x]=0
state[y][x]+=state[y][x]
moved=True
break
if i>y+1:
state[y+1][x]=state[i][x]
state[i][x]=0
moved=True
break
elif move=="down":
for x in range(4):
for y in range(3,0,-1):
if not state[y][x]:
for i in range(y-1,-1,-1):
if state[i][x]:
state[y][x]=state[i][x]
state[i][x]=0
moved=True
break
if state[y][x]:
for i in range(y-1,-1,-1):
if state[i][x]==0: continue
if state[i][x]==state[y][x]:
state[i][x]=0
state[y][x]+=state[y][x]
moved=True
break
if ix+1:
state[y][x+1]=state[y][i]
state[y][i]=0
moved=True
break
if not moved:
for y in range(4):
for x in range(4):
if not state[y][x]: return state
return [['G','A','M','E'],['O','V','E','R'],['G','A','M','E'],['O','V','E','R']]
for y in state:
if 2048 in y:
return [['U','W','I','N'],['U','W','I','N'],['U','W','I','N'],['U','W','I','N']]
for y in range(3,-1,-1):
for x in range(3,-1,-1):
if state[y][x]==0:
state[y][x]=2
return state
Nov. 22, 2014