@@ -19,6 +19,7 @@ class BoltzmannWealthModel(mesa.Model):
19
19
20
20
def __init__ (self , N = 100 , width = 10 , height = 10 ):
21
21
super ().__init__ ()
22
+ self .running = True # TODO remove this line when at Mesa 3.0
22
23
self .num_agents = N
23
24
self .grid = mesa .space .MultiGrid (width , height , True )
24
25
self .datacollector = mesa .DataCollector (
@@ -32,12 +33,10 @@ def __init__(self, N=100, width=10, height=10):
32
33
y = self .random .randrange (self .grid .height )
33
34
self .grid .place_agent (a , (x , y ))
34
35
35
- self .running = True
36
36
self .datacollector .collect (self )
37
37
38
38
def step (self ):
39
39
self .agents .shuffle ().do ("step" )
40
- # collect data
41
40
self .datacollector .collect (self )
42
41
43
42
def run_model (self , n ):
@@ -53,17 +52,18 @@ def __init__(self, unique_id, model):
53
52
self .wealth = 1
54
53
55
54
def move (self ):
56
- possible_steps = self .model .grid .get_neighborhood (
55
+ possible_positions = self .model .grid .get_neighborhood (
57
56
self .pos , moore = True , include_center = False
58
57
)
59
- new_position = self .random .choice (possible_steps )
60
- self .model .grid .move_agent (self , new_position )
58
+ self .model .grid .move_agent_to_one_of (self , possible_positions )
61
59
62
60
def give_money (self ):
63
- cellmates = self .model .grid .get_cell_list_contents ([self .pos ])
64
- cellmates .pop (
65
- cellmates .index (self )
66
- ) # Ensure agent is not giving money to itself
61
+ cellmates = [
62
+ c
63
+ for c in self .model .grid .get_cell_list_contents ([self .pos ])
64
+ # Ensure agent is not giving money to itself
65
+ if c is not self
66
+ ]
67
67
if len (cellmates ) > 0 :
68
68
other = self .random .choice (cellmates )
69
69
other .wealth += 1
0 commit comments