From ed0826679d2370178f1877c50acc3df04d28e365 Mon Sep 17 00:00:00 2001 From: 1Codealot <58225804+1Codealot@users.noreply.github.com> Date: Sat, 22 Apr 2023 08:41:37 +0100 Subject: [PATCH] Made mainLoop function Also creates settings file if it doesn't exist. --- Infection.py | 80 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/Infection.py b/Infection.py index 9fb5708..fc8b6e0 100644 --- a/Infection.py +++ b/Infection.py @@ -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:]) @@ -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 @@ -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] @@ -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()