SE450: Some advice: How to deal with the order of cars [16/16] Previous pageContents

You can assume that as the ArrayList of cars is iterated through, the
cars will move one at a time in the same sequence they were created.

One way to make the simulation insensitive to such
effects to to change the interface of agent from:

 Agent { void run(double time); }


 Agent { void setup(double time); void commit(); }

with the idea that these will always be called in alternation.  The
main loop becomes:

 for (t in times) {
   for (a in agents)
   for (a in agents)

And the car becomes something like this:

 Car {
   void setup(double time) {
     _velocity = // newly computed velocity
   void commit() {
     _position += _velocity;

Previous pageContents