-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulation.py
86 lines (56 loc) · 2.12 KB
/
population.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from graphics import *
from agent import Agent
from disease import *
import numpy as np
import random
import copy
class Population():
def __init__(self, shape, window):
self.shape = shape
self.agent_array = np.empty(shape=(shape[0], shape[1]), dtype=object)
self.window = window
self.init_agents()
def init_agents(self):
window = self.window
cell_x = window.width / self.shape[0]
cell_y = window.height / self.shape[1]
#Initialize agents
for i in range(self.shape[0]):
for j in range(self.shape[1]):
x = i * (window.width / self.shape[0])
y = j * (window.height / self.shape[1])
agent_rectangle = Rectangle(Point(x, y), Point(x + cell_x, y + cell_y))
agent_population_coordinates = (i, j)
agent_window_coordinates = (x, y)
agent_size = (cell_x, cell_y)
self.agent_array[i][j] = Agent(agent_rectangle, agent_population_coordinates, agent_window_coordinates, agent_size)
return
def init_diseases(self, diseases, num_cases):
#For each disease, choose random spot for each case
for index, disease in enumerate(diseases):
for i in range(num_cases[index]):
fate_x = np.random.choice(range(self.shape[0] - 1))
fate_y = np.random.choice(range(self.shape[1] - 1))
self.agent_array[fate_x][fate_y].contract_disease(disease)
return
def draw(self):
for row in self.agent_array:
for agent in row:
agent.draw(self.window)
return
def next_state(self):
#Spread disease
self.spread_disease()
#Update agent states
self.update_agent_states()
return
def spread_disease(self):
for row in self.agent_array:
for agent in row:
agent.spread_disease(self.agent_array)
return
def update_agent_states(self):
for row in self.agent_array:
for agent in row:
agent.next_state()
return