From 33d0b6c497fbaac50b1171c5387cf0ff8bc2ea7b Mon Sep 17 00:00:00 2001 From: stuphi Date: Wed, 16 May 2018 14:05:13 +0100 Subject: [PATCH] Change obstical definition and detection is done so that they only need to be defined in one place. --- BestTutorialEver/BestTutorialEver.pde | 19 ++++++++++++++----- BestTutorialEver/Dot.pde | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) mode change 100644 => 100755 BestTutorialEver/BestTutorialEver.pde mode change 100644 => 100755 BestTutorialEver/Dot.pde diff --git a/BestTutorialEver/BestTutorialEver.pde b/BestTutorialEver/BestTutorialEver.pde old mode 100644 new mode 100755 index 0f4b8b3..f00c02c --- a/BestTutorialEver/BestTutorialEver.pde +++ b/BestTutorialEver/BestTutorialEver.pde @@ -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 @@ -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 @@ -33,4 +42,4 @@ void draw() { test.update(); test.show(); } -} \ No newline at end of file +} diff --git a/BestTutorialEver/Dot.pde b/BestTutorialEver/Dot.pde old mode 100644 new mode 100755 index a6f2d71..5a0898d --- a/BestTutorialEver/Dot.pde +++ b/BestTutorialEver/Dot.pde @@ -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; } } @@ -85,4 +85,4 @@ class Dot { baby.brain = brain.clone();//babies have the same brain as their parents return baby; } -} \ No newline at end of file +}