Returns whether a position is within the bounds of the grid.
bool containsPos(Pos pos) { return pos.x >= 0 && pos.x < width && pos.y >= 0 && pos.y < height; }