Skip to content

Commit

Permalink
- Cell class now interacts with Gamboard class
Browse files Browse the repository at this point in the history
 - Gameboard shows real time stats of infectino
  - perameters are not able to interacted with correctlty

  !! there are some indexing issues which are solved poorly
  • Loading branch information
tripplerizz committed Apr 1, 2020
1 parent b308536 commit f38ac3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
47 changes: 17 additions & 30 deletions Cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Cell:
age = 0
timeHealthy = 0
timeVirus = 0
gameBoard = []

#-----------------------------------------------------------------------------------
#constructors
Expand Down Expand Up @@ -48,20 +47,6 @@ def isOld(self):
# -----------------------------------------------------------------------------------------
#set functions

def setPos(self,x,y): # setting x,y coords

if(x >= 99):
return
if (y >= 99):
return
if ( x <= 1):
return
if (y <= 1):
return

self.Column = y
self.Row = x

def addYear(self): # checks if year has happened
if(self.timeHealthy + self.timeVirues %365 == 0): ## if a year has passed
self.age+=1 # adding one year to the age
Expand All @@ -76,39 +61,41 @@ def setInfectionStatus(self, stat):
self.infectionStatus = stat

# move functions---------------------------------------------------------------------------------
def setPos(self,x,y): # setting x,y coords
# this function checks the bounds of the board
if(x >= self.gameBoard.size -1):
return
if (y >= self.gameBoard.size - 1):
return
if ( x <= 1):
return
if (y <= 1):
return

def movePos(self,x,y): # this function is tied to move function
self.Column += x # adding movement to horiz
if(self.Column < 0 or self.Column >= self.gameBoard.sizeX):
self.Column = 1
self.Row += y # adding movement to vert
if(self.Row < 0 or self.Row >= self.gameBoard.sizeX):
self.Column = 1
self.gameBoard.boardMove(self.Column, self.Row)


self.Column = y
self.Row = x

def move(self, cellDict):


x = self.Row + (random.randint(-1,1))
y = self.Column + (random.randint(-1,1))

while(self.gameBoard[x,y] != 0):
while(self.gameBoard.grid[x,y] != 0):
if cellDict[x,y].infectionStatus == 2:
self.collision()

x = self.Row + (random.randint(-1,1))
y = self.Column + (random.randint(-1,1))

self.setPos(x, y)


def collision(self):
if(self.infectionStatus == 1):
x = random.randint(0,2)
if (x == 2):
self.infectionStatus = 2
self.gameBoard.infectedCount += 1 # updating infected count of population



Expand Down
13 changes: 7 additions & 6 deletions GameBoard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def __init__(self, inSize): # creating parameter for user

def createPopulation (self, population, infected): # this function creates a population based on perameters and board

self.population = population
self.population = population + 1
self.infectedCount = infected
randomCoord = [0,0]
randomCoord[0] = (rd.randint(0, self.size -1)) # location x
randomCoord[1] = (rd.randint(0, self.size -1)) # location y

for x in range(0, population):
for x in range(0, self.population -1):

infectionStatus = 1
if x < infected: # this condition creates number of ifected sells specified by perameters
Expand All @@ -43,18 +43,19 @@ def createPopulation (self, population, infected): # this function creates a pop
randomCoord[1], # location y
rd.randint(0, 255), # time virus
rd.randint(0, 255), # time
self.grid)
self)

self.cell_dict[new_cell.Row, new_cell.Column] = new_cell
self.grid[new_cell.Row, new_cell.Column] = new_cell.infectionStatus

def update_grid(self):
for x in range(0, 99):
for y in range(0, 99):
for x in range(0, self.size-1):
for y in range(0, self.size-1):
if (x, y) in self.cell_dict:
popped_cell = self.cell_dict.pop((x, y))
self.grid[x][y] = 0
popped_cell.move(self.cell_dict) # call move on cell

self.cell_dict[popped_cell.Row, popped_cell.Column] = popped_cell
self.grid[popped_cell.Row][popped_cell.Column] = popped_cell.infectionStatus

Expand All @@ -63,7 +64,7 @@ def show(self):
for x in range(0, 100000):
plt.imshow(self.grid)
plt.title("Population: " + str(len(self.cell_dict)))
#plt.xlabel("starting infection count = " + str(self.infectedCount))
plt.xlabel("starting infection count = " + str(self.infectedCount))
self.update_grid()
plt.pause(0.000005)
plt.clf()
Expand Down
2 changes: 1 addition & 1 deletion GermTheory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def main():
b1 = Board(100)
b1.createPopulation(100, 1)
b1.createPopulation(200, 25)
b1.update_grid()
b1.show()

Expand Down
Binary file modified __pycache__/Cell.cpython-37.pyc
Binary file not shown.
Binary file modified __pycache__/GameBoard.cpython-37.pyc
Binary file not shown.

0 comments on commit f38ac3b

Please sign in to comment.