Article Preview
Buy Now
FEATURE
Karel the REALbasic Robot
How the rbKarel robot simulation teaches logic with RBScript
Issue: 8.1 (November/December 2009)
Author: Andy Dent
Author Bio: Andy is a freelance developer from Perth, Western Australia who alternates REALbasic with C++, C#, Ruby, and Objective-C and welcomes the return to the kindler, gentler and often more-productive world of REALbasic.
Article Description: No description available.
Article Length (in bytes): 36,455
Starting Page Number: 30
Article Number: 8110
Resource File(s):
project8110.zip Updated: 2009-11-02 11:51:29
Related Web Link(s):
http://code.google.com/p/rbstuff/wiki/rbKarelOverview
http://www.cs.mtsu.edu/~untch/karel/
http://sourceforge.net/projects/karel/
http://karel.sourceforge.net/doc/html_mono/karel.html
http://www.amazon.com/Karel-Robot-Gentle-Introduction-Programming/dp/0471597252
http://www.amazon.com/Karel-Gentle-Introduction-Object-Oriented-Programming/dp/0471138096
HTTP://www.gametraining.net
http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.1615329425.01615329428
http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.1615329425.01615329428
http://karel.sourceforge.net/
Excerpt of article text...
Karel the Robot has been around for nearly thirty years as a way to teach people the basics of logic through solving simple problems. The rbKarel project uses RBScript to provide the language interpreter for Karel along with a few goodies like spoken output and single-stepping. It also uses a much simpler context object for a second RBScript to define worlds. Why write a parser when RBScript does the hard work for you? This article doesn't attempt to teach the basics of RBScript -- see the resources list at the end for past
RBDeveloper articles on that topic. What I do cover are some of the interesting challenges in adapting RBScript for Karel and particularly how to add single-stepping and other controls over the script execution. As I wrote the article I also found myself explaining a few points about the software design decisions, which may seem heavy-handed to experienced programmers but hopefully will keep reminding others of some core principles.When Jeff Ayling posted his request for help, I was intrigued by the "Just how hard could it be?" prospect of trying to implement a particularly REALbasic style of Karel.
I had already published a complex example of RBScript being used to drive 2D graphics. Putting a little user logic on top of this didn't seem that hard, just a case of adding a few methods to the context object to manipulate a robot. Things are never quite as simple as they seem in the first rush of enthusiasm and one challenge I hadn't anticipated is that Karel's world is not one of pixel coordinates but of a grid with intervening walls and coordinates. The first public teaching trial also proved that adding single-stepping and some feedback as to what was going to happen next was a hugely desirable feature.
Karel From the Users's Viewpoint
Karel moves around on a simple grid of vertical Avenues and horizontal Streets, with walls between. See Figures 1 and 2 for examples. He carries a
Beeper Bag into which he can put the Beepers he picks up and from which he takes beepers to put on the grid points. Beepers are conceptually there -- they are visible but (thankfully) do not actually beep. Real audible beeping isnot an enhancement that has been requested and is probably the Karel equivalent of the <BLINK> tag. If more than one beeper is on a given grid location, we have improved visual feedback that a count is visible in the middle of the beeper.
...End of Excerpt. Please purchase the magazine to read the full article.