Skip to content
Snippets Groups Projects
Commit a7571c14 authored by Thomas Bianco's avatar Thomas Bianco
Browse files

Merge branch 'master' of gitlab.viarezo.fr:2018biancot/2048

parents ee991d2b b9b1e4f4
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ def create_grid(n): ...@@ -8,7 +8,7 @@ def create_grid(n):
game_grid = [] game_grid = []
for i in range(n): for i in range(n):
#crée le bon nombre de ligne #crée le bon nombre de ligne
game_grid.append([' ']*n) #crée le bon nombre de colonnes game_grid.append([0]*n) #crée le bon nombre de colonnes
return (game_grid) return (game_grid)
...@@ -125,7 +125,7 @@ def del_zeros(row): ...@@ -125,7 +125,7 @@ def del_zeros(row):
def move_left_bis(row,i=0): def move_left_bis(row,i=0):
n = len(row) n = len(row)
if i == n-1: if i >= n-1:
return row return row
if row[i] == row[i+1]: if row[i] == row[i+1]:
row[i] = row[i]*2 row[i] = row[i]*2
...@@ -195,3 +195,40 @@ def is_game_over(grid): ...@@ -195,3 +195,40 @@ def is_game_over(grid):
def get_grid_tile_max(grid): def get_grid_tile_max(grid):
return max(get_all_tiles(grid)) return max(get_all_tiles(grid))
def did_you_win (grid):
return (get_grid_tile_max(grid)>=2048)
#Fonctinnalité 6
def list_moove_possible (grid):
list_bool=move_possible(grid)
list_final=[]
if list_bool[0]:
list_final.append("left")
if list_bool[1]:
list_final.append("right")
if list_bool[2]:
list_final.append("up")
if list_bool[3]:
list_final.append("down")
return(list_final)
def random_play():
#on suppose que le jeu par defaut comprend une grille de 4x4
grid_game=init_game(4)
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4))
while not is_game_over(grid_game):
d=rd.choice(list_moove_possible(grid_game))
grid_game=move_grid(grid_game,d)
grid_game=grid_add_new_tile(grid_game)
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4))
print("\n***********************************\n")
if did_you_win(grid_game):
print("CONGRATS ! YOU WON !!!")
else :
print ("YOU FAIL, TRY AGAIN")
return()
random_play()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment