Tracks of buggles

Your buggle got lost in a strange maze, and you must help it to find the exit that is represented in orange. You cannot simply explain the path to the exit in something like right();forward();forward();forward() because you have to save two buggles at the same time, that are lost in similar but not identical worlds. You can switch to the other world by using the combobox above the world representation (where it's written 'Deep Forest' right now), and selecting the other entry (that should read 'Deeper Forest').

The good news is that the path to the exit is written on the ground. As you can see, the world is made of several corridors, with baggles on the ground. After each corridor, you should turn left if the corridor contains three baggels or more, and you have to turn right if there is only 2 baggles or less.

You should count exactly 5 cells per corridor, the one at the intersection counting as the last cell of the previous corridor, not as the first cell after your turn.

So, the general form of your code must be something like "while I did not find the exit, take the next corridor to decide whether I should turn left or right at the next intersection". You can determine whether you are on the exit cell (that is orange) with the provided exitReached() method.

To take one corridor, you simply have to run from one intersection to another while counting the baggles you see on your path. The method crossing() tells you whether your buggle currently stands on an intersection. The extra complexity is that at the beginning of a corridor, you obviously stand on an intersection, but you still want to move on. [!java|scala|c]For that, the easiest is to use a do / while loop instead of a regular while loop to move until the next intersection.[/!] [!python]For that, use an extra variable indicating whether you already entered the corridor, as follows. This will ensure that you execute the loop body at least once (when firstTime is true) before we actually use the value returned by crossing() to determine to continue or not.[/!]

[!python]
firstTime = True
while firstTime or not crossing():
  firstTime = False
  (loop body)
[/!]

You need a variable that is initialized to 0, and incremented each time you see a baggle on the ground. A variable used this way is often called counter.

Don't forget to reset your counter to 0 at the beginning of each corridor!

Oh, and when you reach the exit, don't forget to take an extra step to actually exit the maze!