Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mestari Yousra
NOTRE_PROJEEET
Commits
66b82a3f
Commit
66b82a3f
authored
May 23, 2017
by
Trogno Lucas
Browse files
Algorithme modifié
parent
674d45c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
algo_princpal.py
View file @
66b82a3f
#
# Hello World server in Python
# Binds REP socket to tcp://*:5555
# Expects b"Hello" from client, replies with b"World"
...
...
@@ -9,13 +6,13 @@
import
time
import
zmq
import
numpy
as
np
import
built
s
in
import
builtin
s
def
f
(
c
):
return
ord
(
c
)
-
ord
(
"
a
"
)
+
1
return
ord
(
c
)
-
ord
(
"
A
"
)
+
1
class
Bateau
:
"d
é
finition de la classe bateau"
"d
e
finition de la classe bateau"
porte_avion
=
Bateau
()
porte_avion
.
longueur
=
5
...
...
@@ -40,7 +37,7 @@ torpilleur.nom="torpilleur"
bateaux
=
[
porte_avion
,
croiseur
,
contre_torpilleur
,
sous_marin
,
torpilleur
]
class
Joueur
:
"d
é
finition d'un joueur"
"d
e
finition d'un joueur"
J1
=
Joueur
()
M1
=
np
.
zeros
((
10
,
10
))
...
...
@@ -50,58 +47,94 @@ M2=np.zeros((10,10))
J2
.
grille
=
M2
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
R
EP
)
socket
=
context
.
socket
(
zmq
.
R
OUTER
)
socket
.
bind
(
"tcp://*:5555"
)
while
True
:
# Wait for next request from client
message
=
socket
.
recv
()
print
(
message
)
addr
,
empty
,
message
=
socket
.
recv
_multipart
()
print
(
message
.
decode
()
)
if
message
.
decode
()
==
"PLAY"
:
socket
.
send
(
b
"VS J2 or C?"
)
vs
=
socket
.
recv
()
socket
.
send
_multipart
(
b
"VS J2 or C?"
)
addr
,
empty
,
msg
=
socket
.
recv
_multipart
()
print
(
vs
.
decode
())
socket
.
send
(
b
"Comment vous appelez-vous?"
)
nom
=
socket
.
recv
()
socket
.
send
_multipart
(
b
"Comment vous appelez-vous?"
)
addr
,
empty
,
msg
=
socket
.
recv
_multipart
()
print
(
nom
.
decode
())
J1
.
nom
=
nom
.
decode
#constituer sa grille
for
elem
in
bateaux
:
question
=
"Ou voulez-vous mettre la tete de "
+
elem
.
nom
+
"?"
socket
.
send
(
question
.
encode
())
tete
=
socket
.
recv
()
k
=
f
(
tete
[
0
])
l
=
int
(
tete
[
1
])
assert
M1
[
k
][
l
]
==
0
possibilites
=
[]
for
possibility
in
range
(
4
):
question
=
question
.
encode
()
socket
.
send_multipart
[
addr
,
question
]
tete
=
addr
,
empty
,
msg
=
socket
.
recv_multipart
()
tete
=
tete
.
decode
()
k
=
f
(
tete
[
0
])
-
1
l
=
int
(
tete
[
1
])
-
1
if
M1
[
k
][
l
]
!=
0
:
socket
.
send_multipart
(
b
"Cette case est deja occupee"
)
bateaux
.
append
(
elem
)
else
:
possibilites
=
[]
a
,
b
,
c
,
d
=
0
,
0
,
0
,
0
for
case
in
range
(
0
,
elem
.
longueur
):
if
k
-
elem
.
longueur
<
0
or
M1
[
k
-
case
][
l
]
!=
0
:
#horizontal a gauche
if
k
-
elem
.
longueur
<-
1
or
M1
[
k
-
case
][
l
]
!=
0
:
a
+=
1
if
k
+
elem
.
longueur
>
10
and
M1
[
k
+
case
][
l
]
!=
0
:
#horizontal a droite
if
k
+
elem
.
longueur
>
10
or
M1
[
k
+
case
][
l
]
!=
0
:
b
+=
1
if
l
-
elem
.
longueur
<
0
and
M1
[
k
][
l
-
case
]
!=
0
:
#vertical en haut
if
l
-
elem
.
longueur
<-
1
or
M1
[
k
][
l
-
case
]
!=
0
:
c
+=
1
if
k
-
elem
.
longueur
>
10
and
M1
[
k
][
l
+
case
]
!=
0
:
#vertical en bas
if
l
+
elem
.
longueur
>
10
or
M1
[
k
][
l
+
case
]
!=
0
:
d
+=
1
if
a
==
0
:
possibilites
.
append
(
chr
(
9
6
+
k
-
elem
.
longueur
)
+
'l'
)
possibilites
.
append
(
chr
(
6
4
+
k
-
elem
.
longueur
+
2
)
+
str
(
l
+
1
)
)
if
b
==
0
:
possibilites
.
append
(
chr
(
9
6
+
k
+
elem
.
longueur
)
+
'l'
)
possibilites
.
append
(
chr
(
6
4
+
k
+
elem
.
longueur
)
+
str
(
l
+
1
)
)
if
c
==
0
:
possibilites
.
append
(
'k'
+
chr
(
96
+
l
-
elem
.
longueur
))
possibilites
.
append
(
chr
(
k
+
65
)
+
str
(
l
-
elem
.
longueur
+
2
))
if
d
==
0
:
possibilites
.
append
(
'k'
+
chr
(
96
+
l
+
elem
.
longueur
))
question
=
"Ou voulez-vous mettre la queue de "
+
elem
.
nom
+
" parmis les possibilités?"
print
(
possibilites
)
socket
.
send
(
question
.
encode
())
queue
=
socket
.
recv
()
m
=
f
(
tete
[
0
])
n
=
int
(
tete
[
1
])
possibilites
.
append
(
chr
(
k
+
65
)
+
str
(
l
+
elem
.
longueur
))
poss
=
''
for
possi
in
possibilites
:
poss
+=
possi
+
', '
poss
=
poss
[:
-
2
]
print
(
'possibilites = '
+
poss
)
question
=
"Ou voulez-vous mettre la queue de "
+
elem
.
nom
+
" parmi les possibilites : "
+
poss
+
" ?"
socket
.
send_multipart
(
question
.
encode
())
queue
=
addr
,
empty
,
msg
=
socket
.
recv_multipart
()
queue
=
queue
.
decode
()
m
=
f
(
queue
[
0
])
-
1
n
=
int
(
queue
[
1
])
-
1
if
k
==
m
:
for
i
in
range
(
min
(
l
,
n
),
max
(
l
,
n
)
+
1
):
M1
[
k
][
i
]
=
1
if
l
==
n
:
for
i
in
range
(
min
(
k
,
m
),
max
(
k
,
m
)
+
1
):
M1
[
i
][
l
]
=
1
print
(
M1
)
#frapper l'autre grille
socket
.
send_multipart
(
b
"Quelle case frapper?"
)
case
=
addr
,
empty
,
msg
=
socket
.
recv_multipart
()
case
=
case
.
decode
()
print
(
case
)
k
=
f
(
case
[
0
])
-
1
l
=
int
(
case
[
1
])
-
1
while
M2
[
k
][
l
]
==
1
:
M2
[
k
][
l
]
=
2
socket
.
send_multipart
(
b
"Touche! Quelle case frapper ?"
)
case
=
addr
,
empty
,
msg
=
socket
.
recv_multipart
()
case
=
case
.
decode
()
k
=
f
(
case
[
0
])
-
1
l
=
int
(
case
[
1
])
-
1
socket
.
send_multipart
(
b
"Manque!"
)
# Do some 'work'
time
.
sleep
(
1
)
# Send reply back to client
socket
.
send
(
b
"World"
)
socket
.
send
(
b
"World"
)
\ No newline at end of file
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