Skip to content

Commit

Permalink
Made mainLoop function
Browse files Browse the repository at this point in the history
Also creates settings file if it doesn't exist.
  • Loading branch information
1Codealot authored Apr 22, 2023
1 parent f17fb51 commit ed08266
Showing 1 changed file with 56 additions and 24 deletions.
80 changes: 56 additions & 24 deletions Infection.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import random
import time

Generation = 0

f = open("Infection_Settings.txt","r")

X=f.readline()
Y=f.readline()
InfectChance=f.readline()
Healing=f.readline()
MinGensToUninfect=f.readline()
ChanceOfHealing=f.readline()
Immunity=f.readline()
ImmuneCellCount=f.readline()
Output=True

try:
f = open("Infection_Settings.txt","r")
f.close()
except:
f = open("Infection_Settings.txt","a")
f.write("X=20\n\
Y=20\n\
InfectChance=5\n\
Healing=1\n\
MinGensToUninfect=20\n\
ChanceOfHealing=5\n\
Immunity=1\n\
ImmuneCellCount=12")
#I guess these are default settings now ¯\_(ツ)_/¯
f.close()
finally:
f = open("Infection_Settings.txt","r")
X = f.readline()
Y = f.readline()
InfectChance = f.readline()
Healing = f.readline()
MinGensToUninfect = f.readline()
ChanceOfHealing = f.readline()
Immunity = f.readline()
ImmuneCellCount = f.readline()

f.close()

X=int(X[2:])
Y=int(Y[2:])
Expand All @@ -23,6 +40,8 @@
Immunity=int(Immunity[9:])
ImmuneCellCount=int(ImmuneCellCount[16:])

########################################################################

Cells=[] #Main List
InCells=[] #Place where cells were infected
Gen_Infected=[] #Generation the cell was infected
Expand Down Expand Up @@ -54,18 +73,29 @@ def Print_As_Grid(X,Y):
else:
print(Cells[n],end='')

Print_As_Grid(X,Y)
input()
if Output == True:
Print_As_Grid(X,Y)
Seed = input("\nMake sure the grid is the correct size. \nYou can also add type in a seed. ")

if Seed != '':
random.seed(Seed)

Infected=random.randint(0,len(Cells))
Cells[Infected]='●'
Gen_Infected[Infected]=Generation
Gen_Infected[Infected]=0
InCells.append(Infected)

print("\n\n\n\n\n")
Print_As_Grid(X,Y)
if Output == True:
print("\n\n\n\n\n")
Print_As_Grid(X,Y)

def mainLoop():
global Generation
try:
Generation += 1
except:
Generation = 0

while len(InCells) != X*Y:
for t in range(0,len(InCells)):
CellInfecting=InCells[t]

Expand Down Expand Up @@ -109,12 +139,14 @@ def Print_As_Grid(X,Y):
Gen_Infected[h] = -1
InCells.remove(h)

Generation += 1
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
Print_As_Grid(X,Y)

print("\n",len(InCells), "Cells infected.")
print("Generation:", Generation)
while len(InCells) != X*Y:
time.sleep(0.35)
mainLoop()
if Output == True:
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
Print_As_Grid(X,Y)

print("\n",len(InCells), "Cells infected.")
print("Generation:", Generation)

input()

0 comments on commit ed08266

Please sign in to comment.