You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Hamza elkhatri b84f103eb3
CON-1816-MARKDOWN-road-intersection-raid-for-java-piscine (#2100)
1 year ago
..
audit CON-1816-MARKDOWN-road-intersection-raid-for-java-piscine (#2100) 1 year ago
README.md CON-1816-MARKDOWN-road-intersection-raid-for-java-piscine (#2100) 1 year ago

README.md

Jraffic

Objectives

Traffic congestion can be a major problem in urban areas. Your task is to create a traffic control strategy and visualize it with a simulation. The choice of library and file system is up to you. However, you might find the JavaFX library useful for creating GUI applications.

Instructions

Environment and Rules

You should create an environment that includes the objects specified in this section. The representation of the objects is entirely up to you.

1. Roads

Create two intersecting roads, each with a single lane in both directions. Traffic approaching the intersection can choose between :

  • going straight
  • turning left
  • turning right

Below is a simple representation:

                        North
                    |  ↓  |  ↑  |
                    |  ↓  |  ↑  |
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
     _______________|     |     |_______________
     ← ←                                     ← ←
East ---------------             --------------- West
     → →                                     → →
     _______________             _______________
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
                    |     |     |
                    |  ↓  |  ↑  |
                    |  ↓  |  ↑  |
                        South

2. Traffic Lights

Position traffic lights at the points where each lane enters the intersection. Your traffic lights should only have two colors: red and green.

You can use any algorithm to control the traffic lights. However, the system should be efficient enough to avoid traffic congestion (8 or more vehicles). The primary aim of the traffic light system is to prevent collisions at the intersection.

3. Vehicles

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

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

  • Vehicles must be painted in a color that illustrates the route they will follow. The colors are up to you to decide, and your choices will need to be made available during the audit of the raid. For example, all cars which make a right turn could be painted yellow. It's really up to you though.

  • It is not possible for the vehicle to change its selected route.

  • Each vehicle must have a fixed velocity.

  • A safety distance from other vehicles must be maintained. If one vehicle stops, the following vehicle must also stop before it gets too close to the stationary vehicle in front.

  • Vehicles must stop if the traffic light is red and proceed otherwise.

  • There are no other vehicle types with special privileges. You can consider that there are no emergency vehicles in your capital city.


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.

  • Up: moves towards the intersection from the south.
  • Down: moves towards the intersection from the north.
  • Right: moves towards the intersection from the west.
  • Left: moves towards the intersection from the east.
  • r: moves towards the intersection from a random direction.
  • Esc Escape: ends the simulation.

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