def can_move(minimap, i, j, di, dj):
    """
    Check whether can move in specified direction
    """

    # minimap is always square
    n = len(minimap)

    # Move once
    i += di
    j += dj

    # Cannot move outside of minimap
    if i < 0 or i >= n or j < 0 or j >= n:
        return False

    # Cannot move if occupied
    if minimap[i][j] == 1:
        return False

    # Move second time
    i += di
    j += dj

    # Can move if second move falls outside
    if i < 0 or i >= n or j < 0 or j >= n:
        return True

    # Cannot move if second move is occupied
    if minimap[i][j] == 1:
        return False

    # Otherwise we can move
    return True