import random
import time
board = [["_", "_", "_", "_"],["_", "_", "_", "_"],["_", "_", "_", "_"], ["_", "_", "_", "_"]]
def spit(list):
listcount = 0
while listcount < len(list):
print list[listcount][0], list[listcount][1], list[listcount][2], list[listcount][3]
listcount = listcount + 1
def newtile(list):
blank = list[0].count("_") + list[1].count("_") + list[2].count("_") + list[3].count("_")
position = random.randint(0, blank-1)
counter = 0
lcountera = 0
lcounterb = 0
while counter < position:
checking = list[lcountera][lcounterb]
if checking == "_":
list[lcountera][lcounterb] = "-"
counter = counter + 1
lcounterb = lcounterb + 1
if lcounterb == 4:
lcountera = lcountera + 1
lcounterb = 0
if lcountera == 4:
lcountera = 0
elif checking != "_":
lcounterb = lcounterb + 1
if lcounterb == 4:
lcountera = lcountera + 1
lcounterb = 0
if lcountera == 4:
lcountera = 0
if counter == position:
list[lcountera][lcounterb] = "2"
def fixtiles(list):
fcountera = 0
fcounterb = 0
while fcountera < 4:
fixing = list[fcountera][fcounterb]
if fixing == "-":
list[fcountera][fcounterb] = "_"
fcounterb = fcounterb + 1
if fcounterb == 4:
fcountera = fcountera + 1
fcounterb = 0
def up(list):
uplista = [list[0][0], list[1][0], list[2][0], list[3][0]]
uplistb = [list[0][1], list[1][1], list[2][1], list[3][1]]
uplistc = [list[0][2], list[1][2], list[2][2], list[3][2]]
uplistd = [list[0][3], list[1][3], list[2][3], list[3][3]]
acount = uplista.count("_")
bcount = uplistb.count("_")
ccount = uplistc.count("_")
dcount = uplistd.count("_")
ac = 0
bc = 0
cc = 0
dc = 0
while ac < acount:
uplista.remove("_")
ac = ac + 1
while bc < bcount:
uplistb.remove("_")
bc = bc + 1
while cc < ccount:
uplistc.remove("_")
cc = cc + 1
while dc < dcount:
uplistd.remove("_")
dc = dc + 1
while len(uplista) < 4:
uplista.append("_")
while len(uplistb) < 4:
uplistb.append("_")
while len(uplistc) < 4:
uplistc.append("_")
while len(uplistd) < 4:
uplistd.append("_")
ula = [uplista[0], uplistb[0], uplistc[0], uplistd[0]]
ulb = [uplista[1], uplistb[1], uplistc[1], uplistd[1]]
ulc = [uplista[2], uplistb[2], uplistc[2], uplistd[2]]
uld = [uplista[3], uplistb[3], uplistc[3], uplistd[3]]
list[0] = ula
list[1] = ulb
list[2] = ulc
list[3] = uld
def down(list):
uplista = [list[0][0], list[1][0], list[2][0], list[3][0]]
uplistb = [list[0][1], list[1][1], list[2][1], list[3][1]]
uplistc = [list[0][2], list[1][2], list[2][2], list[3][2]]
uplistd = [list[0][3], list[1][3], list[2][3], list[3][3]]
acount = uplista.count("_")
bcount = uplistb.count("_")
ccount = uplistc.count("_")
dcount = uplistd.count("_")
uplista = uplista[::-1]
uplistb = uplistb[::-1]
uplistc = uplistc[::-1]
uplistd = uplistd[::-1]
ac = 0
bc = 0
cc = 0
dc = 0
while ac < acount:
uplista.remove("_")
ac = ac + 1
while bc < bcount:
uplistb.remove("_")
bc = bc + 1
while cc < ccount:
uplistc.remove("_")
cc = cc + 1
while dc < dcount:
uplistd.remove("_")
dc = dc + 1
while len(uplista) < 4:
uplista.append("_")
while len(uplistb) < 4:
uplistb.append("_")
while len(uplistc) < 4:
uplistc.append("_")
while len(uplistd) < 4:
uplistd.append("_")
uplista = uplista[::-1]
uplistb = uplistb[::-1]
uplistc = uplistc[::-1]
uplistd = uplistd[::-1]
ula = []
ulb = []
ulc = []
uld = []
ula = [uplista[0], uplistb[0], uplistc[0], uplistd[0]]
ulb = [uplista[1], uplistb[1], uplistc[1], uplistd[1]]
ulc = [uplista[2], uplistb[2], uplistc[2], uplistd[2]]
uld = [uplista[3], uplistb[3], uplistc[3], uplistd[3]]
list[0] = ula
list[1] = ulb
list[2] = ulc
list[3] = uld
def left(list):
uplista = list[0]
uplistb = list[1]
uplistc = list[2]
uplistd = list[3]
acount = uplista.count("_")
bcount = uplistb.count("_")
ccount = uplistc.count("_")
dcount = uplistd.count("_")
ac = 0
bc = 0
cc = 0
dc = 0
while ac < acount:
uplista.remove("_")
ac = ac + 1
while bc < bcount:
uplistb.remove("_")
bc = bc + 1
while cc < ccount:
uplistc.remove("_")
cc = cc + 1
while dc < dcount:
uplistd.remove("_")
dc = dc + 1
while len(uplista) < 4:
uplista.append("_")
while len(uplistb) < 4:
uplistb.append("_")
while len(uplistc) < 4:
uplistc.append("_")
while len(uplistd) < 4:
uplistd.append("_")
list[0] = uplista
list[1] = uplistb
list[2] = uplistc
list[3] = uplistd
def right(list):
uplista = list[0]
uplistb = list[1]
uplistc = list[2]
uplistd = list[3]
acount = uplista.count("_")
bcount = uplistb.count("_")
ccount = uplistc.count("_")
dcount = uplistd.count("_")
uplista = uplista[::-1]
uplistb = uplistb[::-1]
uplistc = uplistc[::-1]
uplistd = uplistd[::-1]
ac = 0
bc = 0
cc = 0
dc = 0
while ac < acount:
uplista.remove("_")
ac = ac + 1
while bc < bcount:
uplistb.remove("_")
bc = bc + 1
while cc < ccount:
uplistc.remove("_")
cc = cc + 1
while dc < dcount:
uplistd.remove("_")
dc = dc + 1
while len(uplista) < 4:
uplista.append("_")
while len(uplistb) < 4:
uplistb.append("_")
while len(uplistc) < 4:
uplistc.append("_")
while len(uplistd) < 4:
uplistd.append("_")
uplista = uplista[::-1]
uplistb = uplistb[::-1]
uplistc = uplistc[::-1]
uplistd = uplistd[::-1]
list[0] = uplista
list[1] = uplistb
list[2] = uplistc
list[3] = uplistd
def upadd(list):
clm = 0
while clm < 4:
if list[0][clm] != "_" and list[0][clm] == list[1][clm]:
list[0][clm] = str(int(list[0][clm])*2)
list[1][clm] = "_"
if list[1][clm] != "_" and list[1][clm] == list[2][clm]:
list[1][clm] = str(int(list[1][clm])*2)
list[2][clm] = "_"
if list[2][clm] != "_" and list[2][clm] == list[3][clm]:
list[2][clm] = str(int(list[2][clm])*2)
list[3][clm] = "_"
clm = clm + 1
def downadd(list):
clm = 0
while clm < 4:
if list[3][clm] != "_" and list[3][clm] == list[2][clm]:
list[3][clm] = str(int(list[3][clm])*2)
list[2][clm] = "_"
if list[2][clm] != "_" and list[2][clm] == list[1][clm]:
list[2][clm] = str(int(list[2][clm])*2)
list[1][clm] = "_"
if list[1][clm] != "_" and list[1][clm] == list[0][clm]:
list[1][clm] = str(int(list[1][clm])*2)
list[0][clm] = "_"
clm = clm + 1
def rightadd(list):
row = 0
while row < 4:
if list[row][3] != "_" and list[row][3] == list[row][2]:
list[row][3] = str(int(list[row][3])*2)
list[row][2] = "_"
if list[row][2] != "_" and list[row][2] == list[row][1]:
list[row][2] = str(int(list[row][2])*2)
list[row][1] = "_"
if list[row][1] != "_" and list[row][1] == list[row][0]:
list[row][1] = str(int(list[row][1])*2)
list[row][0] = "_"
row = row + 1
def leftadd(list):
row = 0
while row < 4:
if list[row][0] != "_" and list[row][0] == list[row][1]:
list[row][0] = str(int(list[row][0])*2)
list[row][1] = "_"
if list[row][1] != "_" and list[row][1] == list[row][2]:
list[row][1] = str(int(list[row][1])*2)
list[row][2] = "_"
if list[row][2] != "_" and list[row][2] == list[row][3]:
list[row][2] = str(int(list[row][2])*2)
list[row][3] = "_"
row = row + 1
print">>>2048.exe..."
time.sleep(2)
print"..."
time.sleep(2)
print"..."
time.sleep(2)
print"..."
time.sleep(4)
print'''
eeeeeeee eeeeeeeeeeee 8888 eeeeeeeeee
88 8888 88 8888 88 88
88 8888 88 8888 8888 88eeeeee88
eeeeee88 8888 88 8888eeee8888 8888 8888
88 8888 88 8888 8888 8888
88eeeeee 88eeeeeeee88 8888 8888eeeeee8888
GGE
Good Game
Entertainment
2014
'''
print'''
__ __ ______ _ _
| \/ | | ____| (_) (_)
| \ / | __ _ _ _ | |__ __ ___ __ _ _ __ _ ___ _ __ ___ ___
| |\/| |/ _` | | | | | __| \ \/ / '_ \| | '__| |/ _ \ '_ \ / __/ _ \
| | | | (_| | |_| | | |____ > <| |_) | | | | | __/ | | | (_| __/
|_| |_|\__,_|\__, | |______/_/\_\ .__/|_|_| |_|\___|_| |_|\___\___|
__/ | | |
|___/ |_|
'''
print'''
_____ _ _ _
/ ____|| |(_) | |
| | __ | | _ ___ | |__ ___ ___
| | |_ || || | / __|| '_ \ / _ \/ __|
| |__| || || || (__ | | | || __/\__ \
\_____||_||_| \___||_| |_| \___||___/
'''
print '''well... thats ironic...
'''
play = "yes"
print'''
INSTRUCTIONS:
up : move all tiles up
down : all tiles down
left: you get the idea
right: you are stupid if you dont get the idea
quit : quit ze game, obviously....
'''
newtile(board)
fixtiles(board)
spit(board)
while play == "yes":
input = raw_input("Move : ")
if input == "up":
up(board)
upadd(board)
up(board)
newtile(board)
fixtiles(board)
spit(board)
elif input == "down":
down(board)
downadd(board)
down(board)
newtile(board)
fixtiles(board)
spit(board)
elif input == "left":
left(board)
leftadd(board)
left(board)
newtile(board)
fixtiles(board)
spit(board)
elif input == "right":
right(board)
rightadd(board)
right(board)
newtile(board)
fixtiles(board)
spit(board)
elif input == "quit":
play = "no"
print "you give up too easy..."