Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2048
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Bianco
2048
Commits
a7571c14
Commit
a7571c14
authored
6 years ago
by
Thomas Bianco
Browse files
Options
Downloads
Plain Diff
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
game2048/grid_2048.py
+39
-2
39 additions, 2 deletions
game2048/grid_2048.py
with
39 additions
and
2 deletions
game2048/grid_2048.py
+
39
−
2
View file @
a7571c14
...
@@ -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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment