1 from teamwork.math.Interval import Interval
2 from teamwork.utils.PsychUtils import *
3
4 DYNAMICS = 'object'
5
6
8 """Class of objects that represent the dynamics of a specific
9 state/belief feature in the simulation"""
10
15
16 - def apply(self,entity,value,action,world,debug=0):
17 """Takes an entity with the specified initial value for the
18 feature of interest and returns a new value in response to the
19 specified action being taken within the specified world
20 context (in the form of a dictionary of entity objects,
21 indexed by entity name)"""
22 return value
23
26
27 - def invert(self,entity,value,action,world,debug=0):
29
31 """Returns the incremental delta by which this dynamics
32 function adjusts values; this delta is stored in the
33 'increment' field of the 'args' attribute of this object; if
34 none is specified, defaults to 0.1"""
35 try:
36 return self.args['increment']
37 except KeyError:
38 return 0.1
39
41 """Deletes any stored information (e.g., partial results)
42 before beginning dynamics computation (should be
43 overridden by subclass)"""
44 pass
45
47 if entity.name == object.name:
48 return normalize(oldValue-objParam)
49 elif entity.name == actor.name:
50 return normalize(oldValue+actParam)
51 else:
52 return oldValue
53
56 actor = action['actor']
57 if type(actor) is InstanceType:
58 actor = actor.name
59 if action['type'][:6] == 'moveTo':
60 destination = action['type'][6:]
61 origin = world[actor].getState('floor')
62 if entity == actor:
63 pass
64 elif entity.getState('floor') == origin:
65 pass
66 elif entity.getState('floor') == destination:
67 pass
68 else:
69 return value
70 else:
71 return value
72
77
116
118 for key in self.results.keys():
119 del self.results[key]
120
121
123 """Dynamics function for change in power due to act of violence"""
124 if invert:
125 if entity.name == victim.name:
126 return normalize(oldPower+0.1)
127 elif entity.name == actor.name:
128 return normalize(oldPower-0.1)
129 else:
130 return oldPower
131 else:
132 if entity.name == victim.name:
133 return normalize(oldPower-0.1)
134 elif entity.name == actor.name:
135 return normalize(oldPower+0.1)
136 else:
137 return oldPower
138
140 """Dynamics function for change in hardship due to act of violence"""
141 if entity.name == victim.name:
142 if invert:
143
144 pass
145 else:
146 return delta(actor,oldHardship,'power') + decay(oldHardship)
147 else:
148 return decay(oldHardship,invert)
149
150 decayRate = 0.9
151
152 -def decay(value,invert=None):
157
158 -def delta(actor,oldValue,feature):
163
166