****Traffic Week 2: Cars behavior

Week 2 Challenges: Movement of the cars in one lane without passing

In the Car tab: When Forever button is pushed
1- Check the car status. If the car status is "good", a car has the tendency to accelerate, so its speed would randomly increase by 0.1:
Set my speed to my speed + (random 2)/10

2- If the car exits the right of the screen, a NEW car comes in from the left of the screen. Use Teleport.

3- forward "my speed"
because "speed" can be considered as the distance travelled in one tick based on the equation:
distance = speed x time where time is 1 tick.

What do you notice?
4- Cars are moving on top of each other. Need a collision block that calls a procedure to tell the car behind the slow car to slow down by setting the speed to the speed of the car in front and setting its status to "delayed"

Speed and Status are traits of the car agent.
Speed ranges between 0.5 - 0.8 at start based on the randomness in setup.

Programmer notes:
1- We need to use "yield" in the setup code before calling the procedure. I think there must be an issue where brand-new agents aren't properly placed into the binning system for detection. The yield waits for the binning process to work.

2- No more than 10 cars can be used in this setup if we want the cars to scatter without overlap on the x-axis. We need to be careful with the scatter procedure - if we change the numbers to count within (for example) 10 steps > 0, we get an infinite loop because that number of cars cannot spread evenly into that amount of space. Count Cars within 5 steps > 0, and it looks very nicely spread out.

  • 0 (Current Version) View Project History
Engine speed5
Loading...
0%

Loading...