-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_base.py
50 lines (36 loc) · 1.03 KB
/
player_base.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
#!/usr/bin/env python
import cpu
class PlayerBase(object):
def __init__(self, hitpoints, program):
self.cpu = cpu.CPU(program)
self.hitpoints = hitpoints
# Hook up the io
self.cpu.set_forward_callback(self.forward)
self.cpu.set_left_callback(self.left)
self.cpu.set_right_callback(self.right)
self.cpu.set_fire_callback(self.fire)
def set_forward(self, forward):
self._forward = forward
def forward(self):
self._forward()
def set_right(self, right):
self._right = right
def right(self):
self._right()
def set_left(self, left):
self._left = left
def left(self):
self._left()
def set_fire(self, fire):
self._fire = fire
def fire(self):
self._fire()
def bump(self):
self.cpu.set_bump(True)
def hit(self):
self.hitpoints -= 1
def step(self):
if self.hitpoints > 0:
self.cpu.step()
def is_alive(self):
return self.hitpoints > 0