Editor

Turn a piece

Pygame challenges · Blocks, step 1 of 3 · 20 XP

Press Up and the piece stays exactly as it was.

Your task

A piece is a list of cells (x, y) inside a small square box, size cells wide: 4 for the long piece, 3 for most others. A quarter turn clockwise moves every cell (x, y) to (size - 1 - y, x).

Write rotate(cells, size) and return the turned list.

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
the T piecerotate([(1, 0), (0, 1), (1, 1), (2, 1)], 3)[(2, 1), (1, 0), (1, 1), (1, 2)]
the long piece stands uprotate([(0, 1), (1, 1), (2, 1), (3, 1)], 4)[(2, 0), (2, 1), (2, 2), (2, 3)]
one cell in a 2 by 2 boxrotate([(0, 0)], 2)[(1, 0)]
four turns come backp = [(1, 0), (0, 1), (1, 1), (2, 1)] for _ in range(4): p = rotate(p, 3)sorted(p)[(0, 1), (1, 0), (1, 1), (2, 1)]