human
I found an interesting problem on https://www.codewars.com/kata/5877027d885d4f6144000404:
_That's terrible! Some evil korrigans have abducted you during your sleep and threw you into a maze of thorns in the scrubland D:  
But have no worry, as long as you're asleep your mind is floating freely in the sky above your body._
> **Seeing the whole maze from above in your sleep, can you remember the list of movements you'll have to do to get out when you awake?**

---

**Input**
---
---

You are given the whole maze `maze` as a 2D grid, more specifically in your language:
```if:ruby,javascript,python
an array of strings
```
```if:java
a `char[][]`
```
```if:ruby,javascript,python,java
`maze[0][0]` is the top left-hand corner
```
```if:c
a `Maze*` (a struct with three fields: `unsigned height`, `unsigned width`, `char **grid`)
Each line is '\0' terminated, but the array of lines is not.  
`maze->grid[0][0]` is the top left-hand corner.
```
```if:java,javascript,ruby
`maze[maze.length - 1][maze[0].length - 1]` is the bottom right-hand corner
```
```if:python
`maze[len(maze) - 1][len(maze[0]) - 1]` is the bottom right-hand corner
```
```if:c
`maze->grid[maze->height - 1][maze->width - 1]` is the bottom right-hand corner.
```
Inside this 2D grid:
 - `' '` is some walkable space  
 - `'#'` is a thorn bush (you can't pass through)  
 - `'^'`, `'<'`, `'v'` or `'>'` is your sleeping body facing respectively the top, left, bottom or right side of the map.
 
---

**Output**
---
---
Write the function `escape` that returns the list/array of moves you need to do relatively to the direction you're facing in order to escape the maze (you won't be able to see the map when you wake up). as an array of the following instructions:  
 - `'F'` move one step forward  
 - `'L'` turn left  
 - `'R'` turn right  
 - `'B'` turn back   
 > Note: `'L'`,`'R'`, and `'B'` **ONLY** perform a rotation and will not move your body
 
```if:javascript,ruby,python,java
If the maze has no exit, return an empty array.
```
```if:c
If the maze has no exit, return `NULL`.
```
* This is a real maze, there is no "escape" point. Just reach the...

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is the Python program you requested.

class Piece:

    def __init__(self, map):
        self.map = map
        self.size = (len(map) - 1, len(map[0]) - 1)
        for num, line in enumerate(map):
            for tag in ('^', '<', 'v', '>'):
                if tag in line:
                    self.x, self.y, self.direct = num, line.index(tag), tag
        self.walked = set()     # 记录所有行进过得点
        self.walked.add((self.x, self.y))
        self.forks = []     # 记录所有岔路口以及在岔路口时的步数
        self.steps = 0  # 记录行动过得步数，方便回溯
        self.check_fork(self.x, self.y, 1)  # 起点时有两个方向就算岔路口
        self.dir = {
            'up': ('^', (-1, 0)),
            'down': ('v', (1, 0)),
            'left': ('<', (0, -1)),
            'right': ('>', (0, 1)),
        }
        self.turn = {
            '>': {'L': self.dir['up'], 'R': self.dir['down'], 'B': self.dir['left'], 'F': self.dir['right']},
            '<': {'L': self.dir['down'], 'R': self.dir['up'], 'B': self.dir['right'], 'F': self.dir['left']},
            '^': {'L': self.dir['left'], 'R': self.dir['right'], 'B': self.dir['down'], 'F': self.dir['up']},
            'v': {'L': self.dir['right'], 'R': self.dir['left'], 'B': self.dir['up'], 'F': self.dir['down']},
        }

    def check_fork(self, x, y, direct=2):
        count = 0
        for x_, y_ in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
            if x_ >= 0 and x_ <= self.size[0] and y_ >= 0 and y_ <= self.size[1]:
                if self.map[x_][y_] != '#':
                    count += 1
        fork = ((x, y), self.steps, self.direct)
        for _ in range(count-direct):   # 四个方向有三个能通才是岔路口
            self.forks.append(fork)

    def draw_map(self, x, y):
        self.map[x] = self.map[x][:y] + self.direct + self.map[x][y + 1:]

    def go_forward(self):
        self.direct, (x, y) = self.turn[self.direct]['F']
        x, y = self.x + x, self.y + y
        if self.map[x][y] != '#' and (x, y) not in self.walked:     # 只有前方是空地，并且没有走过才会向前走
            self.x, self.y = x, y
            self.walked.add((x, y))  # 将走过的路劲都记录下来，不走重复的路
           ...