Created
March 27, 2012 09:11
-
-
Save mitchellbusby/2214215 to your computer and use it in GitHub Desktop.
not implemented
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
population = [] | |
#reproduction command | |
def reproduce(DNA): | |
assignname = str(random.randint(1000, 10000)) | |
organism = Organism(assignname, DNA) | |
population.append(organism) | |
#command to do a turn for the entire population | |
def TurnNow(): | |
global population | |
templi = [] | |
for i in xrange(len(population)): | |
if population[i].Dead(): | |
print population[i].name + " is dead!" | |
population[i] = None | |
else: | |
population[i].Turn() | |
for i in population: | |
if i: | |
templi.append(i) | |
population = templi[:] | |
def checkup(number): | |
print population[number] | |
class Organism: | |
def __init__(self, name, DNA): | |
self.name = name | |
self.life = 1 | |
self.DNA = DNA | |
self.lifespan = int(self.DNA[0:2]) | |
self.mrate = 3 | |
def __str__(self): | |
return "ID: " + self.name + " AGE: " + str(self.life) + " DNA: " + self.DNA | |
def Dead(self): | |
if self.life >= self.lifespan: | |
return True | |
return False | |
def Turn(self): | |
print self | |
self.mutate() | |
self.reproductionchance = random.randint(0,6) | |
if self.reproductionchance == 1: | |
reproduce(self.DNA) | |
self.life +=1 | |
def mutate(self): | |
#if it returns with a 0/false then | |
if not random.randint(0, self.mrate): | |
editpoint = random.randint(0, len(self.DNA)) | |
self.DNA = self.DNA[:editpoint] + str(random.randint(0,9)) + self.DNA[editpoint+1:] | |
def disease(self): | |
if self.DNA >= 9000: | |
print self.DNA | |
self.life = 70 | |
#populate | |
numBegin = input("How many organisms would you like to start with? ") | |
for i in xrange(numBegin): | |
reproduce(raw_input("DNA: ")) | |
#iterate | |
while population: | |
TurnNow() | |
#infect | |
def infect(): | |
for i in xrange(len(population)): | |
population[i].disease() | |
TurnNow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment