xxxxxxxxxx
56
var obst = [];
var player;
var popul;
var numOfDots = 500;
globalMutationRate = 0.04;
//ga code
var lowest_alive = 0;
function setup() {
createCanvas(800, 800);
obst.push(new Obstacles(0,600,500,10));
obst.push(new Obstacles(600,200,500,10));
obst.push(new Obstacles(0,200,550,10));
//player = new Player(50,700);
popul = new Population(numOfDots);
}
function draw() {
background(220);
for(let i = 0; i<= obst.length - 1; i++) {
obst[i].show();
}
if(!popul.done()) {
popul.updateAlive();
} else {
popul.calculateFitness();
popul.naturalSelection();
}
//player.update();
//player.show();
fill(0,255,0);
strokeWeight(1);
//start
ellipse(50,700,8,8);
//goal
fill(255,0,0);
ellipse(700,50,8,8);
showInfo();
}
function showInfo() {
fill(0);
textAlign(LEFT);
textSize(10);
let tempStepsLeft = popul.players[lowest_alive].brain.total_steps - popul.players[lowest_alive].brain.step - 1;
let tempDistToGoal = abs(p5.Vector.dist(popul.players[lowest_alive].position,popul.players[lowest_alive].goal));
text("Dist to Goal: " + tempDistToGoal,30,height - 80);
text("Actions Left: " + tempStepsLeft,30,height - 50);
text("Gen: " + popul.gen, 30, height - 60);
text("Left Alive: " + popul.numAlive, 30, height - 70);
}