Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet AP
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
Thierno Abdoulaye Diallo
Projet AP
Commits
b85b3861
Commit
b85b3861
authored
2 months ago
by
diallo
Browse files
Options
Downloads
Patches
Plain Diff
mise à jour du fichier class_vehicule.py
parent
44e43951
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
class_plateau.py
+83
-37
83 additions, 37 deletions
class_plateau.py
with
83 additions
and
37 deletions
class_plateau.py
+
83
−
37
View file @
b85b3861
from
class_vehicule
import
Vehicule
class
Plateau
():
"""
à_remplacer_par_ce_que_fait_la_classe
Exemple(s) :
$$$
$$$ plateau = Plateau()
$$$ plateau.position_vehicules()
set()
$$$ voiture_rouge = Vehicule(
'
Rouge
'
, (5, 0), 2,
'
horizontal
'
)
$$$ plateau.est_position_valide(voiture_rouge)
True
$$$ voiture_bleu = Vehicule(
'
Bleu
'
, (2, 3), 1,
'
vertical
'
)
$$$ plateau.sont_en_chevauchement(voiture_bleu)
False
$$$ voiture_vert = Vehicule(
'
vert
'
, (2, 3),1 ,
'
horizontal
'
)
$$$ plateau.sont_en_chevauchement(voiture_vert)
False
"""
def
__init__
(
self
):
...
...
@@ -14,17 +26,15 @@ class Plateau():
"""
self
.
taille
=
(
6
,
6
)
self
.
liste_vehicule
=
[]
GRILLE_VIDE
=
[[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
],[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
],[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
],[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
],[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
],[
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
]]
def
initialiser_grille
()
->
None
:
def
__repr__
(
self
):
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
for
lignes
in
GRILLE_VIDE
:
print
(
'
|
'
+
lignes
[
0
]
+
'
|
'
+
lignes
[
1
]
+
'
|
'
+
lignes
[
2
]
+
'
|
'
+
lignes
[
3
]
+
'
|
'
+
lignes
[
4
]
+
'
|
'
+
lignes
[
5
]
+
'
|
'
)
return
f
"
(
{
self
.
liste_vehicule
}
)
"
def
position_vehicules
(
self
):
"""
renvoie un ensemble contenant la position de chaque vehicule
...
...
@@ -33,60 +43,96 @@ class Plateau():
$$$
"""
res
=
set
()
for
vehicule
in
liste_vehicule
:
for
vehicule
in
self
.
liste_vehicule
:
x
,
y
=
vehicule
.
position
for
i
in
range
(
vehicule
.
taille
):
for
i
in
range
(
vehicule
.
longueur
):
if
vehicule
.
orientation
==
'
horizontal
'
:
res
.
add
((
x
,
y
+
i
))
elif
vehicule
.
orientation
==
'
vertical
'
:
res
.
add
((
x
+
i
,
y
))
return
res
def
ajout_vehicule
(
self
,
vehicule
):
"""
ajoute le vehicule à sa position dans le plateau
def
sont_en_chevauchement
(
self
,
vehicule
:
Vehicule
):
"""
renvoie True si les deux vehicules se chevaussent et False sinon
Précondition :
Exemple(s) :
$$$
"""
if
est_position_valide
(
vehicule
):
self
.
liste_vehicule
.
add
(
vehicule
)
else
:
print
(
"
la position du vehicule est invalide
"
)
positions
=
self
.
position_vehicules
()
coordonnees_vehicule
=
vehicule
.
liste_coordonnees
for
c
in
coordonnees_vehicule
:
if
c
in
positions
:
return
True
return
False
def
est_position_valide
(
self
,
vehicule
):
def
est_position_valide
(
self
,
vehicule
:
Vehicule
):
"""
verifie si la position du vehicule est valide
Précondition :
Exemple(s) :
$$$
"""
self
.
position
=
vehicule
.
position
x
,
y
=
self
.
position
i
=
0
while
i
<
vehicule
.
taille
:
if
vehicule
.
orientation
==
'
horizontal
'
:
if
(
x
,
y
+
i
)
in
self
.
position_vehicules
()
or
y
+
i
>=
self
.
taille
[
0
]:
return
False
elif
vehicule
.
orientation
==
'
vertical
'
:
if
(
x
,
y
+
i
)
in
self
.
position_vehicules
()
or
y
+
i
>=
self
.
taille
[
1
]:
return
False
return
True
def
est_voiture_rouge
(
self
,
liste_vehicule
)
->
bool
:
"""
verifie si c
'
est bel et bien la voiture rouge et si elle peux sortir par la droite
liste_positions
=
vehicule
.
liste_coordonnees
return
all
(
position
[
0
]
<
6
and
position
[
1
]
<
6
for
position
in
liste_positions
)
def
ajout_vehicule
(
self
,
vehicule
:
Vehicule
):
"""
ajoute le vehicule à sa position dans le plateau
Précondition :
Exemple(s) :
$$$
"""
for
vehicule
in
self
.
liste_vehicule
:
if
couleur
.
vehicule
==
'
R
'
:
x
,
y
=
vehicule
.
position
if
vehicule
.
orientation
==
'
horizontal
'
and
y
+
vehicule
.
taille
>=
self
.
taille
[
0
]:
return
True
return
False
if
self
.
sont_en_chevauchement
(
vehicule
):
print
(
f
"
le vehicule
{
vehicule
.
couleur
}
est en chevauchement avec un autre vehicule .
"
)
else
:
self
.
liste_vehicule
.
append
((
vehicule
))
def
affiche_grille
(
self
):
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
\ No newline at end of file
grille
=
[[
"
"
for
_
in
range
(
6
)]
for
_
in
range
(
6
)]
for
vehicule
in
self
.
liste_vehicule
:
x
,
y
=
vehicule
.
position
position_valide
=
True
for
i
in
range
(
vehicule
.
longueur
):
if
vehicule
.
orientation
==
"
horizontal
"
:
if
not
(
0
<=
x
<
len
(
grille
)
and
0
<=
y
+
i
<
len
(
grille
[
0
])):
position_valide
=
False
elif
vehicule
.
orientation
==
"
vertical
"
:
if
not
(
0
<=
x
+
i
<
len
(
grille
)
and
0
<=
y
<
len
(
grille
[
0
])):
position_valide
=
False
if
position_valide
:
for
i
in
range
(
vehicule
.
longueur
):
if
vehicule
.
orientation
==
"
horizontal
"
:
grille
[
x
][
y
+
i
]
=
vehicule
.
couleur
[
0
]
elif
vehicule
.
orientation
==
"
vertical
"
:
grille
[
x
+
i
][
y
]
=
vehicule
.
couleur
[
0
]
else
:
print
(
f
"
Position invalide pour le véhicule
{
vehicule
.
couleur
}
, il ne sera pas ajouté.
"
)
for
ligne
in
grille
:
print
(
"
+
"
+
"
---+
"
*
6
)
print
(
"
|
"
+
"
|
"
.
join
(
ligne
)
+
"
|
"
)
print
(
"
+
"
+
"
---+
"
*
6
)
if
__name__
==
'
__main__
'
:
# éxécuté qd ce module n'est pas initialisé par un import.
plateau
=
Plateau
()
#liste_vehicules = [Vehicule("Rouge", (2, 0), 2, "horizontal"),Vehicule("Bleu", (0, 3), 3, "vertical"),]
voiture_rouge
=
Vehicule
(
'
Rouge
'
,
(
3
,
5
),
3
,
'
vertical
'
)
voiture_bleu
=
Vehicule
(
'
Bleu
'
,
(
3
,
4
),
1
,
'
vertical
'
)
# Position corrigée
voiture_vert
=
Vehicule
(
'
vert
'
,
(
4
,
2
),
2
,
'
horizontal
'
)
voiture_orange
=
Vehicule
(
'
Orange
'
,
(
1
,
3
),
2
,
'
vertical
'
)
plateau
.
ajout_vehicule
(
voiture_rouge
)
plateau
.
ajout_vehicule
(
voiture_bleu
)
plateau
.
ajout_vehicule
(
voiture_vert
)
plateau
.
ajout_vehicule
(
voiture_orange
)
plateau
.
affiche_grille
()
\ 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