2022-05-07 12:08:13 +00:00
|
|
|
PVector goal;
|
|
|
|
Obstacles obstacles;
|
|
|
|
Genetic AI;
|
2022-05-07 13:57:05 +00:00
|
|
|
boolean pause = false;
|
2022-05-07 12:08:13 +00:00
|
|
|
|
|
|
|
void setup(){
|
|
|
|
size(800, 800);
|
|
|
|
frameRate(100000);
|
|
|
|
goal=new PVector(400, 10);
|
|
|
|
obstacles=new Obstacles();
|
|
|
|
AI=new Genetic(true);
|
|
|
|
|
|
|
|
obstacles.add(new Obstacle(300, 580, 800, 600));
|
|
|
|
obstacles.add(new Obstacle(350, 30, 450, 50));
|
|
|
|
obstacles.add(new Obstacle(600, 10, 620, 300));
|
|
|
|
obstacles.add(new Obstacle(300, 650, 320, 800));
|
|
|
|
obstacles.add(new Obstacle(100, 400, 800, 420));
|
|
|
|
obstacles.add(new Obstacle(0, 520, 200, 540));
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(){
|
2022-05-07 13:57:05 +00:00
|
|
|
if(pause) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-07 12:08:13 +00:00
|
|
|
background(255);
|
|
|
|
|
|
|
|
//draw goal
|
|
|
|
fill(255, 0, 0);
|
|
|
|
ellipse(goal.x, goal.y, 10, 10);
|
|
|
|
|
|
|
|
//draw obstacles
|
|
|
|
obstacles.display();
|
|
|
|
|
|
|
|
//run genetica
|
|
|
|
if(!AI.isDone()){
|
|
|
|
AI.update();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
AI.nextGeneration();
|
|
|
|
}
|
|
|
|
|
|
|
|
//print infos
|
|
|
|
fill(0);
|
|
|
|
text("Generation: "+AI.generation, 10, 10);
|
|
|
|
text("Minimal steps: "+AI.lessSteps, 10, 20);
|
|
|
|
text("Minimal distance: "+AI.lessDistance, 10, 30);
|
|
|
|
text("Max fitness: "+AI.maxFitness, 10, 40);
|
|
|
|
text("Goal reached: "+AI.goalReached, 10, 50);
|
|
|
|
text("Steps/s: "+frameRate, 10, 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseClicked(){
|
2022-05-07 13:57:05 +00:00
|
|
|
pause = !pause;
|
2022-05-07 12:08:13 +00:00
|
|
|
}
|