Karel is an educational programming language for beginners, created by Richard E. Pattis in his book Karel The Robot: A Gentle Introduction to the Art of Programming. Pattis used the language in his courses at Stanford University, California. The language is named after Karel Čapek, a Czech writer who introduced the word robot.
A program in Karel is used to control a simple robot named Karel that lives in an environment consisting of a grid of streets (left-right) and avenues (up-down). Karel understands five basic instructions: move
(Karel moves by one square in the direction he is facing), turnLeft
(Karel turns 90 ° left), putBeeper
(Karel puts a beeper on the square he is standing at), pickBeeper
(Karel lifts a beeper off the square he is standing at), and turnoff
(Karel switches himself off, the program ends). Karel can also perform boolean queries about his immediate environment, asking whether there is a beeper where he is standing, whether there are barriers next to him, and about the direction he is facing. A programmer can create additional instructions by defining them in terms of the five basic instructions, and by using conditional control flow statements if
and while
with environment queries, and by using the iterate
construct. [출처]
Karel the Robot in OSORI (referred to as "Karel OSORI") is based on Python3 environment.
The world is made up of avenues and streets. These correspond to Cartesian X and Y coordinates respectively. Avenues are vertical lines, increasing to the East. Streets are horizontal lines increasing to the North. In the world file, coordinates are always described as avenues then street just as in geometry, where coordinates are described as x, y.
Directions are defined as enumeration. [North, East, South, West]
In Project, world file is saved as pickle
format which can serialize python object. The file contains number of streets, number of avenues, positions and directions of walls, beepers on world and its position, default position and direction of robot, number of beepers in robot's bag.
The robot has five primitive actions.
move(), turnleft(), pickbeeper(), putbeeper(), turnoff()
And robot can check some conditions about its status and surroundings.
front_is_clear(), front_is_blocked(),
left_is_clear(), left_is_blocked(),
right_is_clear(), right_is_blocked(),
back_is_clear(), back_is_blocked(),
on_beeper(), not_on_beeper(),
any_beepers_in_beeper_bag(), no_beepers_in_beeper_bag(),
facing_north(), not_facing_north(),
facing_south(), not_facing_south(),
facing_east(), not_facing_east(),
facing_west(), not_facing_west()
- Execution of move() when that move would cause Karel to hit a wall, or get outside the world range.
- Execution of pickbeeper() when there are no beepers on the field Karel is standing on.
- Execution of putbeeper() when Karel has no beepers in his bag.
- Missing of the last turnoff() statement at the end of the program body.
TBD
TBD
Karel the robot : a gentle introduction to the art of programming