Do you remember the [`road_intersection`](https://public.01-edu.org/subjects/road_intersection/) raid done in the Rust Piscine? Well, you will have to create another traffic control strategy and its simulation. However, it will have to be done without traffic lights and with a smart intersection management strategy this time.
Overused intersections might lead to severe traffic jams on multiple roads, which wastes drivers' time and money and causes unnecessary air pollution. Additionally, according to a study from the National Highway Traffic Safety Administration in the U.S., it is reported that about 96% of the intersection-related crashes had critical reasons to be the driver's fault, such as inadequate surveillance, false assumption of other actions, and turns with an obstructed view.
[Autonomous vehicles](https://en.wikipedia.org/wiki/Self-driving_car) (AVs) are a promising solution to traffic accidents. An optimistic prediction is that AVs will be publicly available in the next decade, and thus traffic issues related to autonomous vehicles are also being extensively investigated.
Current intersection management strategies, such as the traditional traffic lights and other more advanced methods, are designed exclusively for human drivers. With the rapid development of AVs, new traffic strategies must be taken into account.
This is where you come in. You will have to create this new traffic strategy algorithm so that AVs can pass an intersection without any collisions and with a minimum of traffic congestion.
If a vehicle is driving at a high velocity and encounters another vehicle, it must detect that vehicle and keep a safe distance from it. It should not collide!
You are free to decide the safety distance, but it must be a strictly positive value.
Animation is not just rendering an image into the canvas. By using assets, you get to decide your "world coordinate system" for the rendered image and therefore you create your own animation. But this is not enough. Basically, you must animate while moving.
1. The creation of vehicles must be done using the keyboard events. It must be able to randomly generate vehicles with different routes. The keys to be used are the following :
4. When spamming the same key, the vehicles should not be generated all at the same time. In other words, the vehicles should not be created on top of each other.
Your program must be able to generate statistics, as stated above. These must be displayed in a window, right after the user tries to exit the simulation.
- The time starts to count whenever the vehicle is detected by the **smart intersection algorithm** until the end of the intersection, which is when the vehicle is removed from the canvas.
- Consider acceleration and deceleration on the physics of your game. That means that the cars don't change automatically of speed (e.g. different cars can take different times to change from 50 to 10 depending on how good the brakes are)