-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brain.pde
48 lines (42 loc) · 871 Bytes
/
Brain.pde
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
class Brain
{
PVector[] direction;
int step = 0;
Brain(int size)
{
direction = new PVector[size];
randomize();
}
void randomize()
{
for (int i = 0; i< direction.length; i++)
{
float randomAngle = random(2*PI);
direction[i] = PVector.fromAngle(randomAngle);
}
}
Brain clone()
{
Brain clone = new Brain(direction.length);
{
for (int i = 0; i< direction.length; i++)
{
clone.direction[i] = direction[i].copy();
}
return clone;
}
}
void mutate()
{
float mutationrate = 0.01;
for (int i = 0; i<direction.length; i++)
{
float rand = random(1);
if (rand < mutationrate)
{
float randomAngle = random(2*PI);
direction[i] = PVector.fromAngle(randomAngle);
}
}
}
}