King Julian needs to get through the jungle, but he's feeling lazy. He wants a computer to be able to calculate a route through the jungle for him.
Using STDIN get a map of the jungle for the computer to crack. It will follow the following format:
01001E 010110 000P00 1100J1 S00111
The way the jungle map works is:
0 is ground that Julian can move along.
1 is dense impassable jungle.
P is an area with predators in it, that you must avoid at all costs.
J is relatively thick jungle. Julian's minions can break through one of these before tiring.
S is where Julian starts. It can be anywhere on the map.
E is where Julian wants to go; the end of the path. It also can be anywhere on the map, just like any other tile.
Every character is a tile on the map. Line breaks indicate a new row of tiles. If STDIN in your language does not support line breaks, the line break must be replaced by a space to signify a new row.
To move between the tiles, you must output a string using STDOUT containing the following special characters:
F - Forward
B - Backward
L - Rotate Julian left (90 degrees anticlockwise)
R - Rotate Julian right (90 degrees clockwise)
M - Minions destroy a
J tile 1 tile forward from Julian, if there is one (
M just clears out the tile, you still have to move onto it)
A possible output would be:
Which solves the map above.
If your program outputs a solution which hits predators, game over.
If you hit impassable jungle, you just bounce back to where you were before you ran into dense jungle, facing the same way. (Toward the jungle)
Julian starts facing upwards. (^ That way ^)
The output doesn't have to be the fastest solution,
FBFBFBFBFBFFFare the same. However, outputting the fastest possible solution gives a -10% byte count bonus.
If a map is invalid, STDOUT 'Invalid map.' (That includes if the map is unsolvable)
A map cannot have rows or columns of different lengths; that makes it invalid.
Your answer should somewhat follow this format:
#Language name, *n* bytes code Explanation (optional)
This is code-golf, so the shortest code in bytes wins.