public

road_intersection

Objectives

Traffic, traffic, traffic…

You will need to solve the traffic problem in your capital city. Your objective will be to create a traffic control strategy, and visualize it with a simulation.

It is up to you to decide which library and file system you want to use in order to create this simulation, but we recommend that you use the sdl2 library.

Instructions

Environment and Rules

You must create an environment which contains all the objects described in this section. You can display the objects in any way you wish.

1 Roads

You will create two roads which cross each other to create an intersection. Each road will have one lane in each direction.

Traffic entering the intersection will be able to select a route by:

                        North
                    |  ↓  |  ↑  |
                    |  ↓  |  ↑  |
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
     _______________|     |     |_______________
     ← ←                                     ← ←
East ---------------             --------------- West
     β†’ β†’                                     β†’ β†’
     _______________             _______________
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
                    |  ↓  |  ↑  |
                    |  ↓  |  ↑  |
                        South

2 Traffic lights

Traffic lights are signaling devices positioned at road intersections that follow a universal color code. We all know the normal colors for traffic lights, but for this exercise, your traffic lights will only have red and green.

You will position those traffic lights at the point where each lane enters the intersection.

You can implement any algorithm you choose to control the traffic lights system, but bare in mind that traffic congestion should not be too high (8 or more vehicles).

The primary function of your traffic light system, is to avoid collisions between vehicles passing through the intersection.

3. Vehicles

  ______
 /|_||_\`.__
=`-(_)--(_)-'

The vehicles traveling through your capital city’s new junction must follow these rules:


Commands

You will use your keyboard to spawn vehicles for your simulation. You will use the arrow keys to spawn a vehicle on the appropriate side of the road, and with a random route.

It must not be possible to use the keyboard to spam the creation of vehicles; they must be created with a safe distance between them.

A safe distance is any distance which enables the vehicles to avoid crashing into each other.

Example

You can see an example for road_intersection here.

Bonus

You can implement the following optional features:

Notions