
Fill in
Row Before Column
A square on the map is a position. We store it as a tuple
(row, col): row first, then column.
Why row first? Because world[row] picks the row string, and
only then [col] picks a tile inside it:
pos = (1, 3)
row, col = pos # unpack the tuple
print(world[row][col])
Moving is adding
A move is a small change called a delta. Add it to the position to get the next square:
| Move | Delta |
|---|---|
| north | (-1, 0) |
| south | (1, 0) |
| east | (0, 1) |
| west | (0, -1) |
Rows are counted from the top of the screen down. So going south (down) adds 1 to the row.
Pip tip: The pixel canvas uses
(x, y)instead, where x is the column and y is the row. That's the other way round! So Pip at(row, col)is painted withc.set(col, row, "gold").
Assignment
Replace each ___ so that:
tile_at(world, pos)returns the tile atpos.next_pos(pos, delta)returns the new(row, col)after the move.find(world, thing)returns the(row, col)of the first tile equal tothing, orNoneif there isn't one.
Replace each ___ so that:
tile_at(world, pos)returns the tile atpos.next_pos(pos, delta)returns the new(row, col)after the move.find(world, thing)returns the(row, col)of the first tile equal tothing, orNoneif there isn't one.
main.py Python sleeping
Press Run to try your code, then Check to test it.