-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
148 lines (120 loc) · 5.29 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Simulateur permettant de simuler un match d'eurobot.
Déplacer gros robot: clic gauche
Déplacer petit robot: clic droit
Déplacer adversaire: idem + ctrl
@author Thomas Recouvreux
@author Pierre-Henry Fricot
@author Cédric Bache
Pour la version 2013, nous avons utilisé le nouveau protocole de communication zérobot. Les objets et engines sont également réécrit pour adapter au nouveau reglement.
@author Siqi LIU <[email protected]>
@author Florent Thévenet <[email protected]>
@author Thomas Fuhrmann <[email protected]>
"""
import sys
import os
DIR_PATH = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(DIR_PATH, "..", "lib"))
import optparse
import threading
import time
import zmq
import zerobot
import utcoupe
from simu import *
if __name__ == "__main__":
default = {}
default["server_ip"] = "localhost"
default["port_frontend"] = 5000
default["port_backend"] = 5001
default["port_ev_push"] = 5003
default["port_ev_sub"] = 5004
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage,version="%prog 0.0")
parser.add_option("-S", "--server-ip",
action="store", dest="server_ip", default=default["server_ip"],
help="ip zerobot server")
parser.add_option("-b", "--port-backend",
action="store", dest="port_backend", type="int", default=default["port_backend"],
help="port backend")
parser.add_option("-f", "--port-frontend",
action="store", dest="port_frontend", type="int", default=default["port_frontend"],
help="port frontend")
parser.add_option("-p", "--port-ev-push",
action="store", dest="port_ev_push", type="int", default=default["port_ev_push"],
help="port events publishing")
parser.add_option("-s", "--port-ev-sub",
action="store", dest="port_ev_sub", type="int", default=default["port_ev_sub"],
help="port events subscribtion")
(options, args) = parser.parse_args()
engine = Engine()
match = Match()
# debug
debug = Debug()
# Store server info
server = utcoupe.Server(server = options.server_ip,
frontend = options.port_frontend,
backend = options.port_backend,
ev_push = options.port_ev_push,
ev_sub = options.port_ev_sub)
# Create services on demand
ctx = zmq.Context(1)
services = utcoupe.ServicesManager(server, ctx)
# robots
bigrobot = BigRobot(engine = engine,
posinit = mm_to_px(150, 1800),
team = BLUE,
asserv = utcoupe.ASSERV_BIG,
others = utcoupe.OTHERS_BIG,
visio = utcoupe.VISIO_BIG,
match = match,
services = services)
minirobot = MiniRobot(engine = engine,
posinit = mm_to_px(225, 300),
team = BLUE,
asserv = utcoupe.ASSERV_MINI,
others = utcoupe.OTHERS_MINI,
match = match,
services = services)
bigrobot2 = BigRobot(engine = engine,
posinit = mm_to_px(3000-250,250),
team = RED,
asserv = utcoupe.ASSERV_BIG_ENEMY,
others = utcoupe.OTHERS_BIG_ENEMY,
visio = utcoupe.VISIO_BIG_ENEMY,
match = match,
services = services)
minirobot2 = MiniRobot(engine = engine,
posinit = mm_to_px(3000-400,250),
team = RED,
asserv = utcoupe.ASSERV_MINI_ENEMY,
others = utcoupe.OTHERS_MINI_ENEMY,
match = match,
services = services)
robots = (bigrobot, minirobot, bigrobot2, minirobot2)
# hokuyo
hokuyo = services.create(utcoupe.HOKUYO, Hokuyo(robots))
engine.init(services.stop,match,debug)
match.init(engine)
bigrobot.init(engine)
minirobot.init(engine)
bigrobot2.init(engine)
minirobot2.init(engine)
load_map("map.xml",engine)
engine.add(bigrobot)
engine.add(minirobot)
engine.add(bigrobot2)
engine.add(minirobot2)
t=threading.Thread(target=engine.start)
t.setDaemon(True)
t.start()
while not engine.e_stop.is_set():
try:
engine.e_stop.wait(3)
print(match.score(BLUE))
print(match.score(RED))
except KeyboardInterrupt:
engine.stop()
break