-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (65 loc) · 2.07 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import time
import random
from hq_agent import HqAgent
from radar_agent import RadarAgent
from missile_agent import MissileAgent
import util
import settings
class Timeline:
def __init__(self):
self.data = [
{'id': 10, 'object': 'plane', 'type': 'enemy', 'x': 320, 'y': 320},
{'id': 20, 'object': 'missile', 'type': 'enemy', 'x': 420, 'y': 420},
{'id': 33, 'object': 'plane', 'type': 'enemy', 'x': 400, 'y': 400},
{'id': 50, 'object': 'missile', 'type': 'enemy', 'x': settings.agents['hq']['x'], 'y': settings.agents['hq']['y']},
]
self.time = 0
objects = ['plane', 'bird', 'missile']
types = ['enemy', 'friend']
for i in range(100):
obj = random.choice(objects)
typ = random.choice(types)
if obj == 'bird':
typ = 'neutral'
x = random.randint(10, 840)
y = random.randint(10, 540)
item = {'id': 100 + i, 'object': obj, 'type': typ, 'x': x, 'y': y}
self.data.append(item)
def next(self):
if len(self.data) == self.time:
return False
instance = self.data[self.time]
self.time += 1
return instance
if __name__ == "__main__":
timeline = Timeline()
hq = HqAgent('hq', settings.agents)
hq_future = hq.start()
util.start_web(hq)
m1 = MissileAgent('missile1')
m1_future = m1.start()
util.start_web(m1)
m2 = MissileAgent('missile2')
m2_future = m2.start()
util.start_web(m2)
# Wait for hq & missiles to be prepared
hq_future.result()
m1_future.result()
m2_future.result()
r1 = RadarAgent('radar1', timeline, hq, settings.agents)
r1.start()
util.start_web(r1)
r2 = RadarAgent('radar2', timeline, hq, settings.agents)
r2.start()
util.start_web(r2)
util.mas_print_info("Wait until user interrupts with ctrl+C")
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break
hq.stop()
m1.stop()
m2.stop()
r1.stop()
r2.stop()