Karel is just a robot trying to make it in the world.
This is a C# implementation of the classic programming teaching tool. It runs on .NET Core, and is cross platform (Windows, Mac OS X and Linux). It's intended to be a fun way to practice with the basics of the C# programming language.
- Clone this repository.
- Choose a challenge from the available challenges (
*.json
files) or make your own. (see the documentation below) - Write code in the KarelTheRobot.Main/Program.cs file to solve the challenge.
- Run the program.
- In Linux or Mac OS X:
- Open the Terminal
- Navigate to the repo's root directory.
- Run the program using the
run
command$ ./run
- In Windows
- Open the Command Prompt (cmd.exe)
- Navigate to the repo's root directory.
- Run the program using the
run.bat
command> run
- In Linux or Mac OS X:
The robot's world is a rectangle surrounded by walls. It may contain internal walls and beepers for the robot to interact with. You may think it's a lonely place, but, fortunately, most robots enjoy time to themselves.
The world is made up of streets and avenues. Streets run east-west and avenues run north-south.
A world looks something like this:
┏┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┓
┣····················┫
┣····················┫
┣····················┫
┣····················┫
┣····················┫
┣····················┫
┣····················┫
┣····················┫
┗┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┛
A small plastic cone that emits a quiet beeping noise that the robot can sense. Any number of beepers may be on any street corner. The robot carries a bag that can hold any number of beepers.
A beeper looks something like: ☼
The robot is controlled by the code you write. It can move around the world, pick up beepers to put in its bag, and take beepers from its bag to place in the world.
A robot looks something like a triangle pointed in the robot's current direction of movement.
A robot has the following built in commands:
TurnOn
- Power up the robot. The robot MUST be turned on before receiving any commends otherwise it will be destroyed. If the robot is already tunred on, turning it on again will destroy it.TurnOff
- Power off the robot. The robot MUST be turned off before the application exists or it will be destroyed. The robot MUST be on when it is turned off, or it will be restored.Move
- Move the robot one space in it's current direction. If the robot hits a wall it will be destroyed.TurnLeft
- Turn the robot 90 degrees to the left. The robot will remain in the same location.PickBeeper
- Pick up a beeper at the robot's current location and put it in the robot's bag. If there is no beeper at the robot's current location the robot will be destroyed.PutBeeper
- Take a beeper from the robot's bag and place it in the world at the robot's current location. If there is no beeper in the robot's bag, the robot will be destroyed.
The robot can sense the world around it using these properties.
IsFrontClear
- Is the location in front of the robot free to move into?IsLeftClear
- Is the location to the left of the robot free to move into?IsRightClear
- Is the location to the right of the robot free to move into?IsNextToBeeper
- Is there a beeper at the robot's current location?AreAnyBeepersInBag
- Are there any beepers in the robot's bag?IsFacingNorth
- Is the robot facing north? (i.e. toward the top of the screen)IsFacingSouth
- Is the robot facing south? (i.e. toward the bottom of the screen)IsFacingEast
- Is the robot facing east? (i.e. toward the right of the screen)IsFacingWest
- Is the robot facing west? (i.e. toward the left of the screen)
Configuration is done by way of a JSON file containing an object with the following properties:
challengeText
- The description of the challenge to be completed in this world.streetCount
- The number of streets in the world.avenueCount
- The number of avenues in the worl.drobot
- An object containing two keys,street
andavenue
, that specifies the initial location for the robot.beepers
- (Optional) An array describing the initial locations of each beeper in the world.walls
- (Optional) An array describing the locations of each internal wall in the world. Note: you do not need to list the outer boundaries of the world.
{
"challengeText": "Pick up the beeper in front of you and move it to the opposite location across the world",
"streetCount": 20,
"avenueCount": 20,
"robot" : { "street": 10, "avenue": 1 },
"beepers": [
{"street": 10, "avenue": 2}
],
"walls": [
{"street": 2, "avenue": 10},
{"street": 18, "avenue": 10}
]
}