-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.py
More file actions
53 lines (39 loc) · 1.24 KB
/
state.py
File metadata and controls
53 lines (39 loc) · 1.24 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
#!/usr/bin/env python
import random
class State(object):
def __init__(self, name):
self._name = name
self.setup()
@property
def name(self):
return self._name
def setup(self):
# initialise state variables that we will need etc.
pass
def is_excited(self):
# check if state is still excited, return True or False
raise NotImplementedError
def excite(self):
# try to make transistion to this state
raise NotImplementedError
def decay(self, lower):
# try to make transition down from this state
raise NotImplementedError
def __str__(self):
return self.name
class GroundState(State):
def __init__(self):
super(GroundState, self).__init__('GROUND')
def is_excited(self):
# this is not physically correct, but makes things easiert :)
return True
class FailingState(State):
def __init__(self, name, success_rate):
self.success_rate = success_rate
super(FailingState, self).__init__(name)
def do_we_succeed(self):
return random.random() < self.success_rate
def is_excited(self):
return self.do_we_succeed()
def excite(self):
return self.do_we_succeed()