Editor

Move the snake

Pygame challenges · Snake, step 1 of 4 · 15 XP

The snake is frozen: its head never moves.

Your task

The board is a grid of cells, each (column, row), and a direction is how far to move: (1, 0) is right, (-1, 0) left, (0, -1) up and (0, 1) down (rows count downwards, like pygame's y).

Write next_head(head, direction): the cell the head moves into.

The function is at the top of the program, marked fix this. Press Run to play the game as it is, then Check when your function is ready.

What Check tests

CallShould give
rightnext_head((5, 5), (1, 0))(6, 5)
upnext_head((5, 5), (0, -1))(5, 4)
left, off the boardnext_head((0, 3), (-1, 0))(-1, 3)
downnext_head((2, 9), (0, 1))(2, 10)