AI Features

Merging Tiles and Scoring

Learn how to combine compress_row and merge_row and create a full left move.

By the end of this lesson, you will:

  • Generate detailed specs for merge_row(row: list[int]) -> tuple[list[int], int] with the help of AI.

  • Understand the exact 2048 merge rules (especially tricky cases like [2, 2, 2, 0]).

  • Generate code for the merge_row function, with the help of specs.

  • Test the AI-generated code.

  • See how compress_row and merge_row will combine to create a full left move.

Merged tiles in row when the left arrow key is pressed, score updated by 4
Merged tiles in row when the left arrow key is pressed, score updated by 4

If you look at the illustration closely, we can compress a row to the left, then merge any adjacent tiles that can be merged, and compress again to achieve the final row state. ...