Pages

Friday, May 20, 2011

Karel The Robot

Karel, The Robot is a simple program done in Karel, a programming language similar to Java, named after Mr.Karel Capek, who is a Czech writer who actually introduced the word "Robot".

Karel is a very useful utility for the easy understanding of the basic principles of Java.

Using this very simple yet useful application, we can learn many basic commands and methods in Java like the for loop, while loop and the if condition which is very much the same as compared to that C++ and C.

Basically Karel has four commands or methods as they are called. They are turnLeft, move, putBeeper and pickBeeper. We control Karel and navigate through a "world". "World" can be defined according to our needs and may contain certain walls or beepers which Karel could collect and place it in other spots around the world.Karel may have 0 to infinity beeepers in his bags at a particular time.

The following is a simple example of Karel syntax (a ";" indicates end of instruction, can be omitted if current instruction is followed by an END).

BEGINNING-OF-PROGRAM

DEFINE turnright AS //The method to define the function turnRight()
BEGIN
turnleft;
turnleft;
turnleft
END

BEGINNING-OF-EXECUTION //Body of the program
ITERATE 3 TIMES
turnright;
move;
END-OF-EXECUTION

END-OF-PROGRAM

No comments:

Post a Comment