Elevator Saga Unblocked
You are the elevator control system. Write the code, press Apply, and hope nobody waits too long.
What is Elevator Saga?
Elevator Saga is a coding puzzle in which your JavaScript runs the lifts of a simulated building. Riders appear on floors and press call buttons, and your code decides where each car goes. Each challenge sets a target, like delivering a quota of riders before time runs out, and you win by meeting it.
- Category
- Puzzle Games
- Players
- 1 player
- Plays on
- Desktop / Chromebook
- Input
- Keyboard, Mouse
- Checked
Elevator Saga flips the usual relationship with an elevator. Instead of pressing a button and waiting, you write the code that decides which button gets answered. A cutaway building fills the top of the screen, tiny riders appear and call for lifts, and your JavaScript moves the cars. Good code clears the crowd; lazy code leaves people stranded on the top floor while an empty car bounces between the bottom two. It is an open-source project by Magnus Wolffelt and contributors, and it plays unblocked in a desktop browser.
The Shape of a Program
Beneath the building is an editor preloaded with a basic program that runs but performs poorly. Your code has to be a single object exposing a pair of functions:
init(elevators, floors)runs once at the start of a challenge. Almost all your logic lives here.update(dt, elevators, floors)runs repeatedly as time passes. Many solutions leave it nearly empty.
Inside init, you attach event listeners. Elevators fire events like idle, floor_button_pressed and stopped_at_floor. Each floor reports its own up and down call buttons through up_button_pressed and down_button_pressed. Your handlers respond by calling goToFloor(), checking loadFactor() for how crowded a car has become, or reordering destinationQueue by hand.
Press Apply and the challenge restarts with your new code. A stats panel updates live with the number of people delivered, throughput per second, typical and worst waiting times, and total floors traveled.
How the Challenges Escalate
The game scores you on 18 challenges. Number one is a single car serving three floors. Further on, the building gains extra cars of varying sizes and climbs as high as 21 floors. The win condition shifts as well. Sometimes you must deliver a quota of riders before the clock runs out, sometimes the total distance your cars move is capped, and sometimes a single rider kept waiting too long means failure.
Elevator Saga controls
| To do this | Keyboard | Mouse |
|---|---|---|
| Write and edit the control program | Type in the code editor (Tab inserts four spaces) | Click inside the editor to place the cursor |
| Load your code and restart the challenge | — | Click "Apply" |
| Run, pause or restart the simulation | — | Click the Start / Pause / Restart button |
| Speed the clock up or slow it down | — | Click the minus or plus icon next to the speed number |
| Move on after a passed challenge | — | Click "Next challenge" |
| Save, reset, or recover code from before a reset | — | Click "Save", "Reset" or "Undo reset" |
Building a Better Dispatcher
Think of your code in layers, improving one thing at a time.
Layer one: obey riders. Listen for floor_button_pressed and send the car where its passengers want to go. That alone fixes the starter code.
Layer two: respond to waiting riders. Use the floors’ call button events so idle cars head to people who are waiting, instead of sitting at the lobby.
Layer three: be efficient. A car going up should stop at floors on its way rather than zigzag. Sorting or filtering destinationQueue by direction cuts wasted travel.
Layer four: respect capacity. Look at loadFactor() before pulling in to collect more people. A full car that stops anyway wastes time and moves.
Read the goal every time. A strategy tuned for speed may fail a challenge that limits moves. On those, waiting for several riders before departing is often the winning trick.
Use the time scale freely. Run at a high speed to see whether a strategy survives the full challenge, then slow down to watch exactly where riders pile up.
For Coders Who Like a Puzzle
Elevator Saga is best for people who already know some JavaScript and want a real problem to chew on. It needs a keyboard and a wide screen. If you are still learning the basics, start with Block Code Duck Pond, or practice another skill with SQL Detective Mystery.
Elevator Saga: questions players ask
How do I beat challenge 1 in Elevator Saga?
The program you start with only travels from the ground floor to the first and back, so anyone upstairs is ignored. Add a listener for the elevator's floor button event and send the car to whichever floor a rider pressed. That simple change is usually enough to pass.
How much JavaScript is needed for Elevator Saga?
Functions, objects, arrays and event callbacks are the core. You do not need any libraries. The built-in Help page documents each method and event for cars and floors, with snippets to borrow.
My code has an error. What happens?
An error line shows up in red over the code box, and no car moves until it is fixed. Code missing either required function is rejected the same way, so make sure both are still there.
Does Elevator Saga save my code?
Yes. Shortly after you pause typing, the program is written to browser storage automatically, and the Save button does it immediately. The game also keeps your chosen simulation speed.
Is there an end to the game?
After the 18 graded challenges, a 19th stage runs as an endless sandbox with no target, useful for testing a general-purpose algorithm.
Credits and license
Elevator Saga was created by Magnus Wolffelt and contributors and released as open source. FreezeNova hosts a lightly adapted copy on its own server, together with the original license file.
- Source code: github.com/magwo (original project)
- Code license: MIT
- Art & audio: MIT (graphics drawn with HTML and CSS); Font Awesome 4.1 icons under SIL OFL 1.1
- Our changes: We stripped out analytics, the Google Fonts link and links to the outside wiki and test runner, and the Help page now links back to the game. Challenges and game code are as the authors released them.