Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
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
674d45c6
Commit
674d45c6
authored
May 16, 2017
by
Mestari Yousra
Browse files
a relire et tester
parent
0d6bd44a
Changes
1
Hide whitespace changes
Inline
Side-by-side
algo_princpal.py
View file @
674d45c6
hello
\ No newline at end of file
#
# Hello World server in Python
# Binds REP socket to tcp://*:5555
# Expects b"Hello" from client, replies with b"World"
#
import
time
import
zmq
import
numpy
as
np
import
builtsin
def
f
(
c
):
return
ord
(
c
)
-
ord
(
"a"
)
+
1
class
Bateau
:
"définition de la classe bateau"
porte_avion
=
Bateau
()
porte_avion
.
longueur
=
5
porte_avion
.
nom
=
"porte_avion"
croiseur
=
Bateau
()
croiseur
.
longueur
=
4
croiseur
.
nom
=
"croiseur"
contre_torpilleur
=
Bateau
()
contre_torpilleur
.
longueur
=
3
contre_torpilleur
.
nom
=
"contre_torpilleur"
sous_marin
=
Bateau
()
sous_marin
.
longueur
=
3
sous_marin
.
nom
=
"sous marin"
torpilleur
=
Bateau
()
torpilleur
.
longueur
=
2
torpilleur
.
nom
=
"torpilleur"
bateaux
=
[
porte_avion
,
croiseur
,
contre_torpilleur
,
sous_marin
,
torpilleur
]
class
Joueur
:
"définition d'un joueur"
J1
=
Joueur
()
M1
=
np
.
zeros
((
10
,
10
))
J1
.
grille
=
M1
J2
=
Joueur
()
M2
=
np
.
zeros
((
10
,
10
))
J2
.
grille
=
M2
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
REP
)
socket
.
bind
(
"tcp://*:5555"
)
while
True
:
# Wait for next request from client
message
=
socket
.
recv
()
print
(
message
)
if
message
.
decode
()
==
"PLAY"
:
socket
.
send
(
b
"VS J2 or C?"
)
vs
=
socket
.
recv
()
print
(
vs
.
decode
())
socket
.
send
(
b
"Comment vous appelez-vous?"
)
nom
=
socket
.
recv
()
print
(
nom
.
decode
())
J1
.
nom
=
nom
.
decode
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
):
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
:
a
+=
1
if
k
+
elem
.
longueur
>
10
and
M1
[
k
+
case
][
l
]
!=
0
:
b
+=
1
if
l
-
elem
.
longueur
<
0
and
M1
[
k
][
l
-
case
]
!=
0
:
c
+=
1
if
k
-
elem
.
longueur
>
10
and
M1
[
k
][
l
+
case
]
!=
0
:
d
+=
1
if
a
==
0
:
possibilites
.
append
(
chr
(
96
+
k
-
elem
.
longueur
)
+
'l'
)
if
b
==
0
:
possibilites
.
append
(
chr
(
96
+
k
+
elem
.
longueur
)
+
'l'
)
if
c
==
0
:
possibilites
.
append
(
'k'
+
chr
(
96
+
l
-
elem
.
longueur
))
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
])
# Do some 'work'
time
.
sleep
(
1
)
# Send reply back to client
socket
.
send
(
b
"World"
)
Write
Preview
Supports
Markdown
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