-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
49 lines (41 loc) · 1.37 KB
/
parser.py
File metadata and controls
49 lines (41 loc) · 1.37 KB
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
import re
import utils
class Parser:
def parse(self, msg):
flag = msg[1:5]
if flag == 'init':
return self.parse_init(msg)
elif flag == 'sens':
return self.parse_body(msg)
elif flag == 'see ':
return self.parse_vision(msg)
else:
print 'msg', msg
def parse_init(self, msg):
m = re.match(r'\(init ([lr]) (\d+) (\w+)', msg)
side, unum, mode = m.groups()
info = {'type': 'INIT', 'side': side, 'unum': unum, 'mode': mode}
utils.int_dict(info)
return info
def parse_body(self, msg):
info = {'type': 'BODY'}
print msg
m = re.match(r'.*view_mode (\w+) (\w+)', msg)
info['view_mode'] = m.groups()
m = re.match(r'.*stamina (\d+) (\d+)', msg)
info['stamina'] = m.group(0)
info['effort'] = m.group(1)
m = re.match(r'.*speed (\d+)', msg)
info['speed'] = m.group(0)
attrs = ['kick', 'dash', 'turn', 'say', 'turn_neck', 'catch', 'move',
'change_view']
for attr in attrs:
pat = '.*{0} (\d+)'.format(attr)
m = re.match(pat, msg)
info[attr] = m.groups(0)
utils.int_dict(info)
return info
def parse_vision(self, msg):
info = {'type': 'VISION'}
utils.int_dict(info)
return info