****Traffic Week 3: Cars status stopped by Roadblock

Week 3 Challenges: Car movement to be continued
In the Car tab:

1- Watching a car that is delayed, what do you notice about its speed?
Once delayed, it moves slowly even after the car in front of it moves on.
New behavior: Once the car in front of it speeds up then the delayed car has a "good" status and tries to speed up too.

Add a conditional statement such that if there is no car in front and the car's status is "delayed", its status changes back to "good"

2- In the Interface, add two push buttons, one for "Add Roadblock", and one for "Remove Roadblock".

3- Add a breed named "Roadblock"

4- In the World, When "Add Roadblock" create a roadblock on y = -2 and x randomly between 0-50.

5- In the Roadblock tab, When "Remove Roadblock" is pushed, delete Roadblock.

6- Make the cars stop when they collide with a Roadblock. Set status to "stopped".
Therefore, car status can have three values: "good", "stopped", or "delayed".

7- If the car is stopped and the Roadblock is removed, status is changed to "good" and the speed is back to original set-up speed.

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...