WorldGenerator.path_avail_dirs()

def path_avail_dirs(self,position,impediments,dest=None,rand=False):

    # Processes available directions, returns a random direction
    # if the random flag is passed, else returns the direction
    # list

    self.logger.debug('[*] Finding available directions')

    imp = ''.join(str(i) for i in impediments)
    self.logger.debug('\tImpediments : {}'.format(imp))

    p = position
    self.logger.debug('\tPosition : {}'.format(p))

    # Define directions
    north = [0,1]
    south = [0,-1]
    east = [1,1]
    west = [1,-1]

    if dest is not None:
        prefer_y = [True] if p[0]==dest[0] else [False]
        prefer_x = [True] if p[1]==dest[1] else [False]

        if p[0]<dest[0] and prefer_x: prefer_x.append(1)
        if p[0]>dest[0] and prefer_x: prefer_x.append(-1)
        if p[1]<dest[1] and prefer_y: prefer_y.append(1)
        if p[1]>dest[1] and prefer_y: prefer_y.append(-1)

        # Reduce compared value for more direct paths
        if random.randint(0,100)>30:
            apply_preference=True
        else:
            apply_preference=False

    # impediments will contain impassable vals
    # x-axis
    if p[0]+1>=self.dim_x:
        north.append(False)
    else:
        north.append(
            True if self.grid[p[0]+1,p[1],p[2]][0] not in imp else False
            )

    if p[0]-1<=0:
        south.append(False)
    else:
        south.append(
            True if self.grid[p[0]-1,p[1],p[2]][0] not in imp else False
            )

    # y-axis
    if p[1]+1>=self.dim_y:
        east.append(False)
    else:
        east.append(
            True if self.grid[p[0],p[1]+1,p[2]][0] not in imp else False
            )
    if p[1]-1<=0:
        west.append(False)
    else:
        west.append(
            True if self.grid[p[0],p[1]-1,p[2]][0] not in imp else False
            )

    dirs = [north,south,east,west]
    assert any(dirs),'Pathbuilder : No available moves!'

    if not rand:
        return dirs
    elif apply_preference and (prefer_x or prefer_y):
        if prefer_x[0]:
            self.logger.debug('\tPreferring x : {}'.format(prefer_x[1]))
            return 0,prefer_x[1]
        elif prefer_y:
            self.logger.debug('\tPreferring y : {}'.format(prefer_y[1]))
            return 1,prefer_y[1]
    else:
        # Randomly selects an available move and returns it
        while True:
            roll = random.randint(0,3)
            if dirs[roll][2]:
                if roll in [0,1]:
                    idx = 0
                    val = 1 if roll==0 else -1
                else:
                    idx = 1
                    val = 1 if roll==2 else -1
                break

        self.logger.debug('\tindex (x,y)= {} value= {}'.format(idx,val))
        return idx,val