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

algo fonctionnel

parent 44e40da7
...@@ -2,55 +2,48 @@ import time ...@@ -2,55 +2,48 @@ import time
import zmq import zmq
import numpy as np import numpy as np
import builtins import builtins
from grille_serveur import f
context = zmq.Context() def frappe(J,case,M,position):
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)
k=f(case[0])-1 k=f(case[0])-1
l=int(case[1])-1 l=int(case[1])-1
while M2[k][l]==1: if len(case)==3:
M2[k][l]=2 l=9
position[(k,l)]=position[(k,l)][0],2 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] elem=position[(k,l)][0]
print(M2) longueur=position[(k,l)][1]
print(M)
#verifier si le bateau est coule #verifier si le bateau est coule
i=0 i=0
for cle in position.keys(): 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 i+=1
if i==elem.longueur: if i==longueur:
coule=elem.nom+" coule!" message=message + elem+" coule! \n"
socket.send_multipart([J.addr,b'',coule.encode()])
for cle in position.keys(): for cle in position.keys():
if position[cle][0]==elem: if position[cle][0]==elem:
M2[cle[0]][cle[1]]=3 M[cle[0]][cle[1]]=3
position[cle]=position[cle][0],3 position[cle]=position[cle][0],position[(k,l)][1],3
print(M)
#verifier si le jeu est gagne #verifier si le jeu est gagne
j=0 j=0
for cle in position.keys(): for cle in position.keys():
if position[cle][1]==3: if position[cle][2]==3:
j+=1 j+=1
if j==18: if j==17:
victoire= J1.nom+" a gagne!" victoire= J.nom+" a gagne!"
socket.send_multipart([J.addr,b"",victoire]) message="Jeu Termine!"
message="jeu fini"
victoire=J.nom + "a gagne!"
quit
#sinon, continuer #sinon, continuer
else: else:
socket.send_multipart([J.addr,b'',b"Touche!"]) message = message + "Touche! \n"
socket.send_multipart([J.addr,b'',b"Quelle case frapper?"]) message = message + "Quelle case frapper?"
J.addr,empty,frappe=socket.recv_multipart() if victoire!='':
frappe=frappe.decode() message=message[:-20]
print(frappe)
k=f(frappe[0])-1 else:
l=int(frappe[1])-1 message="Manque! C'est le tour de l'autre joueur maintenant."
socket.send_multipart([J.addr,b'',b"Manque! C'est le tour de l'autre joueur maintenant."])
return(message, victoire ,M,position) 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