Commit 2c14a99b authored by Mestari Yousra's avatar Mestari Yousra
Browse files

algo fonctionnel

parent 44e40da7
......@@ -2,55 +2,48 @@ import time
import zmq
import numpy as np
import builtins
from grille_serveur import f
context = zmq.Context()
socket = context.socket(zmq.ROUTER)
socket.bind("tcp://*:5555")
def frappe(J,M,position):
socket.send_multipart([J.addr,b'',b"Quelle case frapper?"])
J.addr,empty,case=socket.recv_multipart()
case=case.decode()
print(case)
def frappe(J,case,M,position):
k=f(case[0])-1
l=int(case[1])-1
while M2[k][l]==1:
M2[k][l]=2
position[(k,l)]=position[(k,l)][0],2
l=int(case[1])-1
if len(case)==3:
l=9
message=''
victoire=''
if M[k][l]==1:
M[k][l]=2
position[(k,l)]=position[(k,l)][0],position[(k,l)][1],2
elem=position[(k,l)][0]
print(M2)
longueur=position[(k,l)][1]
print(M)
#verifier si le bateau est coule
i=0
for cle in position.keys():
if position[cle][0]==elem and position[cle][1]==2:
if position[cle][0]==elem and position[cle][2]==2:
i+=1
if i==elem.longueur:
coule=elem.nom+" coule!"
socket.send_multipart([J.addr,b'',coule.encode()])
if i==longueur:
message=message + elem+" coule! \n"
for cle in position.keys():
if position[cle][0]==elem:
M2[cle[0]][cle[1]]=3
position[cle]=position[cle][0],3
M[cle[0]][cle[1]]=3
position[cle]=position[cle][0],position[(k,l)][1],3
print(M)
#verifier si le jeu est gagne
j=0
for cle in position.keys():
if position[cle][1]==3:
if position[cle][2]==3:
j+=1
if j==18:
victoire= J1.nom+" a gagne!"
socket.send_multipart([J.addr,b"",victoire])
message="jeu fini"
victoire=J.nom + "a gagne!"
quit
if j==17:
victoire= J.nom+" a gagne!"
message="Jeu Termine!"
#sinon, continuer
else:
socket.send_multipart([J.addr,b'',b"Touche!"])
socket.send_multipart([J.addr,b'',b"Quelle case frapper?"])
J.addr,empty,frappe=socket.recv_multipart()
frappe=frappe.decode()
print(frappe)
k=f(frappe[0])-1
l=int(frappe[1])-1
socket.send_multipart([J.addr,b'',b"Manque! C'est le tour de l'autre joueur maintenant."])
message = message + "Touche! \n"
message = message + "Quelle case frapper?"
if victoire!='':
message=message[:-20]
else:
message="Manque! C'est le tour de l'autre joueur maintenant."
return(message, victoire ,M,position)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment