-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionBlock.js
95 lines (86 loc) · 2.62 KB
/
FunctionBlock.js
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
let PlatformPostionMemoryX;
let PlatformPostionMemoryY;
function Train(Eterations){
for (let i = 0; i < Eterations; ++i){
if (Rockets.length != Population){
for (let k = 0; k < CurrentGroup.length; ++k){
if (CurrentGroup[k].HasCrashed)
SavedRockets.push(CurrentGroup.splice(k, 1)[0]);
}
if (CurrentGroup.length == 0){
if (CurrentGroupNum <= Groups - 1){
CurrentGroupNum++;
HasLandedThisGen += HasLandedThisGroup;
CountSuccesRate();
if (Rockets.length != Population){
CurrentGroup = Rockets.splice(0, RocketsPerGroup);
}
}
else{
HasLandedThisGen += HasLandedThisGroup;
CountSuccesRate();
HasLandedThisGen = 0;
CreateNextGeneration();
CurrentGroupNum = 1;
CurrentGroup = Rockets.splice(0, RocketsPerGroup);
}
}
for (let i = 0; i < CurrentGroup.length; ++i){
CurrentGroup[i].Update(LifeSpan);
if (CurrentGroup[i].Timer > LifeSpan)
SavedRockets.push(CurrentGroup.splice(i, 1)[0]);
}
}
}
}
function CalculatePlatformScatter(){
if (AverageSuccesPrecentage >= 10 && PlatformScatter < windowWidth / 2 - 150){
PlatformScatter += 5;
}
else if (AverageSuccesPrecentage <= 2 && AverageSuccesPrecentage > 0)
if (PlatformScatter > 30)
PlatformScatter -= 15;
else
PlatformScatter = 0;
else if (AverageSuccesPrecentage == 0)
PlatformScatter = 0;
}
let TenLastSuccesRates = [];
function PutSuccess(X){
TenLastSuccesRates.push(X);
if (TenLastSuccesRates.length > 10)
TenLastSuccesRates.splice(0, 1);
let Sum = 0;
for (let i = 0; i < TenLastSuccesRates.length; ++i){
Sum += TenLastSuccesRates[i];
}
AverageSuccesPrecentage = Math.floor(Sum / TenLastSuccesRates.length);
}
function CountSuccesRate(){
let Sum = 0;
for (let i = 0; i < CurrentGroup.length; ++i){
if (CurrentGroup[i].HasLanded == true)
Sum++;
}
HasLandedThisGroup = Sum;
SuccesPercentage = Math.floor((HasLandedThisGen + HasLandedThisGroup) / Population * 100);
}
function IsAnyBodyAlive(){
let Flag = false;
for (let i = 0; i < Population; ++i){
if (!Rockets[i].HasCrashed)
Flag = true;
}
return Flag;
}
let ShouldSave = false;
function keyPressed(){
if (key == "s"){
ShouldSave = true;
}
}
function LoadPretrainedModel(){
let PreTrainedModelBrain = NeuralNetwork.Deserialize(PreTrainedModelBrainData);
PreTrainedModel = new Rocket;
PreTrainedModel.Brain = PreTrainedModelBrain;
}