The main difficulty is making sure that Kara does not endlessly walk up through an exit to the next row and then back down again. He must remember whether he is looking for an exit to his right or to his left. He must ignore exits on the other side. The following extract of the main programs shows how two boolean variables can be used to search fo the next exit:
ignoriereLochLinks = false ignoriereLochRechts= true while not kara.onLeaf while (ignoriereLochLinks or kara.treeLeft) and (ignoriereLochRechts or kara.treeRight) if not kara.treeFront kara.move else ignoriereLochLinks = !ignoriereLochLinks ignoriereLochRechts= !ignoriereLochRechts kara.turnLeft kara.turnLeft end end # ...