-
Notifications
You must be signed in to change notification settings - Fork 840
/
server.py
48 lines (37 loc) · 1.39 KB
/
server.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
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import CanvasGrid
from .model import CivilViolenceModel
from .agent import Citizen, Cop
COP_COLOR = "#000000"
AGENT_QUIET_COLOR = "#0066CC"
AGENT_REBEL_COLOR = "#CC0000"
JAIL_COLOR = "#757575"
def citizen_cop_portrayal(agent):
if agent is None:
return
portrayal = {"Shape": "circle",
"x": agent.pos[0], "y": agent.pos[1],
"Filled": "true"}
if type(agent) is Citizen:
color = AGENT_QUIET_COLOR if agent.condition == "Quiescent" else \
AGENT_REBEL_COLOR
color = JAIL_COLOR if agent.jail_sentence else color
portrayal["Color"] = color
portrayal["r"] = 0.8
portrayal["Layer"] = 0
elif type(agent) is Cop:
portrayal["Color"] = COP_COLOR
portrayal["r"] = 0.5
portrayal["Layer"] = 1
return portrayal
model_params = dict(height=40,
width=40,
citizen_density=.7,
cop_density=.074,
citizen_vision=7,
cop_vision=7,
legitimacy=.8,
max_jail_term=1000)
canvas_element = CanvasGrid(citizen_cop_portrayal, 40, 40, 500, 500)
server = ModularServer(CivilViolenceModel, [canvas_element],
"Epstein Civil Violence", model_params)