9fa2c294a73cd4b443dc0aa02439ee65fa8d4cd1
[experiments.git] / evolution / main.py
1
2 import copy
3 import random
4
5 import logging
6
7 from entities import *
8 from systems import PygameRenderer, Movement, Behavior
9 from utils import Clock, Vector
10
11 def generateRandomGenes(entity):
12 for g in random.sample(GENES.values(), 3):
13 entity.addGene(g())
14 logging.debug("Creation: %s[%s]", entity, entity.getGenes())
15
16
17 if __name__ == "__main__":
18 logging.basicConfig(format='%(module)s:%(levelname)s:%(message)s', filename='output.log',level=logging.DEBUG)
19
20 random.seed(1)
21 clock = Clock(0.1)
22 scene = Scene("mainScene", clock)
23 size = (100, 100)
24 renderer = PygameRenderer(600, 480, "Evolution")
25 movement = Movement(size[0], size[1])
26 behavior = Behavior()
27 population = 4
28 food = 15
29 for _ in xrange(0, population):
30 b = Bot(Vector(random.randint(0, size[0] - 1), random.randint(0, size[1] - 1))).addToScene(scene)
31 generateRandomGenes(b)
32
33 for _ in xrange(0, food):
34 o = Good(Vector(random.randint(0, size[0] - 1), random.randint(0, size[1] - 1))).addToScene(scene)
35
36 renderer.update(scene)
37
38 isRunning = True
39 while isRunning:
40 for event in renderer.pygame.event.get():
41 if event.type == renderer.pygame.QUIT:
42 isRunning = False
43 clock.tick()
44
45 behavior.update(scene)
46 movement.update(scene)
47 renderer.update(scene)
48
49 renderer.close()
50 movement.close()
51 behavior.close()
52