-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLeaderboard.pde
110 lines (94 loc) · 2.66 KB
/
Leaderboard.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
class leaderboard {
//current TOP 10
int[] generation = {};
int[] score = {};
int[] colour = {};
int[] last_position = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; //for animation in bars
float[] generation_array = {};
float[] top1 = {};
leaderboard()
{}
void update(ArrayList<organism> board)
{
reset_last_position();
if(gen == 1)
first_update(board);
else
{
for(int i=0; i<10 && board.get(i).get_closestGoal()>score[9] ; i++) //until 10 or score now enough to TOP 10 for each new score
{
boolean flag = true;
for(int j=0; j<10 && flag==true; j++) //flag for not repeat, for each current TOP10
{
if(board.get(i).get_closestGoal()==score[j] && board.get(i).get_color()==colour[j]) // check if new entry or just mom or dad from previous
{
flag = false;
continue;
}
if(board.get(i).get_closestGoal()>score[j])
{
for(int k=9; k>j; k--)
{
generation[k]=generation[k-1];
score[k]=score[k-1];
colour[k]=colour[k-1];
last_position[k]=last_position[k-1];
}
generation[j]=gen;
score[j]=board.get(i).get_closestGoal();
colour[j]=board.get(i).get_color();
last_position[j]=11;
flag = false;
}
}
}
}
//for(int i = 0; i<10; i++)
//println("#"+(i+1)+" Score: "+score[i]+" color: "+colour[i]+" | GEN: "+generation[i]);
//update others things maybe
top1 = append(top1, score[0]);
generation_array = append(generation_array, gen);
}
//local functions
private void first_update(ArrayList<organism> board)
{
for (int t=0; t<10; t++)
{
generation = append(generation, 1);
score = append(score, board.get(t).get_closestGoal());
int c = (int) map(board.get(t).get_mutation(), min_mutation, max_mutation, 850, 0);
colour = append(colour, c);
}
generation_array = append(generation_array, 1);
top1 = append(top1, score[0]);
}
int get_score(int index)
{
return score[index];
}
int get_color(int index)
{
return colour[index];
}
int get_generation(int index)
{
return generation[index];
}
float[] get_top1()
{
return top1;
}
float[] get_generation_array()
{
return generation_array;
}
private void reset_last_position()
{
for(int i=0; i<10; i++)
last_position[i]=i;
}
int get_last_position(int index)
{
return last_position[index];
}
} //end of class