Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Théo BOUTEMY
siam
Commits
2423470b
Commit
2423470b
authored
May 29, 2021
by
Théo BOUTEMY
Browse files
l'IA fonctionne
le jeu s'arrête proprement à la fin
parent
3eee568a
Changes
2
Hide whitespace changes
Inline
Side-by-side
joueur.py
View file @
2423470b
...
...
@@ -10,8 +10,8 @@ class Joueur(metaclass = ABCMeta):
def
__init__
(
self
,
plateau
):
self
.
plateau
=
plateau
self
.
coup
=
[
"entrer"
,
"sortir"
,
"orientation"
,
"position"
,
"pousser"
]
#coup possible pour l'IA
self
.
numero_pieces
=
[
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
]
#numéro de pieces possibles pour l'IA
self
.
coup
=
[
"entrer"
,
"sortir"
,
"orientation"
,
"position"
,
"position"
,
"pousser"
,
"pousser"
]
#coup possible pour l'IA
self
.
numero_pieces
=
[
'0'
,
'1'
,
'2'
,
'3'
,
'4'
]
#numéro de pieces possibles pour l'IA
self
.
ori_possible
=
[
'droite'
,
'gauche'
,
'demi-tour'
,
'rien'
]
#orientation possible pour l'IA
...
...
@@ -30,8 +30,8 @@ class Joueur(metaclass = ABCMeta):
while
not
bool
:
if
self
.
nom
==
'IA'
:
n
=
self
.
numero_pieces
[
randint
(
0
,
6
)]
coup
=
self
.
coup
[
randint
(
0
,
5
)]
n
=
self
.
numero_pieces
[
randint
(
0
,
5
)]
coup
=
self
.
coup
[
randint
(
0
,
7
)]
else
:
n
=
input
(
'quelle piece voulez-vous bouger: 0? 1? 2? 3? 4?'
)
...
...
@@ -82,8 +82,9 @@ class Joueur(metaclass = ABCMeta):
a
,
b
=
self
.
pieces_du_joueur
()[
n
].
coords
if
a
not
in
[
0
,
1
,
2
,
3
,
4
]
or
b
not
in
[
0
,
1
,
2
,
3
,
4
]:
print
(
'vous ne pouvez pas bouger une piece qui n est pas sur le plateau'
)
if
(
a
not
in
[
0
,
1
,
2
,
3
,
4
]
or
b
not
in
[
0
,
1
,
2
,
3
,
4
]):
if
self
.
nom
!=
'IA'
:
print
(
'vous ne pouvez pas bouger une piece qui n est pas sur le plateau'
)
# ca c'est pour vérifier que la piece est bien sur le plateau avant de la faire boiger
elif
coup
==
'pousser'
:
...
...
@@ -115,7 +116,7 @@ class Joueur(metaclass = ABCMeta):
self
.
pieces_du_joueur
()[
n
].
changement_position
(
i
,
j
,
ori
)
bool
=
self
.
pieces_du_joueur
()[
n
].
tour_effectué
else
:
if
n
not
in
[
0
,
1
,
2
,
3
,
4
]
:
print
(
'numéro de piece non valide'
)
for
i
in
self
.
plateau
:
#ici on s'assure qu'une piece ne soit pas accidentellement sortie du plateau de jeu, auquel cas on la remet à sa position initiale
...
...
@@ -123,8 +124,8 @@ class Joueur(metaclass = ABCMeta):
if
i
.
coords
[
0
]
in
[
-
1
,
5
]
or
i
.
coords
[
1
]
in
[
5
,
-
1
,
-
2
,
6
]:
# une piece est alors sortie du plateau
if
i
.
car
()
in
[
'R'
,
'E'
]:
i
.
sortir
()
if
bool
:
print
(
n
,
coup
)
if
bool
and
self
.
nom
==
'IA'
:
print
(
'l IA a joué le coup'
,
coup
,
'sur la piece numero'
,
n
)
...
...
@@ -151,7 +152,7 @@ class IA(Joueur):
def
__init__
(
self
,
plateau
):
super
().
__init__
(
plateau
)
self
.
nom
=
'IA'
self
.
description
=
'
au tour de
l IA, qui joue les rhinoceros'
self
.
description
=
'l IA, qui joue les rhinoceros'
def
pieces_du_joueur
(
self
):
return
self
.
plateau
.
rhino
...
...
table_de_jeu.py
View file @
2423470b
...
...
@@ -38,6 +38,7 @@ class Plateau(list):
self
.
rhino
=
[]
self
.
joueur1
=
joueur1
self
.
joueur2
=
joueur2
self
.
partie_finie
=
False
...
...
@@ -131,6 +132,7 @@ class Plateau(list):
if
piece
.
coords
[
0
]
==
m
.
coords
[
0
]
+
i
and
piece
.
coords
[
1
]
==
m
.
coords
[
1
]
and
piece
.
orientation
==
'g'
:
winner
=
piece
bool
=
True
self
.
partie_finie
=
True
break
if
m
.
coords
[
0
]
==
5
:
#la montagne est sortie du plateau
...
...
@@ -140,6 +142,7 @@ class Plateau(list):
if
piece
.
coords
[
0
]
==
m
.
coords
[
0
]
-
i
and
piece
.
coords
[
1
]
==
m
.
coords
[
1
]
and
piece
.
orientation
==
'd'
:
winner
=
piece
bool
=
True
self
.
partie_finie
=
True
break
if
m
.
coords
[
1
]
==-
1
:
#la montagne est sortie du plateau
...
...
@@ -149,6 +152,7 @@ class Plateau(list):
if
piece
.
coords
[
1
]
==
m
.
coords
[
1
]
+
i
and
piece
.
coords
[
0
]
==
m
.
coords
[
0
]
and
piece
.
orientation
==
'h'
:
winner
=
piece
bool
=
True
self
.
partie_finie
=
True
break
if
m
.
coords
[
1
]
==
5
:
#la montagne est sortie du plateau
...
...
@@ -158,6 +162,7 @@ class Plateau(list):
if
piece
.
coords
[
1
]
==
m
.
coords
[
1
]
-
i
and
piece
.
coords
[
0
]
==
m
.
coords
[
0
]
and
piece
.
orientation
==
'b'
:
winner
=
piece
bool
=
True
self
.
partie_finie
=
True
break
...
...
@@ -165,18 +170,13 @@ class Plateau(list):
if
bool
==
True
and
winner
.
car
()
==
'R'
:
print
(
'partie finie, le vainqueur est'
,
self
.
joueur2
(
self
).
nom
)
for
piece
in
self
:
piece
=
'F'
if
bool
==
True
and
winner
.
car
()
==
'E'
:
if
bool
==
True
and
winner
.
car
()
==
'E'
:
print
(
'partie finie, le vainqueur est'
,
self
.
joueur1
(
self
).
nom
)
for
piece
in
self
:
piece
=
'F'
...
...
@@ -205,6 +205,8 @@ class Plateau(list):
self
.
joueur1
(
self
).
a_son_tour
()
self
.
unTour
()
self
.
vainqueur
()
if
self
.
partie_finie
:
break
print
(
self
)
...
...
@@ -217,17 +219,15 @@ class Plateau(list):
self
.
joueur2
(
self
).
a_son_tour
()
self
.
unTour
()
self
.
vainqueur
()
if
self
.
partie_finie
:
break
# if M1 not in (range(5),range(5)) or M2 not in (range(5),range(5)) or M3 not in (range(5),range(5)):
# print('fin du jeu, le joueur est ',self.joueur2(self).nom)
# break
print
(
self
)
if
__name__
==
"__main__"
:
plateau
=
Plateau
(
xmax
=
5
,
ymax
=
5
,
nb_montagne
=
3
,
joueur1
=
Theo
,
joueur2
=
IA
)
Plateau
.
jouer
(
plateau
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment