-
Notifications
You must be signed in to change notification settings - Fork 0
/
Protocol.py
61 lines (53 loc) · 1.97 KB
/
Protocol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Network
import IA
def setName(socket, name):
Network.send(socket, "NME", len(name), name)
class ByeException(Exception):
pass
def manageOrder(socket, order, game):
orderStr = Network.toString(order)
print("Received order %s" % orderStr)
if orderStr == "SET":
n = Network.toInt(socket.recv(1))
m = Network.toInt(socket.recv(1))
game.init(n, m)
elif orderStr == "HUM":
# Passing: legacy rule
# Only reading data from socket
n = Network.toInt(socket.recv(1))
for k in range(n):
x = Network.toInt(socket.recv(1))
y = Network.toInt(socket.recv(1))
elif orderStr == "HME":
x = Network.toInt(socket.recv(1))
y = Network.toInt(socket.recv(1))
game.initHome(x, y)
elif orderStr == "MAP" or orderStr == "UPD":
n = Network.toInt(socket.recv(1))
for k in range(n):
x = Network.toInt(socket.recv(1))
y = Network.toInt(socket.recv(1))
h = Network.toInt(socket.recv(1))
v = Network.toInt(socket.recv(1))
w = Network.toInt(socket.recv(1))
game.setHuman(x, y, h)
game.setVampire(x, y, v)
game.setWerewolf(x, y, w)
print(game)
print("================")
human = game.getHuman()
creatures = game.getCreatures()
for creature in creatures:
agent = IA.Agent()
agent.i = creature["coord"][0]
agent.j = creature["coord"][1]
agent.count = creature["count"]
print("Agent: %s" % str(creature["coord"]))
for h in human:
print("Human: %s. %f" % (str(h["coord"]), agent.cost(h["count"], h["coord"][0], h["coord"][1], game.n)))
elif orderStr == "END":
pass
#ici on met fin à la partie en cours
#Réinitialisez votre modèle
elif orderStr == "BYE":
raise ByeException()