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

ajout run_2048

parent b84ecf13
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
<option value="E501" /> <option value="E501" />
<option value="W29" /> <option value="W29" />
<option value="E501" /> <option value="E501" />
<option value="W29" />
<option value="E501" />
</list> </list>
</option> </option>
</inspection_tool> </inspection_tool>
......
File added
File added
...@@ -182,6 +182,7 @@ def is_game_over(grid): ...@@ -182,6 +182,7 @@ 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): def did_you_win (grid):
return (get_grid_tile_max(grid)>=2048) return (get_grid_tile_max(grid)>=2048)
...@@ -203,33 +204,3 @@ def list_move_possible (grid): ...@@ -203,33 +204,3 @@ def list_move_possible (grid):
return(list_final) return(list_final)
def random_play():
#on suppose que le jeu par defaut comprend une grille de 4x4
#phase d'initialisation du jeu
grid_game=init_game(4)
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4))
#phase de jeu
while not is_game_over(grid_game):
#pour chaque tour
d=rd.choice(list_move_possible(grid_game)) #on choisi un mouvement
grid_game=move_grid(grid_game,d) #on le fait
grid_game=grid_add_new_tile(grid_game) #une tuile se crée
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4)) #on affuche le résulat
print("\n***********************************\n") #permet aux différentes grilles d'être plus lisible
#vérification si le jeu est gagnant ou perdant
d=rd.choice(list_move_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()
from grid_2048 import *
from textual_2048 import *
def random_play():
#on suppose que le jeu par defaut comprend une grille de 4x4
#phase d'initialisation du jeu
grid_game=init_game(4)
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4))
#phase de jeu
while not is_game_over(grid_game):
#pour chaque tour
d=rd.choice(list_move_possible(grid_game)) #on choisi un mouvement
grid_game=move_grid(grid_game,d) #on le fait
grid_game=grid_add_new_tile(grid_game) #une tuile se crée
print(grid_to_string_with_size_and_theme(grid_game,THEMES["0"],4)) #on affuche le résulat
print("\n***********************************\n") #permet aux différentes grilles d'être plus lisible
#vérification si le jeu est gagnant ou perdant
if did_you_win(grid_game):
print("CONGRATS ! YOU WON !!!")
else :
print ("YOU FAIL, TRY AGAIN")
return
def game_play():
# Saisie des paramètres
size = read_size_grid()
theme = read_theme_grid()
# Initialisation
grid = init_game(size)
print(grid_to_string_with_size_and_theme(grid,theme,size))
# Phase de jeu
while not is_game_over(grid):
direction = read_player_command() # Choix de la direction
possibles = list_move_possible(grid)
if direction in possibles:
grid = move_grid(grid,direction)
grid = grid_add_new_tile(grid)
print(grid_to_string_with_size_and_theme(grid,theme,size))
print("\n***********************************\n")
# Test de victoire
if did_you_win(grid_game):
print("CONGRATS ! YOU WON !!!")
else :
print ("YOU FAIL, TRY AGAIN")
return
THEMES = {"0": {"name": "Default", 0: "", 2: "2", 4: "4", 8: "8", 16: "16", 32:"32", 64: "64", 128: "128", 256: "256", 512: "512", 1024: "1024", 2048: "2048",4096: "4096", 8192: "8192"}, "1": {"name": "Chemistry", 0: "", 2: "H", 4: "He", 8:"Li", 16: "Be", 32: "B", 64: "C", 128: "N", 256: "O", 512: "F", 1024: "Ne", 2048:"Na", 4096: "Mg", 8192: "Al"}, "2": {"name": "Alphabet", 0: "", 2: "A", 4: "B", 8:"C", 16: "D", 32: "E", 64: "F", 128: "G", 256: "H", 512: "I", 1024: "J", 2048: "K",4096: "L", 8192: "M"}}
# FONCTIONNALITE 3 # FONCTIONNALITE 3
def read_player_command(): def read_player_command():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment