I want to solve Robozzle puzzle number 291 - Huh? Part 2.
You can see it raw in the image below. You need to collect the stars without falling out of the given grid. You are the rocket on top-left corner of the grid; starting point is red cell here.
You give certain commands to the rocket and it obeys them. The less command, the better. Commands for this puzzle are shown below.
Commands are displayed on right side. From top to down they are:
call F1 function,
call F2 function,
call F3 function;
change colour of the current cell to green,
change colour of the current cell to blue;
execute this command no matter what the colour of cell is,
execute this command in red cell,
execute this command in green cell and
execute this command in blue cell.
Each time it starts with
F1 function. If you don't call
F2 function in
F1 then it will not execute commands in
F2. Same applies for
F3; if you don't call it, it won't be executed.
Let me show you how to play this game in another easy puzzle.
This puzzle is called "Stairs." You can see the commands and given function on the bottom right corner again. They are blank. If I click on
Go! nothing happens because there are no commands given in function.
Now, let's fill in the function with some necessary commands.
You can see where robot stays. It hasn't collected all the stars. Function was called but it was executed just once. Why? Because there is no iteration (or recursion) or repetition of commands.
Remember we need to collect all the stars, so let's call
F1 function again at the end of commands so that it iterates (or recurses) or repeats itself.
The rocket has collected all the stars because F1 was called again at the end so that it repeatedly goes beginning when it finishes executing all the commands. At the bottom you can see what the next steps are such as
turn right and
F1. This was completed in 5 commands.
Now, hoping that you understood how to solve this puzzle I'm returning back to my puzzle in question; I was able to collect only one star in the centre (in green cell) by calling only 2 functions:
F3. However, that's not enough to solve the puzzle. Remember, I needed to collect all the stars.
Now, with the image below, there is still no solution. It just does repetitious U-turn between the green cells in the centre. What I did was to turn right after red cell and colour the cell to green on the corner. I wanted to utilise those green cells on the corners when I return back from the star in the middle. I need to collect the star on the upper left corner also. But, it didn't work.
There are a lot of possible solutions for this puzzle. One way is to collect the star behind the rocket (on the upper left corner) first and then collect the star in the middle. For this one you don't need to use colour changes as far as I know because I have read the comments in that website: comments for Robozzle 291.
And there is another solution: you collect the star in the middle and colouring the corners (or just the cell near the corner, like red one was) to utilise them when returning back. I thought about colouring the cell after you turn right, so that it acts as milestone when returning back. So that you turn left after green when returning back from the middle; as you did turn right after red when going forward to the middle. It is shown below.
Still, I couldn't solve it. I have been dealing with this puzzle for more than 3 days and I think more than when a person spends more than a day or two is enough for asking help from others. There are a lot of solutions for these puzzles and they are fun. You can see my another question in this website where I got a lot of nice answers each of them being quite different: Shorter solution for Robozzle puzzle no 132 - Split. Thanks beforehand.