IA_PathFinder/AIPathFinder.pde
2022-05-07 16:57:05 +03:00

56 lines
1.2 KiB
Plaintext

PVector goal;
Obstacles obstacles;
Genetic AI;
boolean pause = false;
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(){
if(pause) {
return;
}
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(){
pause = !pause;
}