Skip to content

askingalot/KarelTheRobot

Repository files navigation

Karel the Robot

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.

Getting Started

  1. Clone this repository.
  2. Choose a challenge from the available challenges (*.json files) or make your own. (see the documentation below)
  3. Write code in the KarelTheRobot.Main/Program.cs file to solve the challenge.
  4. Run the program.
    • In Linux or Mac OS X:
      1. Open the Terminal
      2. Navigate to the repo's root directory.
      3. Run the program using the run command
        $ ./run
    • In Windows
      1. Open the Command Prompt (cmd.exe)
      2. Navigate to the repo's root directory.
      3. Run the program using the run.bat command
        > run

The World

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:

   ┏┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┓
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┣····················┫
   ┗┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┛

Beepers

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:

Robot

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.

Available Robot Commands

A robot has the following built in commands:

  1. 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.
  2. 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.
  3. Move - Move the robot one space in it's current direction. If the robot hits a wall it will be destroyed.
  4. TurnLeft - Turn the robot 90 degrees to the left. The robot will remain in the same location.
  5. 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.
  6. 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.

Sensing the World

The robot can sense the world around it using these properties.

  1. IsFrontClear - Is the location in front of the robot free to move into?
  2. IsLeftClear - Is the location to the left of the robot free to move into?
  3. IsRightClear - Is the location to the right of the robot free to move into?
  4. IsNextToBeeper - Is there a beeper at the robot's current location?
  5. AreAnyBeepersInBag - Are there any beepers in the robot's bag?
  6. IsFacingNorth - Is the robot facing north? (i.e. toward the top of the screen)
  7. IsFacingSouth - Is the robot facing south? (i.e. toward the bottom of the screen)
  8. IsFacingEast - Is the robot facing east? (i.e. toward the right of the screen)
  9. IsFacingWest - Is the robot facing west? (i.e. toward the left of the screen)

Configuring a World

Configuration is done by way of a JSON file containing an object with the following properties:

  1. challengeText - The description of the challenge to be completed in this world.
  2. streetCount - The number of streets in the world.
  3. avenueCount - The number of avenues in the worl.d
  4. robot - An object containing two keys, street and avenue, that specifies the initial location for the robot.
  5. beepers - (Optional) An array describing the initial locations of each beeper in the world.
  6. 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.

An Example

{
  "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}
  ]
}

Learn More

About

An attempt to implement Karel the Robot in C# (https://en.wikipedia.org/wiki/Karel_(programming_language))

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages