Wednesday, March 30, 2016

It's so logical, but so frustrating

The title of this blog post is an actual quote from a student who was learning programming more than 10 years ago using RUR-PLE, the precursor to Reeborg's World.  This quote captures the essence of what programming a simple virtual robot like Reeborg, or the original Karel, is all about: it is not about syntax but about logic and computational thinking.

One of my favourite examples is a set of two problems, which are the worlds named Rain 1 and Rain 2 in Reeborg's World [1].  In the tutorial I wrote, the situation is described as follows:

It was a beautifully sunny day. Reeborg was playing outside with his friend. Suddenly, it started to rain and Reeborg remembered that the windows in his house were all open. So Reeborg went back to his house and stopped in front of the door, unsure of how to proceed. Using the build_wall() instruction and either wall_on_right() or wall_in_front(), or both, but not right_is_clear() nor front_is_clear(),[2] help Reeborg close the windows of his house. When Reeborg finishes his task, he will stand in the doorway, watching the rain fall, waiting for it to stop before he can go back and play outside. 
A standard strategy is go to around the world, identifying missing wall sections (aka open window) and "closing the window" by building the required wall section.  After the last instruction of the program is executed, automatic feedback is given.
This can be done by a program that looks as follows, where the main challenge, for a beginner is to get the if/elif/else required structure.



While may look straightforward, a simple modification of the world can make the logic required much more complicated.



Suddenly, the absence of a wall on the right no longer indicates an open window.  To write a program that works for this world, as well as for the preceding one, does not require any new syntax; however, it does require one to think of a new way to identify an open window.  And this, for beginners, can be a real challenge.

Notes


[1] A slightly different version of each of these worlds was included in RUR-PLE, which is closer in the original Karel the robot as it has only one type of objects ("beepers") with a robot unable to build walls.  Thus, the goal for Reeborg was to put a beeper in front of each open window, with the starting and finishing positions for the equivalent to "Rain 2" looking as follows.







[2] In addition to wall_on_right() and wall_in_front(), front_is_clear()and right_is_clear() can normally be used by Reeborg to glean information about its world. These two additional functions, which are not available in "Rain 1" and "Rain 2" are "True" if there is an obstacle (wall, or water - and others) at the next location indicated (either in front or to the right of Reeborg).  By making use of these additional conditions, the common solution to both worlds can be simplified. This can be tested by loading the worlds "/src/worlds/rain1a_en.json" and "/src/worlds/rain2a_en.json" where using these two functions is allowed.  To load a world from a URL (as a string), simply execute a program with World(URL) as an instruction.