draft of a new project. puts organisms in a environment and evolves their code
import numpy as np
import math
class Cell:
def __init__(self, position, world):
#self.center = position
#self.blocks = [position]
#world.cells.append(self)
#self.energy = world.initenergy
#self.inst = Code()
def step(self):
#try:
#self.Code.run()()
#except:
#pass
def grow(self):
#while 1
#pick random cell
#check if it has any edges
#pick random edge and fill
def move(self):
#call position on world class
def make(self):
#mutate code, place in front
def eat(self):
#of the objects touching, dissapear one
#add energy
def atk(self):
#of the objects touching, dissapear one cell
#make sure to call that cell and split
#convert to food
def see(self):
#touching search
#also farthest search
def turn(self):
#rotate direction so that movement is different
class Code:
oplist = [Cell.grow, Cell.move, Cell.make, Cell.eat, Cell.atk, Cell.see]
loops = ['for', 'if', 'while']
conditional = [Cell.size, Cell.energy, Cell.sight, Cell.danger]
other = ['break', 'pass']
def __init__(self):
self.topnode = {None:[]}
def codeiterate(self, function):
#queue root node
#while queue
#pick node in queue
#visit node and apply function to it
#add all children to queue
#delete node from queue
def shuffle(self):
#use codeiterate and call random.shuffle on a list
def prune(self):
#probablility of deleting random code with codeiterate
def mutate(self):
#swap out and switch 'for', 'if', and 'while' while codeiterating
def clone(self):
#duplicate lines while codeiterating
def mix(self, other):
#not sure yet
#def dfs(self, graph, string):
#string = graph.keys()[0]
#if not(graph[string]):
#return nullstring
#for k in graph[string]:
#indented add dfs(graph, string)
#return string
def run(self):
#inst = exec(dfs(self.topnode))
#return inst
class World:
def __init__(self, size, initenergy, decayrate, toroidal = True, solar):
#self.grid = np.zeros(size)
#self.cells = []
#self.initenergy = initenergy
#self.decayrate = decayrate
#self.toroidal = toroidal
#self.solar = solar
def move(self, obj):
#check collision
#move if possible
def step(self):
#for each cell
#run decay, solar, etc
#run code