-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.pde
49 lines (42 loc) · 1.14 KB
/
Player.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
49
class Player {
float fitness;
Genome brain;
float wins = 0;
float losses = 0;
float draws = 0;
float gamesPlayed = 0;
int genomeInputs = 9;
int genomeOutputs = 9;
float[] vision = new float[genomeInputs];
float[] decision = new float[genomeOutputs];
Player() {
brain = new Genome(genomeInputs, genomeOutputs);
vision = new float[genomeInputs];
}
float[] think(Space[] spaces, boolean isTeamCorrect) {
for(int i = 0; i < spaces.length; i++){
if(isTeamCorrect) vision[i] = spaces[i].team;
else{
if(spaces[i].team == -1) vision[i] = 1;
else if(spaces[i].team == 1) vision[i] = -1;
}
}
return brain.feedForward(vision);
}
Player clone() {
Player clone = new Player();
clone.brain = brain.clone();
clone.fitness = fitness;
clone.brain.generateNetwork();
return clone;
}
void calculateFitness() {
fitness = ((draws * 7.5) + (wins * 10) + (losses * -10)) / gamesPlayed;
}
Player crossover(Player parent2) {
Player child = new Player();
child.brain = brain.crossover(parent2.brain);
child.brain.generateNetwork();
return child;
}
}