-
Notifications
You must be signed in to change notification settings - Fork 4
/
Sugarscape_migration.py
42 lines (31 loc) · 955 Bytes
/
Sugarscape_migration.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
""" Adpated from Think Complexity 2 edition by Allen Downey (thank you very much).
Available at https://github.com/AllenDowney/ThinkComplexity2/blob/master/code/chap09.ipynb
Copyright 2016 Allen Downey, MIT License
"""
import matplotlib.pyplot as plt
from thinkstats2 import Cdf, RandomSeed
import thinkplot
from Sugarscape import Sugarscape, SugarscapeViewer
# # # Migration I
# RandomSeed(17)
#
# env = Sugarscape(50, num_agents=300, starting_box=(20, 20), max_vision=16)
#
# viewer = SugarscapeViewer(env)
# anim = viewer.animate(frames=20, interval=500)
# plt.show()
# # # Migration II
env = Sugarscape(50, num_agents=300, starting_box=(20, 20), max_vision=16)
viewer = SugarscapeViewer(env)
thinkplot.preplot(cols=3)
viewer.draw()
thinkplot.subplot(2)
for i in range(6):
viewer.step()
viewer.draw()
thinkplot.subplot(3)
for i in range(6):
viewer.step()
viewer.draw()
thinkplot.tight_layout()
thinkplot.save('chap09-5')