-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·52 lines (38 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pygame as pg
from p5 import random_uniform as rd
from p5 import Vector
from Evolver import *
pg.init()
w, h = 800, 600
window = pg.display.set_mode((w, h))
pg.display.set_caption("APH")
evolvers = [Evolver(rd(w), rd(h)) for _ in range(10)]
food = [Vector(rd(w), rd(h)) for _ in range(100)]
poison = [Vector(rd(w), rd(h)) for _ in range(30)]
run = True
while run:
pg.time.delay(100)
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
window.fill(0)
if rd(1) < 0.3:
food.append(Vector(rd(w), rd(h)))
if rd(1) < 0.1:
poison.append(Vector(rd(w), rd(h)))
for f in food:
pg.draw.circle(window, (0, 255, 0), (f.x, f.y), 2)
for p in poison:
pg.draw.circle(window, (255, 0, 0), (p.x, p.y), 2)
for e in reversed(evolvers):
e.boundaries(w, h)
e.behaviour(food, poison)
e.update()
e.display(window)
if e.dead():
evolvers.remove(e)
son = e.clone(rd(w), rd(h))
if son:
evolvers.append(son)
pg.display.update()
pg.quit()