Skip to content
Snippets Groups Projects
Commit b9b1e4f4 authored by Garance Guey's avatar Garance Guey
Browse files

random game

parent 10a4be0e
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ def create_grid(n):
game_grid = []
for i in range(n):
#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)
......@@ -100,7 +100,7 @@ def del_zeros(row):
def move_left_bis(row,i=0):
n = len(row)
if i == n-1:
if i >= n-1:
return row
if row[i] == row[i+1]:
row[i] = row[i]*2
......@@ -170,3 +170,40 @@ def is_game_over(grid):
def get_grid_tile_max(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