Skip to main content

What is Karel?

Chapter 1: Introducing Karel the Robot


In the 1970s, a Stanford graduate student named Rich Pattis decided that it would be easier to teach the fundamentals of programming if students could somehow learn the basic ideas in a simple environment free from the complexities that characterize most programming languages. Rich designed an introductory programming environment in which students teach a robot to solve simple problems. That robot was named Karel, after the Czech playwright Karel Čapek, whose 1923 play R.U.R. (Rossum’s Universal Robots) gave the word robot to the English language.

Karel the Robot was quite a success. Karel has been used in introductory computer science courses all across the world and has been taught to millions of students. Many generations of Stanford students learned how programming works with Karel, and it is still the gentle introduction to coding used at Stanford.

What is Karel?

Karel is a very simple robot living in a very simple world. By giving Karel a set of commands, you can direct it to perform certain tasks within its world. The process of specifying those commands is called programming. Initially, Karel understands only a very small number of predefined commands, but an important part of the programming process is teaching Karel new commands that extend its capabilities.

Karel programs have much the same structure and involve the same fundamental elements as Python, a major programming language. The critical difference is that Karel’s programming language is extremely small and as such the details are easy to master. Even so, you will discover that solving a problem can be challenging.

By starting with Karel, you can concentrate on solving problems from the very beginning. Problem solving is the essence of programming. And because Karel encourages imagination and creativity, you can have quite a lot of fun along the way.

Karel’s world

Karel’s world is defined by rows running horizontally (east-west) and columns running vertically (north-south). The intersection of a row and a column is called a corner. Karel can only be positioned on corners and must be facing one of the four standard compass directions (north, south, east, west). A sample Karel world is shown below. Here Karel is located at the corner of 1st row and 1st column, facing east.

Several other components of Karel’s world can be seen in this example. The object in front of Karel is a beeper. As described in Rich Pattis’s book, beepers are “plastic cones which emit a quiet beeping noise.” Karel can only detect a beeper if it is on the same corner. The solid lines in the diagram are walls. Walls serve as barriers within Karel’s world. Karel cannot walk through walls and must instead go around them. Karel’s world is always bounded by walls along the edges, but the world may have different dimensions depending on the specific problem Karel needs to solve.

Karel's commands

When Karel is shipped from the factory, it responds to a very small set of commands. Lets try out the commands. Use the buttons bellow to get the "world" to match the "goal":

World:
Goal:

Here is what each command does:

CommandDescription
move()Asks Karel to move forward one block. Karel cannot respond to a move()command if there is a wall blocking its way.
turn_left()Asks Karel to rotate 90 degrees to the left (counterclockwise).
pick_beeper()Asks Karel to pick up one beeper from a corner and stores the beeper in its beeper bag, which can hold an infinite number of beepers. Karel cannot respond to a pick_beeper() command unless there is a beeper on the current corner.
put_beeper()Asks Karel to take a beeper from its beeper bag and put it down on the current corner. Karel cannot respond to a put_beeper() command unless there are beepers in its beeper bag.

The empty pair of parentheses that appears in each of these commands is part of the common syntax shared by Karel and Python and is used to specify the invocation of the command. Eventually, the programs you write will include additional information in the space between the parentheses, but such information is not part of the Karel’s primitive world. These parentheses will therefore be empty in standard Karel programs, but you must remember to include them nonetheless.

If Karel tries to do something illegal, such as moving through a wall or picking up a nonexistent beeper, an error condition occurs.

Karel’s commands, are not executed on their own. Instead, you need to incorporate them into a Karel program. You will have a chance to see a few simple Karel programs in Chapter 2!


Next Chapter

Comments

Popular posts from this blog

GTBank swift code and Foreign Currency Transfers details

We take your privacy seriously and only process your personal information to make your banking experience better. In accordance with NDPR, GDPR and other applicable regulations, continuing to use this platform indicates your consent to the processing of your personal data by Guaranty Trust Bank Plc., its subsidiaries and partners as detailed in our Privacy Policy Got it Home Business Banking International Trade Foreign Currency Transfers Foreign Currency Transfers Foreign Currency Transfers (GTMT) The GTBank International Money Transfer (GTMT) is designed to enable both GTBank account holders and non account holders send and receive funds to and from any GTBank subsidiary in West Africa. In line with a directive by the CBN, recipients of funds through GTMT in Nigeria must either be GTBank account holders or must be identified by a GTBank account holder. For Transfer Of USD ($) Into Domiciliary Account Through CitiBank New York: Correspondent Bank: CitiBank, New ...

OGUN STATE POLICE EMERGENCY NUMBERS

OGUN STATE POLICE EMERGENCY NUMBERS Below are the telephone numbers of area commanders, DPOS and Tactical team leaders of Ogun State Police Command.  Any of them can be reached in case of any distress. 1. O/C SARS 07065386591 2. O/C X SQAUD 08081774908 3. O/C S.I.B 08033173756 4. O/C E.O.D 08033447726 5. O/C ANTI-KIDNAPPING 08060374010 6. O/C HIGHWAY 08033208985 7. COMMANDER IGP 08035909911 8. O/C Q.R.S 07038649772 9. O/C MONITORING 08035249181 10. O/C SAFER HIGHWAY 07087253381 11. O/C IGP X SQAUD 08023529332 12. PPRO 08034241238 ABEOKUTA AREA COMMAND 1. ACPOL METRO 08023253470 2. DPO ADIGBE 08033448310 3. DPO IMALA 08030756843 4. DPO LAFENWA 08035141239 5. DPO ILUPEJU 08034610577 6. DPO KEMTA 08030642903 ADATAN AREA COMMAND 1. ACPOL ADATAN 08030742737 2. DPO ADATAN 08035518131 3. DPO ODEDA 08057150916 4. DPO OBANTOKO 08123824273 5. DPO OKE-ITOKU 08037767562 6. DPO ENUGADA 08037169917 7. DPO FUNAAB 08066634646 8. DPO AREGBE 08036041125 SAGAMU AREA COMMAND 1. ACPOL SAGAM...

RCCG SPECIAL THANKSGIVING SERVICE MAY 2020

Topic: Thank God for Calvary Text: Revelation 1:11-18 The greatest battle ever fought since the creation of man was fought at Calvary. It was a battle between the forces of darkness and Light. It seemed as if darkness won, but 3 days later, Light shone. What We Should Thank God For: 1. For the Blood He shed on Calvary. Through this Blood, our sins have been washed away. 1 John 1:7 The Blood is still giving us victory over satan. Revelation 12:10-11 The Blood also gives us access to God. Hebrews 10:19-22 Everyone of us now have access to the Holiest by virtue of the Blood. 2. The Healing Stripes of Jesus. 1 Peter 2:24, Isaiah 53:1-5 Jesus took a stripe for diseases yet undiscovered in addition to the 39 He took for categories of diseases already existing. 3. The Name of Jesus. Philippians 2:5-11, John 14:14 The Name has given us access to God's provision and deliverance. John 16:24 4. Victory over death.  Since Calvary, death has lost its sting. 1 Corinthians 15:54-57, Hebrews 2:14-...