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
645b85e0
Commit
645b85e0
authored
6 years ago
by
Garance Guey
Browse files
Options
Downloads
Plain Diff
dowload_
parents
da93bef4
c7f7a81e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
game2048/grid_2048.py
+39
-2
39 additions, 2 deletions
game2048/grid_2048.py
game2048/test_grid_2048.py
+11
-0
11 additions, 0 deletions
game2048/test_grid_2048.py
with
50 additions
and
2 deletions
game2048/grid_2048.py
+
39
−
2
View file @
645b85e0
...
...
@@ -87,6 +87,31 @@ def grid_to_string_with_size_and_theme(grid, theme,n):
def
long_value_with_theme
(
grid
,
theme
):
return
max
(
len
(
theme
[
v
])
for
v
in
get_all_tiles
(
grid
))
# FONCTIONNALITE 3
def
read_player_command
():
deplacements
=
{
'
g
'
:
"
left
"
,
'
d
'
:
"
right
"
,
'
h
'
:
"
up
"
,
'
b
'
:
"
down
"
}
move
=
input
(
"
Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)):
"
)
while
move
not
in
[
'
g
'
,
'
d
'
,
'
h
'
,
'
b
'
]:
move
=
input
(
"
Commande invalide.
\n
Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)):
"
)
return
deplacements
[
move
]
def
read_size_grid
():
size
=
input
(
"
Choisissez la taille de la grille :
"
)
while
True
:
try
:
size
=
int
(
size
)
except
:
size
=
input
(
"
Taille invalide, choisissez un nombre entier.
\n
Choisissez la taille de la grille :
"
)
else
:
break
return
size
def
read_theme_grid
():
theme
=
input
(
"
Choisissez le numéro du thème :
"
)
while
theme
not
in
[
'
0
'
,
'
1
'
,
'
2
'
]:
theme
=
input
(
"
Ce thème n
'
existe pas !
\n
Choisissez le numéro du thème :
"
)
return
THEMES
[
theme
]
# FONCTIONNALITE 4
...
...
@@ -189,8 +214,12 @@ def did_you_win (grid):
#Fonctinnalité 6
<<<<<<<
HEAD
def
list_moove_possible
(
grid
):
#renvoie la liste des deplacements possibles
=======
def
list_move_possible
(
grid
):
>>>>>>>
c7f7a81e42fe1f954e38b492c9d251128aa9cf68
list_bool
=
move_possible
(
grid
)
list_final
=
[]
if
list_bool
[
0
]:
...
...
@@ -213,6 +242,7 @@ def random_play():
#phase de jeu
while
not
is_game_over
(
grid_game
):
<<<<<<<
HEAD
#pour chaque tour
d
=
rd
.
choice
(
list_moove_possible
(
grid_game
))
#on choisi un mouvement
...
...
@@ -222,6 +252,13 @@ def random_play():
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
"
)
>>>>>>>
c7f7a81e42fe1f954e38b492c9d251128aa9cf68
if
did_you_win
(
grid_game
):
print
(
"
CONGRATS ! YOU WON !!!
"
)
else
:
...
...
This diff is collapsed.
Click to expand it.
game2048/test_grid_2048.py
+
11
−
0
View file @
645b85e0
from
game2048.grid_2048
import
*
from
pytest
import
*
# FONCTIONNALITE 1
def
test_create_grid
():
assert
create_grid
(
0
)
==
[]
assert
create_grid
(
1
)
==
[[
'
'
]]
...
...
@@ -40,6 +42,8 @@ def test_init_game():
assert
2
or
4
in
tiles
assert
len
(
get_empty_tiles_positions
(
grid
))
==
14
#FONCTIONNALITE 2
#def test_grid_to_string():
# a =""" === === === ===
# | | | | |
...
...
@@ -62,6 +66,13 @@ def test_long_value_with_theme():
assert
long_value_with_theme
(
grid
,
THEMES
[
"
1
"
])
==
2
assert
long_value_with_theme
(
grid
,
THEMES
[
"
2
"
])
==
1
#FONCTIONNALITE 3
def
test_read_player_command
(
monkeypatch
):
monkeypatch
.
setattr
(
'
builtins.input
'
,
lambda
x
:
"
d
"
)
# FONCTIONNALITE 4
def
test_move_row_left
():
assert
move_row_left
([
0
,
0
,
0
,
2
])
==
[
2
,
0
,
0
,
0
]
assert
move_row_left
([
0
,
2
,
0
,
4
])
==
[
2
,
4
,
0
,
0
]
...
...
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