Commit 463f6d49 authored by Mestari Yousra's avatar Mestari Yousra
Browse files

code serveur

parent b05120bd
# 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 builtins
import grille_serveur.py
import frappe_serveur.py
class Bateau:
"definition 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:
"definition 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.ROUTER)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
addr,empty,message=socket.recv_multipart()
print(message.decode())
if message.decode() =="PLAY":
socket.send_multipart([addr,b'',b"VS P or C?"])
J1.addr,empty,vs=socket.recv_multipart()
print(vs.decode())
[M1,position1]=grille_serveur(J1,bateaux)
if vs.decode()== "P":
J2.addr,empty,vs=socket.recv_multipart()
[M2,position2]=grille_serveur(J2,bateaux)
message="jeu en cours"
socket.send_multipart([J1.addr,b'',message.encode()])
while message!="jeu fini":
message,victoire, M2, position2=frappe_serveur(J1,M2,position2)
socket.send_multipart([J1.addr,b'',message.encode()])
if message!="jeu fini":
message,victoire, M1, position1=frappe_serveur(J2,M1,position1)
socket.send_multipart([J1.addr,b'',message.encode()])
socket.recv_multipart([J1.addr,b'',victoire.encode()])
elif vs.decode()=='C':
#appeler l'IA
else:
quit
# Do some 'work'
time.sleep(1)
# Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.DEALER)
socket.connect("tcp://147.250.9.87:5555")
# Do 10 requests, waiting each time for a response
while True :
jeu=input("Voulez-vous jouer ?:")
if jeu=="PLAY":
socket.send_multipart([b'',b"PLAY"])
empty,reponse=socket.recv_multipart()
print(reponse.decode())
JouC=input()
socket.send_multipart([b'',JouC.encode()])
empty,reponse=socket.recv_multipart()
print(reponse.decode())
nom=input()
socket.send_multipart([b'',nom.encode()])
for i in range(5):
empty,reponse=socket.recv_multipart()
print(reponse.decode())
position_avant=input()
socket.send_multipart([b'',position_avant.encode()])
empty,reponse=socket.recv_multipart()
print(reponse.decode())
position_queue=input()
socket.send_multipart([b'',position_queue.encode()])
empty,reponse=socket.recv_multipart()
print(reponse.decode())
case=input()
socket.send_multipart([b'',case.encode()])
empty,reponse=socket.recv_multipart()
reponse=reponse.decode()
print(reponse)
while reponse=="Touche! Quelle case frapper?":
case=input()
socket.send_multipart([b'',case.encode()])
empty,reponse=socket.recv_multipart()
print(reponse.decode())
empty,reponse=socket.recv_multipart()
print(reponse.decode())
# Get the reply.
#message = socket.recv()
\ No newline at end of file
# Send reply back to client
socket.send(b"World")
\ 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