Skip to content

Commit

Permalink
Added and changed some stuff
Browse files Browse the repository at this point in the history
Moved placement of clearing terminal in getAsGrid. Changed the delay at end of loop to be more consistant.
  • Loading branch information
1Codealot authored Aug 4, 2023
1 parent ac26ac6 commit ffa6104
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions Infection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import random, time, os
import random, time, os, sys

## Seed stuff
if len(sys.argv) >= 2:
random.seed(sys.argv[1])
else:
Seed = input("\nEnter in a seed (or leave blank for random): ")
if Seed != '':
random.seed(Seed)
else:
random.seed(random.randint(0, 999_999_999_999_999_999_999_999_999_999_999)) # nine hundred ninety-nine nonillion nine hundred ninety-nine octillion... Should be enough lol

Generation = 0

Expand Down Expand Up @@ -46,25 +56,24 @@
ImmunityAfterHealingLength=int(ImmunityAfterHealingLength[27:])
Delay=float(Delay[6:])


InfectedRepresentation = "●"
UnInfectedRepresentation = "○"
ImmuneRepresentation = "X"

AmountOfCells = X*Y # Less computing time needed for making variables

class Cell:
def __init__(self,Gen_Infected = -1) -> None:
self.Gen_Infected = Gen_Infected
self.last_time_infected = 0

self.InfectedRepresentation = "●"
self.UnInfectedRepresentation = "○"
self.ImmuneRepresentation = "X"

def get_cell_type(self) -> str:
if self.Gen_Infected == -2:
return ImmuneRepresentation
return self.ImmuneRepresentation
elif self.Gen_Infected == -1:
return UnInfectedRepresentation
return self.UnInfectedRepresentation
else:
return InfectedRepresentation
return self.InfectedRepresentation

def infect(self):
# Part of Infection logic included: random, not already infected
Expand Down Expand Up @@ -110,38 +119,37 @@ def getInfectedCellCount() -> int:
return count


def Print_As_Grid():
def getAsGrid(shouldOutput = True):

InfectedCellCount: int = 0
if Generation > 0:
if Generation >= 0:
InfectedCellCount = getInfectedCellCount()

os.system('cls' if os.name == 'nt' else 'clear')
GriddedString = ''
for n in range(AmountOfCells):
if n % X == 0:
GriddedString += f'\n'

GriddedString += f"{Cells[n].get_cell_type()}"

print(f"{GriddedString}\n\n\nGeneration: {Generation}\nCells infected: {InfectedCellCount}\n")
if shouldOutput:
os.system('cls' if os.name == 'nt' else 'clear')
print(f"{GriddedString}\n\n\nGeneration: {Generation}\nCells infected: {InfectedCellCount}\n")

Print_As_Grid()
else: return GriddedString

Seed = input("\nEnter in a seed (or leave blank for random): ")
if Seed != '':
random.seed(Seed)
getAsGrid()

# Infecting 'patient zero' (for lack of better term.)
Cells[random.randint(0, AmountOfCells - 1)].Gen_Infected = Generation


Print_As_Grid()
getAsGrid()
time.sleep(Delay)

while getInfectedCellCount() != AmountOfCells:
def infectionLoopAndHealing():
for C in range(AmountOfCells):
if (currentCell := Cells[C]).Gen_Infected >= 0: # currentCell stores the Cell object.
if Cells[C].Gen_Infected >= 0: # currentCell stores the Cell object.

# Right

Expand All @@ -168,9 +176,15 @@ def Print_As_Grid():
if Healing == 1:
Cells[C].heal()


while ((cellCount:=getInfectedCellCount()) != AmountOfCells and Healing == 0) or (cellCount != 0):
startTime = time.time()
Generation += 1
infectionLoopAndHealing()

getAsGrid()

Print_As_Grid()
time.sleep(Delay)
if (finalDelay:= time.time()-startTime) >= 0:
time.sleep(finalDelay)

input()

0 comments on commit ffa6104

Please sign in to comment.