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 with c.set(col, row, "gold").

Assignment

Replace each ___ so that:

  1. tile_at(world, pos) returns the tile at pos.
  2. next_pos(pos, delta) returns the new (row, col) after the move.
  3. find(world, thing) returns the (row, col) of the first tile equal to thing, or None if there isn't one.