Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elevator Saga: Python Edition

The elevator programming game, now for Python!

Your task is to program the movement of elevators, by writing a program in Python3. The goal is to transport people in an efficient manner.

Image of Elevator Saga in browser

Play

uv run elevatorsaga play

uv fetches Python and the dependencies itself, so that is the only step.

That starts a local server, opens your browser, and writes a starter solution.py in the current directory if you do not have one. Edit that file in your own editor and save, the game reloads it and restarts the challenge. There is an editor in the page too, and it writes the same file.

Everything runs on your machine. Your code is just code: print() goes to your terminal, breakpoint() inside update() drops you into a debugger, and your editor can autocomplete the API from the type hints.

Write

from elevatorsaga import Elevator, Floor


def init(elevators: list[Elevator], floors: list[Floor]) -> None:
    elevator = elevators[0]

    @elevator.on("idle")
    def _() -> None:
        elevator.go_to_floor(0)
        elevator.go_to_floor(1)


def update(dt: float, elevators: list[Elevator], floors: list[Floor]) -> None:
    # Called every frame. Most solutions do all their work in init() and leave this empty.
    pass

The full API is on the game's Help page, or in the docstrings in src/elevatorsaga/interfaces.py and floor.py.

Other commands

Same uv run prefix from a clone, or bare if you installed it as a tool.

elevatorsaga run  -c 5 -s 42    # play challenge 5 with seed 42 headlessly, print the result
elevatorsaga bench -n 10        # average your solution over 10 seeds per scenario
elevatorsaga challenges         # list the challenges and their goals

Runs are seeded and reproducible. The seed is shown in the stats panel while you play, so a run that goes wrong in the browser replays exactly with elevatorsaga run -c N -s SEED.

Develop

uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy src/elevatorsaga

Credit & Acknowledgement

Elevator Saga was originally written in JavaScript by Magnus Wolffelt.

About

The elevator programming game, now for Python!

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages