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').
La buona notizia è che il percorso d'uscita è scritto sul terreno. Come potete vedere il mondo è composto da diversi corridoi con dei baggle sul pavimento. Dopo ogni corridoio se si è incontrato tre o più baggle bisognerà girare a sinistra mentre per due o meno a destra.
Dovresti contare esattamente 5 celle per corridoio, quella dell'incrocio conta come l'ultima cella del corridoio appena percorso e non come prima cella del successivo, dopo aver girato.
Quindi la forma generale del vostro codice deve essere qualcosa come "finché
non trovo l'uscita prendo il prossimo corridoio per decidere se dovrò girare
a destra o a sinistra al prossimo incrocio". Puoi determinare se ti trovi
sulla cella di uscita (in arancione) con il metodo
exitReached()
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.[/!]
firstTime = True while firstTime or not crossing(): firstTime = False (loop body)[/!]
Ah, e quando avrai raggiunto l'uscita, non dimenticare di fare uno step extra per uscire effettivamente dal labirinto.