Log In  

Cart #57097 | 2018-09-25 | Code ▽ | Embed ▽ | No License
1


STANDARD PICO-8 COPYRIGHT
Details: https://www.lexaloffle.com/bbs/?tid=31927


UPDATED 09-24-18
WHAT'S NEW ??
09-25-18 (final)

  • Decrease chance cars will back up when in a jam

09-24-18

  • Allow traffic to back up if it gets clogged.
  • Traffic level now set default at =3=

Cart #56995 | 2018-09-22 | Code ▽ | Embed ▽ | No License
1


09-22-18

  • First draft
  • Traffic level set default at =1=

Alright, with that out of the way, what does this cart do ?

It is a simulation of automobiles. I was influenced by my Dad on this. For years ago he was interested in writing programs that simulated human life.

He wrote one in Turbo Pascal that had green dots all over it. They moved around slightly, sometimes traveling in a straight line. Sometimes standing still, sometimes wandering a bit. But if one green dot got too crowed by the other green dots it had a chance of going BERZERK.

A BERZERK dot would turn red and start to kill green dots. When enough bodies were found by green dots though, the green dots would clustered together and 3 of them would make a single blue-dot, a policeman, who would kill a red dot - restoring order to the community.

It was all quite fascinating to watch, and the method I'm using here is very similar to the method he used. Where no actual "dot" had its own identity, it was just chosen as a COMPONENT with one invisible number to state its "brain." You can see that I wrote a "component" type of Space Invaders HERE:

https://www.lexaloffle.com/bbs/?pid=55875&tid=31766

Back in QBasic years ago I wrote a program called Traffic to simulate automobile traffic. 4-cars coming from all directions and yet ... few if any pileups would occur. Why ?

HOMEWORK:

  1. Easy question. Why are there no head-on collisions ?
    Explain.

  2. Difficult. Why are pileups extremely rare at a traffic setting 1 ? (hold (O) to confirm this)
    Explain.

  3. Most difficult. If a pileup does occur, what could be changed in the code so cars would automatically clear it ?
    Explain.
P#56996 2018-09-22 13:02 ( Edited 2018-09-26 03:16)

very cool man! i like the patterns that emerge when a full screen jam occurs :)

P#57055 2018-09-24 20:28 ( Edited 2018-09-25 00:28)

Glad you like it, notb, but drabbit ... that's not supposed to happen. Question, what could do you think can be changed in the code to prevent future pile-ups ?

P#57056 2018-09-24 20:41 ( Edited 2018-09-25 00:48)

well it always seems to start from the very rare 4-way collision. in my screen shot, you can see where it happens near the intersection of lanes 3 and 6. all 4 colors meet and the dead lock begins.

if i were coding it, i'd do a check for this special edge case and introduce some kind of novel behavior like moving in reverse or changing lanes. probably it would introduce more edge cases but they would be even more rare I would think. really interesting problem, honestly!

P#57057 2018-09-24 21:19 ( Edited 2018-09-25 01:20)

You are partially correct, notb. When I did this back in QBasic, I set it so any "vehicle" that was stopped had a chance of putting it in reverse to back up and clear the road.

Let's make that change and see if it runs any better ... updating above.

New question, without changing the actual amount or flow of traffic, what could be changed in the code to create more pileups and jams but still have the ability to clear it when it occurs ?

P#57060 2018-09-24 23:25 ( Edited 2018-09-25 04:08)

I would probably just take some randomness out and spawn cars at precise timings to cause the jams

P#57069 2018-09-25 04:07 ( Edited 2018-09-25 08:07)

Simpler than that, notb. Decrease the chance they will back up. Let's see that in action ... updating above.

And that's it ! That concludes the functionality and exploration of this cart (as far as I can tell) :)

P#57096 2018-09-25 14:59 ( Edited 2018-09-25 19:01)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:17:34 | 0.014s | Q:22