Created
February 26, 2018 05:01
-
-
Save christabor/3b0cffc517162ab286a4a9d0f3aeda55 to your computer and use it in GitHub Desktop.
plant type reproduction automata experiment
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
from random import choice | |
types = ['sporophyte', 'gametophyte'] | |
class Plant(object): | |
def __init__(self, type=None): | |
self.type = type or choice(types) | |
self.children = [] | |
def __repr__(self): | |
return '<Plant="{}">'.format(self.type) | |
def reproduce(self): | |
if self.type == 'sporophyte': | |
self.children.append(Plant(type='gametophyte')) | |
else: | |
self.children.append(Plant(type='sporophyte')) | |
def make_conditions(): | |
plants = [Plant(), Plant()] | |
iterations = 20 | |
while iterations > 0: | |
print('iteration={}'.format(iterations)) | |
for p in plants: | |
p.reproduce() | |
for p in plants: | |
for child in p.children: | |
child.reproduce() | |
iterations -= 1 | |
return plants | |
def show(plants): | |
for p in plants: | |
print(p) | |
for child in p.children: | |
print(' {}'.format(child)) | |
for grandchild in child.children: | |
print(' {}'.format(grandchild)) | |
if __name__ == '__main__': | |
plants = make_conditions() | |
show(plants) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment