Search⌘ K
AI Features

Sliding Tiles Left

Learn to write the compress_row function to shift all tiles left on a single row in the 2048 game. Practice using AI-generated code, unit testing, and applying this logic across the entire board for accurate game state updates.

By the end of this lesson, you’ll be able to compress a single row for a left move. If you can do this for one row, you can apply the same logic to slide the entire board left, as shown in the illustration below.

Sliding tiles left without merge
Sliding tiles left without merge

Step 0: Starting point

We start from the end-of-lesson file from the previous lesson and highlight that compress_row is ...