Created
April 1, 2012 02:29
-
-
Save mitchellbusby/2270750 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 = [] | |
turncount = 0 | |
#reproduction command | |
def reproduce(DNA): | |
assignname = str(random.randint(1000, 9999)) | |
organism = Organism(assignname, DNA) | |
population.append(organism) | |
#command to do a turn for the entire population | |
def TurnNow(): | |
global population | |
turncount += 1 | |
print "***Starting round" + str(turncount) + "***" | |
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): | |
#name stuff | |
editpoint = random.randint(0, len(self.DNA)-1) | |
self.DNA = self.DNA[:editpoint] + str(random.randint(0,9)) + self.DNA[editpoint+1:] | |
#lifespan | |
editpoint = random.randint(0, len(self.DNA)-1) | |
self.DNA = self.DNA[:editpoint] + str(random.randint(0,9)) + self.DNA[editpoint+1:] | |
def disease(self): | |
if int(self.DNA[2:3]) >= 5: | |
print self.name + "got infected with the disease! He will die next turn." | |
self.life = self.lifespan+1 | |
#populate | |
numBegin = input("How many organisms would you like to start with? ") | |
for i in xrange(numBegin): | |
reproduce(raw_input("DNA: ")) | |
diseasecountdown=5 | |
#infect | |
def infect(): | |
for i in xrange(len(population)): | |
population[i].disease() | |
TurnNow() | |
#iterate | |
while population: | |
TurnNow() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment