From 911714f9b5e6c57081654859bed2bb3f3c1f1e5a Mon Sep 17 00:00:00 2001 From: guusvdongen Date: Wed, 8 Apr 2015 21:15:45 +0200 Subject: [PATCH] Update Visitor.java --- Applicatie/Visitor.java | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Applicatie/Visitor.java b/Applicatie/Visitor.java index 96c84ba..7b0df29 100644 --- a/Applicatie/Visitor.java +++ b/Applicatie/Visitor.java @@ -316,13 +316,14 @@ public class Visitor { } } + public void fillActions() { int startTime = 540; int stopTime = 1260; while (startTime < stopTime) { int random = (int) Math.floor(Math.random() * 51); - if (random < 40) { + if (random < 30) { Point2D position = null; DrawObject targetStage = null; ArrayList posEvents = new ArrayList(); @@ -331,17 +332,29 @@ public class Visitor { posEvents.add(e); } } + + int totalPopularity = 0; + for (Event ev : posEvents){ + totalPopularity += ev.getExpectedPopularity(); + } - if (posEvents.size() != 0) { - int r = (int) Math.floor(Math.random() * posEvents.size()); - Event evs = posEvents.get(r); - for (DrawObject d : objects) { - if (d.getFileName().equals("stage")) { - Stage s = (Stage) d; - if (s.getStage().getName() - .equals(evs.getStage().getName())) { - position = s.getPosition(); - targetStage = d; + Random rand = new Random(); + int n = rand.nextInt(totalPopularity) + 1; + int currentPop = 0; + if (posEvents != null){ + for (Event evs : posEvents){ + int before = currentPop; + currentPop = currentPop + evs.getExpectedPopularity(); + if (before < n && currentPop >= n){ + for (DrawObject d : objects) { + if (d.getFileName().equals("stage")) { + Stage s = (Stage) d; + if (s.getStage().getName() + .equals(evs.getStage().getName())) { + position = s.getPosition(); + targetStage = d; + } + } } } } @@ -355,7 +368,7 @@ public class Visitor { } startTime = startTime + randomtime; - } else if (random >= 40 && random < 45) { + } else if (random >= 30 && random < 40) { Point2D position = null; DrawObject targetStage = null; ArrayList foodPlaces = new ArrayList(); @@ -376,7 +389,7 @@ public class Visitor { } startTime = startTime + 35; - } else if (random > 45) { + } else if (random >= 40) { Point2D position = null; DrawObject targetStage = null; ArrayList toilets = new ArrayList(); @@ -467,4 +480,4 @@ public class Visitor { } return false; } -} \ No newline at end of file +}