-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (45 loc) · 2.31 KB
/
main.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
import requests
import json
import random
# register_url = "http://localhost:8080/LifeGame.register"
# process_url = "http://localhost:8080/LifeGame.process"
# update_url = "http://localhost:8080/LifeGame.update"
# unregister_url = "http://localhost:8080/LifeGame.unregister"
# clear_url = "http://localhost:8080/LifeGame.clear"
#
register_url = "http://dnsvdiploma.appspot.com/LifeGame.register"
process_url = "http://dnsvdiploma.appspot.com/LifeGame.process"
update_url = "http://dnsvdiploma.appspot.com/LifeGame.update"
unregister_url = "http://dnsvdiploma.appspot.com/LifeGame.unregister"
clear_url = "http://dnsvdiploma.appspot.com/LifeGame.clear"
agentList = list()
headers = {'Content-Type': 'application/json'}
for x in range(0, 5):
for y in range(0, 5):
values = {"coordX": x, "coordY": y, "isAlive":
# False if (x + y) % 2 == 0 else True}
True if random.randint(0, 1) == 1 else False}
agentList.append(values)
r = requests.post(register_url, data=json.dumps(values), headers=headers)
for agent in agentList:
r = requests.post(process_url, data=json.dumps(
{"coordX": agent.get("coordX"), "coordY": agent.get("coordY"), "isAlive": agent.get("isAlive")}),
headers=headers)
aliveCounter = 0
for receivedAgent in json.loads(r.text).get("agentMessage"):
if receivedAgent.get("isAlive"):
aliveCounter += 1
agentData = dict
if agent.get("isAlive") == False and aliveCounter == 3:
agentData = {"coordX": agent.get("coordX"), "coordY": agent.get("coordY"), "isAlive": False,
"newIsAlive": True}
elif agent.get("isAlive") == True and (aliveCounter == 2 or aliveCounter == 3):
agentData = {"coordX": agent.get("coordX"), "coordY": agent.get("coordY"), "isAlive": True,
"newIsAlive": True}
elif agent.get("isAlive") == True and not (aliveCounter == 2 or aliveCounter == 3):
agentData = {"coordX": agent.get("coordX"), "coordY": agent.get("coordY"), "isAlive": True,
"newIsAlive": False}
else:
agentData = {"coordX": agent.get("coordX"), "coordY": agent.get("coordY"), "isAlive": agent.get("isAlive"),
"newIsAlive": agent.get("isAlive")}
r2 = requests.post(update_url, data=json.dumps(agentData), headers=headers)