Difference between revisions of "W1165 Karel Introduction"

From Coder Merlin
Line 67: Line 67:
}}
}}
Press {{Key|I}} (capital 'I') and select the directory for '''this''' challenge in which {{Pathname|Package.swift}} is located.
Press {{Key|I}} (capital 'I') and select the directory for '''this''' challenge in which {{Pathname|Package.swift}} is located.
== Building ==
=== Building ===
Like most challenges, the project can be built by issuing a build command on the console:
Like most challenges, the project can be built by issuing a build command on the console:
{{ConsoleLine|john-williams@codermerlin:~/Merlin...$|build}}
{{ConsoleLine|john-williams@codermerlin:~/Merlin...$|build}}

Revision as of 18:28, 16 February 2021

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
CoderMerlin™ Karel

Prerequisites[edit]

Background[edit]

Richard Pattis
Karel the Robot
Karel Čapek

 Coder Merlin™ Karel , also known as "that little blue bot", is strongly inspired by Richard Pattis' book written during his studies at Stanford.[1][2] Richard Pattis currently teaches at the University of California, Irvine. Pattis chose the name Karel in honor of the Czech playwright Karel Čapek, who introduced the word robot in his 1921 play R.U.R.

Eric Roberts, Department of Computer Science, Stanford University, September 2005:

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. Drawing inspiration from the success of Seymour Papert’s LOGO project at MIT, Rich designed an introductory programming environment in which students teach a robot to solve simple problems. [3]

 Coder Merlin™ Karel  is a very simple robot living in a very simple world. Programming  Coder Merlin™ Karel  is accomplished by specifying a series of simple instructions.  Coder Merlin™ Karel  initially understands only a very few instructions, but over time you can expand the vocabulary by defining functions and enhancing  Coder Merlin™ Karel 's abilities.

All instructions issued to  Coder Merlin™ Karel  must be very precise and unambiguous, a key requirement of well-written programs. The programs themselves must obey a set of syntactic rules which define which commands (and the ordering of those commands) are acceptable. These rules define a programming language, such as the Swift programming language which we've been using. The details of the subset of instructions which  Coder Merlin™ Karel  understands are very easy to master, enabling us to focus on problem solving.

It is problem solving which is the focus and essence of computer programming.

Introduction (Welcome to my World)[edit]

Streets, Avenues, and Corners[edit]

Figure 1

 Coder Merlin™ Karel  lives in a city with green avenues running vertically north-south and blue streets running horizontally east-west. The intersection of a street with an avenue is called a corner.  Coder Merlin™ Karel  can only be position on a corner and must point in one of the four cardinal directions.  Coder Merlin™ Karel  always points with his hat, so in Figure 1  Coder Merlin™ Karel  is positioned at (avenue: 1, street: 1) and is facing north. Note that worlds may be of various sizes depending upon the challenge that needs to be solved.

Beepers[edit]

Figure 2

Corners may have zero or more beepers present, indicated by a yellow/red rotating beacon. The number in the center of the beacon indicates the number of beepers present on the corner. In Rich Pattis’s book, beepers are "plastic cones which emit a quiet beeping noise."  Coder Merlin™ Karel  can only detect a beeper if it is on the same corner.  Coder Merlin™ Karel  carries with him a hidden beeper bag; the number on the front of  Coder Merlin™ Karel  indicates how many beepers are in the bag (Figure 3).

Figure 3


Walls[edit]

Figure 4

Walls may be present between streets and avenues and serve as a barrier to  Coder Merlin™ Karel ; unable to pass through them  Coder Merlin™ Karel  must go around them. Note that the presence of walls is implied around the boundary of the city.

Challenges[edit]

 Coder Merlin™ Karel  is integrated into  Merlin Mission Manager  but because it is built on top of IGIS[4] a few additional steps are necessary to complete  Coder Merlin™ Karel  challenges.

Getting Started[edit]

 Coder Merlin™ Karel  missions take a similar form to other missions and the usage of the  Merlin Mission Manager  is similar. You'll need to follow the same paradigm for accepting and preparing missions and challenges as that of previous missions and challenges. However, there are a few difference which follow:

File Structure[edit]

The challenges require use of a framework (a series of libraries). While most of this is transparent you'll notice several more files in the challenge directory, including:

  • ActionPlan.swift - SHOULD be MODIFIED to develop an effective solution to the challenge.
  • instructions.txt - SHOULD be READ and closely followed before beginning the challenge.
  • 🚫 main.swift - Generally SHOULD NOT be altered. It's responsible for using the  Coder Merlin™ Karel  framework to create the world.
  • 🚫 make.sh - Generally SHOULD NOT be altered. It contains the instructions necessary to build the project.
  • 🚫 Package.swift - Generally SHOULD NOT be altered. It contains a description of the package to be built.
  • 🚫 run.sh - Generally SHOULD NOT be altered. It contains the instructions necessary to run the project.
  • 🚫 WorldPlanner.swift - Generally SHOULD NOT be altered. It contains a description of the world which  Coder Merlin™ Karel  must navigate along with the goal of an effective solution.

Syntax Highlighting[edit]

Syntax highlighting and other Language Services will perform normally in emacs but require additional setup after preparing the challenge. These steps are only required once per challenge.

  1. Enter the challenge directory
  2. Generate a new emacs configuration file

john-williams@codermerlin:~/Merlin...$ dylibEmacs

  1. Open ActionPlan.swift in emacs
  2. A message will appear at the bottom of emacs. When warned about "The local variables list in /home/john-williams/Merlin/...contains values that may not be safe (*)" press ! to apply the local variable list and permanently mark the values as safe
  3. A message will appear at the bottom of emacs:

ActionPlan.swift is not part of any project. Select action:



i==>Import project root ~/Merlin/.../.

I==>Import project by selecting root directory interactively.

d==>Do not ask again for the current project by adding ~/Merlin/.../ to lsp-session-folders-blacklist.

D==>Do not ask again for the current project by selecting ignore path interactively.

n=>Do nothing: ask again when opening other files from the current project.

Press I (capital 'I') and select the directory for this challenge in which Package.swift is located.

Building[edit]

Like most challenges, the project can be built by issuing a build command on the console:

john-williams@codermerlin:~/Merlin...$ build

Alternatively, one can use F5 b from within emacs.

The Goal[edit]

The Instructions[edit]

Building and Running[edit]

Testing[edit]

Submission[edit]

Key Concepts[edit]

Exercises[edit]

References[edit]