Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions BestTutorialEver/BestTutorialEver.pde
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ void setup() {
size(800, 800); //size of the window
frameRate(100);//increase this to make the dots go faster
test = new Population(1000);//create a new population with 1000 members
}


void draw() {
background(255);

//draw goal
Expand All @@ -19,8 +16,20 @@ void draw() {
//draw obstacle(s)
fill(0, 0, 255);

rect(0, 300, 600, 10);
rect(350, 200, 800, 10);
rect(0, 400, 450, 10);
rect(350, 600, 800, 10);

// store a bitmap of the arena
loadPixels();

}


void draw() {

// Restore the arena
updatePixels();

if (test.allDotsDead()) {
//genetic algorithm
Expand All @@ -33,4 +42,4 @@ void draw() {
test.update();
test.show();
}
}
}
4 changes: 2 additions & 2 deletions BestTutorialEver/Dot.pde
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Dot {
} else if (dist(pos.x, pos.y, goal.x, goal.y) < 5) {//if reached goal

reachedGoal = true;
} else if (pos.x< 600 && pos.y < 310 && pos.x > 0 && pos.y > 300) {//if hit obstacle
} else if (pixels[int(pos.x) + int(pos.y) * 800] == color(0, 0, 255)) {//if hit obstacle
dead = true;
}
}
Expand All @@ -85,4 +85,4 @@ class Dot {
baby.brain = brain.clone();//babies have the same brain as their parents
return baby;
}
}
}