Elevator Simulator
Elevator Simulator Challenge with Client/Server Architecture
You are being asked to design and build the navigation logic for an elevator in a building. The building has 6 floors. Each floor has a button or buttons outside of the elevator to summon the elevator and tell it what direction a passenger wants to go. Floors 2-5 have up and down buttons, floor 1 has an up button only, and floor 6 has a down button only. The elevator has buttons inside for passengers to tell it what floor they want to go to, so there are 6 buttons inside, one for each floor. The navigation logic you write should asynchronously take button presses as input in a format of your choice. This simulates the button presses of a “passenger”. To show your navigation logic in use, you should log a simulated elevator’s movements and stops (in terms of the floor numbers) as output. Model the elevator as taking 3 seconds to go from one floor to the next and 4 seconds to make a stop at a floor.
The navigation logic should satisfy these constraints:
- Passengers should be able to press an outside button to summon the elevator to stop at their floor and an inside button to be taken to the specified floor.
- A passenger who presses an outside button should be passed by the elevator at most one time before the elevator makes a stop at their floor to pick them up.
- A passenger who presses an inside button that is compatible with the elevator’s current direction (e.g. floor 6 when the elevator is at floor 3 traveling upwards) should be taken to that floor without experiencing a change in the elevator’s direction.
- A passenger who presses an inside button that is NOT compatible with the elevator’s current direction (e.g. floor 6 when the elevator is at floor 3 traveling downwards) should be taken to the requested floor after all requests that are compatible with the elevator’s current direction are fulfilled.