Does it fit?
Pygame challenges · Blocks, step 2 of 3 · 25 XP
Pieces fall through the floor and through each other.
Your task
The board is a list of rows, and each square is None when empty or a colour when a block is there. Write fits(cells, px, py, board): True if, with the piece's box at column px and row py, every cell lands inside the board and on an empty square.
A cell (x, y) lands on column px + x, row py + y. The board has len(board) rows and len(board[0]) columns.
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
| Call | Should give |
|---|---|
an empty board, top leftboard = [[None] * 4 for _ in range(4)]fits([(0, 0), (1, 0)], 0, 0, board) | True |
past the right edgeboard = [[None] * 4 for _ in range(4)]fits([(0, 0), (1, 0)], 3, 0, board) | False |
below the floorboard = [[None] * 4 for _ in range(4)]fits([(0, 0)], 0, 4, board) | False |
past the left edgeboard = [[None] * 4 for _ in range(4)]fits([(0, 0)], -1, 0, board) | False |
onto a blockboard = [[None] * 4 for _ in range(4)]
board[2][1] = "red"fits([(0, 0), (0, 1)], 1, 1, board) | False |
beside a blockboard = [[None] * 4 for _ in range(4)]
board[2][1] = "red"fits([(0, 0), (0, 1)], 2, 1, board) | True |