#https://www.codewars.com/kata/58583922c1d5b415b00000ff/train/python
#5kyu kata
def super_street_fighter_selection(fighters, position, moves):
    y = position[0]
    x = position[1]
    yMax = len(fighters)-1
    xMax = len(fighters[y])-1
    result = []

    if len(moves) == 0 and fighters[y][x] == '':
        return result
      
    for move in moves:
        while (True):
            if move == "up":
                if y != 0:
                    y -= 1
                    if not fighters[y][x]:
                        y += 1
                        break
                break

            elif move == "down":
                if y != yMax:
                    y += 1
                    if not fighters[y][x]:
                        y -= 1
                        break
                break
                    
            elif move == "right":        
                if x == xMax:
                    x = 0
                    if fighters[y][x]:
                        break
                        
                elif x != xMax:
                    x += 1
                    if fighters[y][x]:
                        break
                continue

            elif move == "left":
                if x == 0:
                    x = xMax
                    if fighters[y][x]:
                        break
                elif x != 0:
                    x -= 1
                    if fighters[y][x]:
                        break 
                continue          
            break
                                    
        if fighters[y][x]:
            result.append(fighters[y][x])

    return result