def isValid(pos, dim, body):
    """Check if given position is a valid position."""
    if not (0 < pos.x < dim[0] - 1): return False
    if not (0 < pos.y < dim[1] - 1): return False
    return pos not in body