-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (73 loc) · 1.66 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from Hunted import Bird
from neurlnet import Neuralnet
from Hunter import Predator
from p5 import *
from copy import deepcopy
import numpy as np
global bird
global pred
global nodead
global saveme
nodead = True
global count
count = 0
net = Neuralnet(flag=True)
bird = [Bird() for i in range(10)]
pred = [Predator(net, net) for i in range(2)]
def setup():
size(1270, 680)
no_stroke()
fill(255)
def alldead():
global nodead
if len(bird) == 0:
nodead = False
for i, k in enumerate(pred):
print("preditor " + str(i) + " killed :", k.kill)
def key_pressed(event):
global saveme
if event.key == 'S':
np.savez("save.npz", saveme.w1, saveme.w2, saveme.w3)
print("saved")
def baby(pred):
global saveme
a = []
y=[]
for pre in pred:
y.append(pre.kill)
a.append(pre.rank())
first = sorted(a)[0]
second = sorted(a)[1]
i = a.index(first)
j = a.index(second)
print(a, i, j)
saveme = deepcopy(pred[i].net)
one = deepcopy(pred[i])
one.forone()
net = deepcopy(pred[i].net)
net2 = deepcopy(pred[j].net)
pred = [Predator(net, net2) for i in range(2)]
pred.append(one)
return pred
def draw():
global nodead
nodead = True
global bird
global pred
global count
count += 1
alldead()
background(255)
if count < 700 and nodead:
for bir in bird:
bir.run(pred)
for pre in pred:
pre.run(bird)
pre.time()
# pre.movebitch(pred)
else:
count = 0
bird = [Bird() for i in range(10)]
pred = baby(pred)
if __name__ == '__main__':
run()