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.
uv run elevatorsaga playuv 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.
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.
passThe full API is on the game's Help page, or in the docstrings in
src/elevatorsaga/interfaces.py and floor.py.
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 goalsRuns 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.
uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy src/elevatorsagaElevator Saga was originally written in JavaScript by Magnus Wolffelt.
