-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopulation.java
More file actions
48 lines (41 loc) · 1.06 KB
/
Copy pathPopulation.java
File metadata and controls
48 lines (41 loc) · 1.06 KB
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
public class Population {
private Combos c[];
private int size;
public Population(int size) {
this.size = size;
c = new Combos[size];
for (int i = 0; i < size; i++)
c[i] = new Combos();
}
public int getScore(int num) {
return c[num].getScore();
}
public int getBestScoreIndex() {
int best = 0;
for (int i = 0; i < size; i++)
if (c[i].getScore() > c[best].getScore())
best = i;
System.out.println("Best score is: " + c[best].getScore());
return best;
}
private void generateElement(int index) {
c[index] = new Combos();
}
public void evolve() {
Combos bestCombo = c[getBestScoreIndex()];
c[0] = bestCombo;
for (int i = 1; i < size; i++) {
c[i] = new Combos(bestCombo);
c[i].mutateResponse(100);
}
}
public int findResponse(char[] inputBoard) {
Combos best = c[getBestScoreIndex()];
return best.findResponse(inputBoard);
}
public void printScores() {
System.out.print("Scores: ");
for (int i = 0; i < size; i++)
System.out.print(c[i].getScore() + ", ");
}
}