You will be given an integer N for the size of the square matrix and then an integer for the count of commands. On the next n lines, you will receive the rows of the matrix. The player starts at a random position (the player is marked with "f") and all of the empty slots will be filled with "-" (dash). The goal is to reach the finish mark which will be marked with "F". On the field there can also be bonuses and traps. Bonuses are marked with "B" and traps are marked with "T".
Each turn you will be given commands for the player’s movement. If the player goes out of the matrix, he comes in from the other side. For example, if the player is on 0, 0 and the next command is left, he goes to the last spot on the first row.
If the player steps on a bonus, he should move another step forward in the direction he is going. If the player steps on a trap, he should move a step backwards.
When the player reaches the finish mark or the count of commands is reached, the game ends.
On the first line, you are given the integer N – the size of the square matrix.
On the second you are given the count of commands.
The next N lines hold the values for every row.
On each of the next lines you will get commands for movement directions.
If the player reaches the finish mark, print:
If the player reaches the commands count and hasn’t reached the finish mark print:
In the end print the matrix.
The size of the matrix will be between [2…20].
The players will always be indicated with "f".
If the player steps on the finish mark at the same time as his last command, he wins the game.
Commands will be in the format up, down, left or right.
There won't be a case where you bypass the finish while you are on a trap or a bonus.
A trap will never place you into a bonus or another trap and a bonus will never place you into a trap or another bonus.
Input Output Comments
down Player won!
-f--- The first command is down so f moves down. On turn 1, the player steps on a bonus and does an additional step. On turn 2, the player steps on a trap and goes a step back. After each turn the field is:
1 2 3
----- ----- -----
----- ----- -----
-B--- -B--- -B---
-fT-- -fT-- --T--
-F--- -F--- -f---
On turn 3 f reaches the finish 'F' and wins the game.
left Player lost!
f--F The first command is up so f moves up and the new player position is (0,1). The next command is up again, so the player goes out of the matrix and comes back from the other side at (3,1). Then the command is left, so the end position is (3,0) which is not the finish mark, so the player has lost.