The elevator game is a little thought experiment. It is not new, in fact Elevator Saga is another fun one. This one was just based on whatever came out of my head to see what would happen.
Here are the rules:
- There is one elevator in a building that has 10 floors.
- There are 30 passengers to transport. 15 passengers from level 1 to another floor and 15 passengers from a higher floor to level 1. However, they are all shuffled together.
- There are up to 5 people waiting for the elevator at any given time.
- The game is repeatable (all the same passengers going to the same place).
- For each floor the elevator moves will be one point.
- The goal is to transport everyone with the lowest final score.
How to Play
You will have to have Python installed. For Mac and Linux people you don't need to do anything. I can't say the same for Windows users; perhaps here.
To actually play (run) it you can download the Python file in this gist.
The engine is not particularly well written in terms of clean code, it's just what fell out as I was coding. What's important is the elevator function:
def elevator(building):for person in building.people:if person.status == Person.WAITING and \person.from_floor != building.elevator_floor:building.goto_floor(person.from_floor)returnif person.status == Person.IN_ELEVATOR:building.goto_floor(person.to_floor)return
It is a very rudimentary algorithm that can be clearly improved. As a starting point that works it scores 183.
The script animates all the lift activity and you an change the speed by alerting how long it sleeps between each floor.
On the far left is the floor number, followed by an icon that indicates if there is at least one person waiting for the elevator at that floor.
The number in the box represents the elevator itself. The number is how many passengers are currently in the elevator.
The person icons on the right show passengers that have got off at their destination floor.
I hope you have fun beating my score! :)