Skip to the workspace
Pebellslearn by building
Linked Lists, Stacks & Queues  ›  Capstone Project

Capstone — Player Engine

35 minThree structures driving one player

dsa / Capstone — Player Engine

Explore each scene at your own pace.

01 · What you're building

What you're building

Capstone — Player Engine

Definition
The player engine combines a linked list for the playlist, a queue for up-next and a stack for history, each used where it is cheapest to touch, so one function can replay button presses and report the player's state.
In plain words
A music player is three small tools working together: a chain of songs you can splice into, a waiting line that cuts in front, and a pile of what you just heard so back works. Each tool fits the way it is used.

In short: every button on Tunebox's player ends up here. The playlist is a linked chain you can splice while it plays, the up-next queue cuts in ahead of it, and the history stack remembers where you've been so back works. Each structure was picked for where it gets touched: the playlist at a node you hold, the queue at both ends, the history only at its top. This capstone connects all three in one engine, run_player, which replays a list of button presses and reports the player's state.

Three structures feeding one 'now playing' box: a stack labelled history on the left feeding in from its top, a linked chain labelled playlist with a cursor node in the middle, and a deque labelled up-next on the right feeding in from its front

What you're building

run_player(playlist, commands)

playlist is the starting list of tracks, and commands is a list of button presses applied in order. The function returns a dict:

{
    "now": "X",                     # the track playing, or None
    "history": ["A"],               # the back stack, oldest first
    "up_next": ["B"],               # the queue, front first
    "playlist": ["A", "B", "C"],    # the linked playlist, in order
}
Scene 1 of 11
Project context and further resources
You're building a piece ofTunebox — the player
This piece — run_player(): Drives playback with the queue, the history and the linked playlist together.
Scenario A listener starts a playlist, queues a friend's track, skips ahead, then hits back. Tunebox's player engine replays those presses through the queue, the history stack and the linked playlist, and reports what's playing.
run_player.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
run_player(playlist, commands) → dictThe player's state after every button press: now, history, up_next and playlist.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.