// "Probabilistic" - a probabilistic runnable // subclass must implement run {} to do first action and schedule // next steps with at() or atRelative() // Creates its own scheduler if none is set // Steppable is implemented only as convenience // (it steps the whole scheduler) // TODO: This is not very clear asclass Probabilistic extends Meta implements IProbabilistic, Steppable { IProbabilisticScheduler ps; void initScheduler { if (ps == null) setScheduler(new ProbabilisticScheduler); } public void setScheduler(IProbabilisticScheduler ps) { this.ps = ps; } public IProbabilisticScheduler scheduler() { initScheduler(); ret ps; } // Breaking change: Made this relative void schedule aka at(Runnable action) { scheduleRelative(1.0, action); } void schedule aka at(double probability, Runnable action) { initScheduler(); ps.at(probability, action); } void scheduleRelative aka atRelative(double probability, Runnable action) { initScheduler(); ps.atRelative(probability, action); } void scheduleAll(Iterable actions) { forEach schedule(actions); } void scheduleAll(double probability, Iterable actions) { forEach(actions, a -> schedule(probability, a)); } void scheduleAllRelative(double probability, Iterable actions) { forEach(actions, a -> scheduleRelative(probability, a)); } ////// the "weird" convenience stuff void stepAll() { main stepAll(scheduler()); } // call run() before public bool step() { ret scheduler().step(); } void runFor(double seconds) { stepForNSeconds(seconds, scheduler()); } }