Question
Implement a simplistic highway simulation in C language . The 'highway' is (rows x cols) grid of cells that can be occupied by a vehicle
Implement a simplistic highway simulation in C language.
The 'highway' is (rows x cols) grid of cells that can be occupied by a vehicle or not. All traffic starts at the left side of of the grid (at column 0) and travels right on, never switching lane (i.e., row). If a car moves beyond the last column it exits the simulation. As input you will be given a list of arrival times of vehicles, the goal is to produce the state of the highway after a specified number of simulation steps. In this version, there is just 1 vehicle type: all vehicles get to move 1 step to the right in each time step. The highway is a (rows x cols) grid, where row 0 corresponds to the topmost lane, and column 0 is the leftmost segment. I.e., a 3 lane highway of 10 segments looks like this:
.......... <- row 0, is the topmost lane
..........
..........
^ | column 0, is the leftmost segment
The simulation is executed in discrete time steps. Each step consists of 2 phases:
1) the movement phase
2) the arrival phase.
In the movement phase, all the vehicles that are already on the highway get to move. They do not move synchronous, but one after another: vehicles that entered the simulation first get to move first. After all vehicles already on the board have been given the opportunity to move, new vehicles can arrive. These are read from a list that serves as the program input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started