-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleRobomodulesUsage
More file actions
62 lines (46 loc) · 2.69 KB
/
Copy pathSampleRobomodulesUsage
File metadata and controls
62 lines (46 loc) · 2.69 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import os
import botCode.botCode.robomodules as rm # may need to change depending on location of file
from botCode.botCode.messages import * # may need to change depending on location of file
from botCode.botCode.messages import MsgType, message_buffers
ADDRESS = os.environ.get("BIND_ADDRESS","192.168.0.100") # Address of game engine server
PORT = os.environ.get("BIND_PORT", 11297) # Port of game engine server
FREQUENCY = 10
class SamplePacbotModule(rm.ProtoModule):
def __init__(self, addr, port):
self.subscriptions = [MsgType.LIGHT_STATE]
super(addr, port, message_buffers, MsgType, FREQUENCY, self.subscriptions)
self.state = None
def msg_received(self, msg, msg_type):
# This gets called whenever any message is received
# This module will connect to the local server
if msg_type == MsgType.LIGHT_STATE:
self.state = msg
def tick(self):
# this function will get called in a loop with FREQUENCY frequency
# The main functionality of your code should be here
# For now we will just print out the state
if self.state:
print('\n' * 100)
print('score: {}'.format(self.state.score))
print('lives: {}'.format(self.state.lives))
state = 'Running' if self.state.mode == LightState.RUNNING else 'Paused'
print('state: {}'.format(state))
print("pacbot's location (x,y): ({},{})".format(self.state.pacman.x, self.state.pacman.y))
print("Red ghost's location (x,y): ({},{})".format(self.state.red_ghost.x, self.state.red_ghost.y))
state = 'Frightened' if self.state.red_ghost.state == LightState.FRIGHTENED else 'Normal'
print('Red ghost state: {}'.format(state))
print("Pink ghost's location (x,y): ({},{})".format(self.state.pink_ghost.x, self.state.pink_ghost.y))
state = 'Frightened' if self.state.pink_ghost.state == LightState.FRIGHTENED else 'Normal'
print('Pink ghost state: {}'.format(state))
print("Blue ghost's location (x,y): ({},{})".format(self.state.blue_ghost.x, self.state.blue_ghost.y))
state = 'Frightened' if self.state.blue_ghost.state == LightState.FRIGHTENED else 'Normal'
print('Blue ghost state: {}'.format(state))
print("Orange ghost's location (x,y): ({},{})".format(self.state.orange_ghost.x, self.state.orange_ghost.y))
state = 'Frightened' if self.state.orange_ghost.state == LightState.FRIGHTENED else 'Normal'
print('Orange ghost state: {}'.format(state))
def main():
module = SamplePacbotModule(ADDRESS, PORT)
module.run()
if __name__ == "__main__":
main()