Karel the Robot A Gentle Introduction to the Art of Programming.

Slides:



Advertisements
Similar presentations
1 karel_IF_part1 Conditional Statements Flavor 1: if ( ) { } For now: these are method invokations (see next slide)
Advertisements

Karel – Making More Complex Decisions IF / THEN / ELSE IF THEN BEGIN Instructions END ELSE BEGIN Instructions END Do these when test = False Do these when.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Note: Original slides provided by and modified for this specific classwww.apComputerScience.com.
1 of 3 Karel Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Copyright, Joseph Bergin
Nested If Statements While Loops
1 karel_part4_functions.ppt Functions Functions return values or Objects. –Using a function allows the programmer to focus on other task. –Using a function.
You ARE NOT ALLOWED To Copy Files!!!. You ARE NOT ALLOWED To Be Told What to Write in the Program.
CMPUT 101 Lab # 2 September 17, :00 – 16:50.
Karel The Robot Nested If Statements While Loops Copyright © 2008 by Helene G. Kershner.
Karel the Robot -- ITERATE Problem Statement: Karel is told to “take a walk around the block!” Revise Algorithm: Define move ahead 5 streets Define turnright.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
Polymorphism Are there different ways to solve the Harvester problem? – Robot teams – instead of one robot to solve a problem, let’s get a team of robots.
Robot? What’s a Robot? Introducing Karel-the-Robot.
Extending the Robot Programming Language In the Robot world 1 mile = 8 blocks Suppose we want a robot to run a marathon (26+ miles)? Does our program have.
Karel JRobot Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Chapter 5 Conditionally Executing Instructions
1 karel_part5_loops Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit (known)
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: LeftSpinngingRobot, RightSpinningRobot, GuardRobot, etc)
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Maze Challenge Maze Challenge activity > TeachEngineering.org
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
Programming Errors Lexical errors – occur whenever Karel reads a word that is not in his vocabulary. Example in English: We are asking directions and instead.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Karel the Robot A Gentle Introduction to the Art of Object- Oriented Programming in Java.
1 Karel J Robot OOP approach to learning computer science “Its study involves development of the ability to abstract the essential features of a problem.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
Chapter 5.  We’ve been using UrRobot – knows only 5 things  Let’s now use a new type of Robot: Robot!  i.e. – public class MileMover extends Robot.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
Extending Karel’s Vocabulary This PPT originated with Dr. Judy Hankins Modifications have been done by Dr. Untch & Dr. Cripps.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Introduction to Computer Science
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Karel J. Robot Chapter 6 Instructions That Repeat.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
Karel J. Robot Chapter 6 Instructions That Repeat.
CS 106A, Lecture 3 Problem-solving with Karel
Karel – Primitive Instructions
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
In the beginning… software
Eric Roberts and Jerry Cain
Copyright © 2008 by Helene G. Kershner
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Copyright © 2008 by Helene G. Kershner
Karel J Robot.
karel_part4_functions_2
Karel – Primitive Instructions
Karel J Robot.
CS 106A, Lecture 2 Programming with Karel
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
Karel the Robot – Making Decisions
slides courtesy of Eric Roberts
A Gentle Introduction to the Art of Object Oriented Programming
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
Nested If Statements While Loops
CSE 111 Karel the Robot.
Karel – Primitive Instructions
Presentation transcript:

Karel the Robot A Gentle Introduction to the Art of Programming

Schools Using Karel UC-Berkeley U. of Washington Air Force Academy Westpoint (USMA) Carnegie-Mellon Purdue Stanford

What is Karel the Robot? Karel is essentially a programmable cursor that can move across the flat world of a CRT screen. Shown on the screen is a grid work of vertical and horizontal lines, representing avenues and streets.

Karel’s Capabilities Karel is restricted to moving from street corner to street corner, one such move at a time. Karel can pivot 90 degrees to the left when requested. Karel can only face North, South, East, or West.

Beepers To add variety to Karel’s environment, Karel’s designer added beepers, flashing symbols that Karel can detect (we say he “hears” them), pick up, carry, and put down. It is possible to program Karel to locate beepers, transport them, or place them in some graphic pattern.

For example, it might look like the figure below on a computer screen.

Walls Also in Karel’s environment are impenetrable wall sections that can be placed between streets. Karel can “see” wall sections that are immediately to his front or to his left and right sides.

Wall Sections Can be used to form a maze that Karel must navigate

Wall Sections …or to represent hurdles that Karel must “jump” in a hurdle race

Karel’s Capabilities Karel is a mobile robot: he can move forward, in the direction he is facing, and he can turn in place. Karel possesses rudimentary senses:  Sight  Sound  Direction  Touch

Karel is equipped with a mechanical arm that he can use to pick up and put down beepers. To carry these beepers, Karel has a soundproof “beeper bag.” Karel can determine if he is carrying any beepers in this bag by probing it with his arm.

Tasks A “task” is just something that we want Karel to do. Examples:  Move to the corner of 3 rd street & 5 th avenue.  Run a hurdle race (with wall sections representing hurdles).  Run a maze.

Whenever we want Karel to accomplish a task in the world, we must apply a detailed set of instructions that explains how to perform the task. Karel is able to read and follow such a set of instructions, which is called a program.

Situations A “situation”, or “world”, is an exact description of what Karel’s world looks like. The basic structure of streets, avenues, and outer boundary walls is fixed. What else do we need to specify?

Karel’s position: location & direction Location & size of wall sections Location of beepers Initial number of beepers in beeper_bag

Initial and Final Situations The initial situation for any task is defined to be the situation that Karel is placed in at the start of the task. The final situation is the situation that Karel is in when he turns himself off.

Karel initially understands only six imperative commands: Move(); TurnLeft(); PickBeeper(); PutBeeper(); TurnOn(); TurnOff(); When these commands, or function calls, are executed in a Karel program, the results are depicted on the screen.

Move(); A Move() command will graphically show Karel moving from one street corner to the next.

Move(); A Move() command will graphically show Karel moving from one street corner to the next.

Should a wall section be in the way, a Move() command would cause an “Error Shutoff”

TurnLeft(); A TurnLeft () instruction causes Karel to pivot 90 degrees to the left. Karel remains on the same street corner. For example, if Karel is facing east, a TurnLeft () causes him to face north.

TurnLeft(); A TurnLeft () instruction causes Karel to pivot 90 degrees to the left. Karel remains on the same street corner. For example, if Karel is facing east, a TurnLeft () causes him to face north.

PickBeeper(); When Karel executes a PickBeeper () instruction, he picks up a beeper from the corner on which he is standing and then deposits it in his beeper_bag. On a corner with multiple beepers, Karel randomly picks one up – and only one – of the beepers.

PickBeeper(); When Karel executes a PickBeeper () instruction, he picks up a beeper from the corner on which he is standing and then deposits it in his beeper_bag. On a corner with multiple beepers, Karel randomly picks one up – and only one – of the beepers.

PickBeeper(); If a PickBeeper() command is issued and there are no beepers on the corner, then he performs an error shutoff.

PutBeeper(); Karel executes a PutBeeper() instruction by extracting a beeper from his beeper_bag and placing it on his current street corner.

PutBeeper(); Karel executes a PutBeeper() instruction by extracting a beeper from his beeper_bag and placing it on his current street corner.

More about beepers If Karel has no beepers in his beeper_bag and a PutBeeper() command is issued, he performs an error shutoff. Beepers are so small that Karel can move right by them; only wall sections and boundary walls can block his movement.

TurnOn(); The TurnOn() instruction must be the first instruction to be performed in a robot program. This instruction sets up the situation and prepares Karel so he can perform the task defined by the instructions that follow.

TurnOff(); When Karel executes a TurnOff() instruction, he turns himself off and is incapable of executing any more instructions. The last instruction to be executed in every robot program must be a TurnOff() instruction.

A complete robot program: Karel’s task is to transport the beeper from 2 nd street, 4 th avenue to 4 th street and 5 th avenue then to move one street further north before stopping.

TurnOn();

TurnOn(); Move();

TurnOn(); Move(); PickBeeper();

TurnOn(); Move(); PickBeeper(); Move();

TurnOn(); Move(); PickBeeper(); Move(); TurnLeft();

TurnOn(); Move(); PickBeeper(); Move(); TurnLeft(); Move();

TurnOn(); Move(); PickBeeper(); Move(); TurnLeft(); Move();

TurnOn(); Move(); PickBeeper(); Move(); TurnLeft(); Move(); PutBeeper(); Move();

TurnOn(); Move(); PickBeeper(); Move(); TurnLeft(); Move(); PutBeeper(); Move(); TurnOff();

#include “karel.h” int main() { TurnOn(); Move(); PickBeeper(); Move(); TurnLeft(); Move(); PutBeeper(); Move(); TurnOff(); }