-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameBoard.py
More file actions
74 lines (58 loc) · 2.82 KB
/
Copy pathGameBoard.py
File metadata and controls
74 lines (58 loc) · 2.82 KB
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
import numpy as np
import matplotlib.pyplot as plt
import random as rd
from Cell import Cell
import info
# from info import getTotalCases, getTotalDeaths, getDeathRate, getPopulation
class Board:
# Core attributes
size = 100
grid = np.zeros((size, size))
cell_list = []
infectedCount = 0
population = 0
def __init__(self, inSize): # creating parameter for user
self.size = inSize
self.grid = np.zeros((inSize, inSize))
cell_list = []
def relativePopulation(self, state): # this function grabs population from census information
return int(info.getPopulation(state)/ self.size **2)
def getPercentInfected(self, state):
return float(info.getTotalCases(state)/info.getPopulation(state))
def createPopulation (self, state): # creates a population based on parameters and board
self.population = self.relativePopulation(state)
self.infectedCount = int(self.population * self.getPercentInfected(state))
randomCoord = [0,0]
randomCoord[0] = (rd.randint(1, self.size - 1)) # location x
randomCoord[1] = (rd.randint(1, self.size - 1)) # location y
for x in range(0, self.population):
infectionStatus = 1
if x < self.infectedCount: # this condition creates number of infected sells specified by parameters
infectionStatus = 2
# get random coordinates for cell
while (self.grid[randomCoord[0], randomCoord[1]] != 0):
randomCoord[0] = rd.randint(0, self.size - 1) # location x
randomCoord[1] = rd.randint(0, self.size -1) # location y
# generate random cell
new_cell = Cell(rd.randint(1, 80), # age
infectionStatus, # infection stat
randomCoord[0], # location x
randomCoord[1], # location y
rd.randint(0, 255), # time
self)
self.cell_list.append( new_cell ) # add cell to dictionary
self.grid[new_cell.Row, new_cell.Column] = new_cell.infectionStatus # add cell status to grid
def update_grid(self):
for index,cell in enumerate(self.cell_list):
if(cell.time % 45 == 0):
if(cell.deathRate()):
self.cell_list.pop(index)
cell.move()
def show(self):
while len(self.cell_list) > self.population/4: # Visualize the grid
plt.imshow(self.grid)
plt.title("Population: " + str(len(self.cell_list)))
plt.xlabel("starting infection count = " + str(self.infectedCount))
self.update_grid()
plt.pause(0.0000005)
plt.clf()