'How to implement a "reverse" BFS algorithm?

enter image description hereI'm playing a game with the following rules: There is a map (with walls), some coins (randomly generated in the map) and a Minotaur. The goal is to grab as many coins as possible without the minotaur killing you. I have implemented a BFS to find coins and move towards them, but my character keeps dying to the minotaur, because i don t know how to make an efficient "run away" algorithm.

What would be the best solution to find the path that runs away from the minotaur as fast as possible (without colliding with walls)

The pseudo code would look somewhat like this:

*if(minotaur_is_close) run_away*

*else find_coins*

Edit: Added picture of the starting round of randomly generated map (green tiles are walkable, grey ones are walls, blue is character, red is Minotaur, orange are coins)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source