Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-WALLOT-Angy
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Angy Wallot
AP-WALLOT-Angy
Commits
530700c1
Commit
530700c1
authored
1 year ago
by
Angy Wallot
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab-ssh.univ-lille.fr:angy.wallot.etu/ap-wallot-angy
parents
8035ae64
86668bc2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tp.5/minesweeper.py
+39
-14
39 additions, 14 deletions
tp.5/minesweeper.py
tp.5/somme.py
+12
-0
12 additions, 0 deletions
tp.5/somme.py
with
51 additions
and
14 deletions
tp.5/minesweeper.py
100755 → 100644
+
39
−
14
View file @
530700c1
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
"""
"""
:mod:`minesweeper` module
:mod:`minesweeper` module
:author:
Wallot Angy
:author:
KINADINOVA Dariya
:date: 14/02/24
:date: 14/02/24
...
@@ -61,12 +61,13 @@ def neighborhood(x: int, y: int, width: int, height: int) -> list[tuple[int, int
...
@@ -61,12 +61,13 @@ def neighborhood(x: int, y: int, width: int, height: int) -> list[tuple[int, int
$$$ neighborhood(3, 9, 10, 10)
$$$ neighborhood(3, 9, 10, 10)
[(2, 8), (2, 9), (3, 8), (4, 8), (4, 9)]
[(2, 8), (2, 9), (3, 8), (4, 8), (4, 9)]
"""
"""
tout_les_voisins
=
[(
x
-
1
,
y
-
1
),(
x
-
1
,
y
),(
x
-
1
,
y
+
1
),(
x
,
y
-
1
),(
x
,
y
+
1
),(
x
+
1
,
y
-
1
),(
x
+
1
,
y
),(
x
+
1
,
y
+
1
)]
res
=
[
(
xn
,
yn
)
for
xn
,
yn
in
[(
x
-
1
,
y
-
1
),
(
x
-
1
,
y
),
(
x
-
1
,
y
+
1
),
res
=
[]
(
x
,
y
-
1
),
(
x
,
y
+
1
),(
x
+
1
,
y
-
1
),
(
x
+
1
,
y
),
for
(
a
,
b
)
in
tout_les_voisins
:
(
x
+
1
,
y
+
1
)]
if
a
>=
0
and
b
>=
0
and
a
<
width
and
b
<
height
:
if
0
<=
xn
<
width
and
0
<=
yn
<
height
]
res
+=
(
a
,
b
),
return
res
return
res
class
Minesweeper
():
class
Minesweeper
():
"""
"""
...
@@ -111,8 +112,12 @@ class Minesweeper():
...
@@ -111,8 +112,12 @@ class Minesweeper():
self
.
width
=
width
self
.
width
=
width
self
.
height
=
height
self
.
height
=
height
self
.
nbombs
=
nbombs
self
.
nbombs
=
nbombs
self
.
grid
=
[[
Cell
()
for
x
in
range
(
width
)]
for
y
in
range
(
height
)]
self
.
state
=
GameState
.
unfinished
self
.
state
=
GameState
.
unfinished
self
.
grid
=
[[
Cell
()
for
x
in
range
(
width
)]
for
y
in
range
(
height
)]
bombs
=
random
.
sample
(
range
(
width
*
height
),
nbombs
)
for
i
in
bombs
:
x
,
y
=
(
i
%
width
),
i
//
width
self
.
_put_a_bomb_at
(
x
,
y
)
def
get_cell
(
self
,
x
:
int
,
y
:
int
)
->
Cell
:
def
get_cell
(
self
,
x
:
int
,
y
:
int
)
->
Cell
:
"""
"""
...
@@ -124,14 +129,14 @@ class Minesweeper():
...
@@ -124,14 +129,14 @@ class Minesweeper():
$$$ sum(1 for x in range(20) for y in range(10) if game.get_cell(x, y).is_bomb)
$$$ sum(1 for x in range(20) for y in range(10) if game.get_cell(x, y).is_bomb)
4
4
"""
"""
return
self
.
grid
[
x
][
y
]
return
self
.
grid
[
y
][
x
]
def
_put_a_bomb_at
(
self
,
x
:
int
,
y
:
int
):
def
_put_a_bomb_at
(
self
,
x
:
int
,
y
:
int
):
"""
"""
this method change the cells
'
s state at x, y to a bomb,
this method change the cells
'
s state at x, y to a bomb,
if the cell is already a bomb, nothing appen
d
.
if the cell is already a bomb, nothing
h
appen
s
.
otherwise it change cell
'
s state and increments by one every
otherwise it change
s
cell
'
s state and increments by one every
cells in its neighborhood.
cells in its neighborhood.
precondition: 0 <= x < self.width and 0 <= y < self.height
precondition: 0 <= x < self.width and 0 <= y < self.height
...
@@ -149,7 +154,11 @@ class Minesweeper():
...
@@ -149,7 +154,11 @@ class Minesweeper():
$$$ all(game.get_cell(x, y).nbombs_in_neighborhood == 1 for x, y in voisins)
$$$ all(game.get_cell(x, y).nbombs_in_neighborhood == 1 for x, y in voisins)
True
True
"""
"""
...
if
self
.
get_cell
(
x
,
y
).
is_bomb
==
False
:
self
.
get_cell
(
x
,
y
).
set_bomb
()
for
i
,
j
in
neighborhood
(
x
,
y
,
self
.
width
,
self
.
height
):
self
.
get_cell
(
i
,
j
).
incr_number_of_bombs_in_neighborhood
()
def
all_cells_are_revealed_or_bomb
(
self
)
->
bool
:
def
all_cells_are_revealed_or_bomb
(
self
)
->
bool
:
"""
"""
...
@@ -158,7 +167,12 @@ class Minesweeper():
...
@@ -158,7 +167,12 @@ class Minesweeper():
précondition: none
précondition: none
"""
"""
...
for
i
in
range
(
self
.
width
):
for
j
in
range
(
self
.
height
):
self
.
get_cell
(
i
,
j
)
if
not
self
.
get_cell
(
i
,
j
).
is_bomb
and
not
self
.
get_cell
(
i
,
j
).
is_revealed
:
return
False
return
True
def
reveal_all_cells_from
(
self
,
x
,
y
):
def
reveal_all_cells_from
(
self
,
x
,
y
):
"""
"""
...
@@ -196,8 +210,19 @@ class Minesweeper():
...
@@ -196,8 +210,19 @@ class Minesweeper():
$$$ game.state
$$$ game.state
GameState.losing
GameState.losing
"""
"""
...
if
self
.
get_cell
(
x
,
y
).
is_bomb
:
self
.
state
=
GameState
.
losing
elif
not
self
.
get_cell
(
x
,
y
).
is_revealed
:
self
.
get_cell
(
x
,
y
).
reveal
()
if
self
.
get_cell
(
x
,
y
).
nbombs_in_neighborhood
==
0
:
for
i
,
j
in
neighborhood
(
x
,
y
,
self
.
width
,
self
.
height
):
self
.
reveal_all_cells_from
(
i
,
j
)
else
:
self
.
all_cells_are_revealed_or_bomb
()
self
.
state
=
GameState
.
winning
# game = Minesweeper(20, 10, 4)
# game.state == GameState.unfinished
if
(
__name__
==
'
__main__
'
):
if
(
__name__
==
'
__main__
'
):
import
apl1test
import
apl1test
...
...
This diff is collapsed.
Click to expand it.
tp.5/somme.py
0 → 100644
+
12
−
0
View file @
530700c1
import
sys
def
main
():
a
=
int
(
sys
.
argv
[
1
])
b
=
int
(
sys
.
argv
[
2
])
print
(
f
"
la somme de
{
a
}
et
{
b
}
est
{
a
+
b
}
"
)
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
!=
3
:
print
(
"
Usage : python3 somme.py <a> <b>
"
)
else
:
main
()
\ No newline at end of file
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