Welcome (back) to IST 338 ! Wow – I see the resemblance Average of these two? ����� ����� Problem 0: Already complete! Problem 1: Four-fours program: Can be done for lab... Homework 0 Problem 2: Rock-paper-scissors program ( Maybe done already!) due Sun. night (11:59pm) Problems 3-5: Picobot! empty room (3) maze (4) + extra (5) Problem 6: Reading + response…
Welcome (back) to IST 338 ! Wow – I see the resemblance ����� Picobot! ����� Problem 0: Already complete! Problem 1: Four-fours program: Can be done for lab... Homework 0 Problem 2: Rock-paper-scissors program ( Maybe done already!) due Sun. night (11:59pm) Problems 3-5: Picobot! empty room (3) maze (4) + extra (5) Problem 6: Reading + response…
Welcome back (from) Baltimore! world's expert on badge- based incentive systems for education…
Extreme RPS!? They call that an alien? Spock mind-melds three-eyed aliens! Provably. http://www.youtube.com/watch?v=iapcKVn7DdY http://www.youtube.com/watch?v=yuEZEyDdmvQ
Last time… CS != Programming
What about the Python programming language ?
Python ? One possible relationship... vs.
Python ! One possible relationship... vs. Happy co-existence… It can even be comfy!
Exclusive Choices if ... elif ... else if perc > .95 : print 'A' elif perc > .90 : print 'A-' 4 mutually exclusive blocks elif perc > .70 : in a single control structure print 'Pass' else: When using print 'Aargh!' if . elif … . else at most one block will run: the first whose test is True . elif and else are optional If all fail, the else will run
What's the difference? non exclusive blocks mutually exclusive blocks if perc > .95 : if perc > .95 : print 'A' print 'A' elif perc > .90 : if perc > .90 : print 'A-' print 'A-' elif perc > .70 : if perc > .70 : print 'Pass' print 'Pass' What if perc == .99 ? (How would we set it?) How many separate control structures does each side have?
Does this program print the What will this do? correct RPS result this time ? Does it always? comp = 'rock' user = 'paper' if comp == 'paper' and user == 'paper': print 'We tie. Try again?' elif comp == 'rock': if user == 'scissors': print 'I win! *_*' else: print 'You win. Aargh!' # of BLOCKS ? # of TESTS ? try it: RPS example #1 # of Control Structures ?
Counting... comp = 'rock' # of BLOCKS # of TESTS user = 'rock' if comp == 'rock': if user == 'paper': print 'I win *_*!' Printing… elif user == 'scissors': print 'You win.' else: print 'Tie.' print 'Ties go to the runner.' print ' - and I am running!' try it: RPS example #2 ... what if the else were indented?
How many possible “input cases” are there? What does For how many is this program correct? this print? comp = 'rock' user = 'rock' if comp == 'rock': print 'I win *_*!' if user == 'paper': print 'You win.' else: print 'An awful tie' try it: RPS example #3
How many possible “input cases” are there? What does For how many is this program correct? this print? comp 'rock' 'paper' 'scissors' comp = 'rock' user 'rock' user = 'rock' if comp == 'rock': 'paper' print 'I win *_*!' if user == 'paper': 'scissors' print 'You win.' else: print 'An awful tie' … how efficiently can RPS be represented by program? • Fewest number of blocks ? • Fewest number of tests ?
shell prompt > or $ This week: hw0pr1 Python prompt >>> shell or command- Python source code, line or terminal a plain-text file (the execution environment) (here, edited by the Sublime text editor) get Python running on your own machine
Commanding the command-line Mac/Linux/ Windows Powershell in Windows' plain cmd pwd p rint w orking d irectory (current path) cd . l i s t (current directory) ls dir cd c hange d irectory cd .. . . shortcut for "directory above" . . shortcut for "current directory" mv m o v e (source/from) (destination/to) move cp c o p y (source/from) (destination/to) copy mkdir m a k e dir ectory (name of new dir) mkdir
Desktop Mental model .. . CS5 (folder) CS5 (folder) pico3.txt (file) start pico4.txt (file) usual picture ~ a window into the underlying structure
a couple of shortcuts… Up arrow Brings back previously-typed commands • Down arrow ~ scrolls the other way • Tab key Completes the file or folder name you start • Cycles through possibilities (older versions would pause…) •
Desktop Mental model .. . CS5 (folder) $ cd .. $ pwd cd CS5 (folder) $ ls dir pico3.txt (file) $ cd C start pico4.txt (file) $ mkdir BotFiles $ cd B $ cp ../pico3.txt . copy $ $ mv p .. move
Desktop Mental model .. . pico3.txt (file) CS5 (folder) $ cd .. $ pwd cd . CS5 (folder) $ ls dir $ cd C end pico4.txt (file) BotFiles $ mkdir BotFiles (folder) $ cd B BotFiles (folder) $ cp ../pico3.txt . copy pico3.txt (file) $ $ mv p .. move
Desktop Draw the changes these shell Try it! commands will make… CS5 (folder) $ mkdir Week0 $ cd W CS5 (folder) $ mv ../h . move hw0pr 0 .py (file) hw0pr 1 .py $ cd .. start (file) $ mkdir Week1 $ cd W $ cp ../h . copy $ Extra #2: What line here would copy the hw0pr0.py file to the current location? See if you can use tabs… $ Extra #1: What is the current folder here? $
Not to mention… python if you don't want to type the full path: c:\python27\python which where add ;c:\python27 cat type find . tree ping may need curl or wget This is a window into the directory tree … to install
XKCD's perspective…
Command line?!? The Operating System's Window Manager Consume Computational interactions (files, folders, data…) Compose Physical interactions (arithmetic and storage) Crazy! not really fair…
Command line?!? The Operating System's Window Manager Consume Computational interactions (files, folders, data…) Compose Physical interactions (arithmetic and storage) Commoditized!
Useful? Consuming Composing
Useful? Consuming Composing Everything at the command line is automatable and programmable…
Useful! Consuming Composing Everything at the command line is automatable and programmable…
Another language already ? Picobot! Python General-purpose language you might see 50% by the end of the term even then, <1% of its libraries! Picobot Special-purpose language you'll see 100% in The Picobot simulator the next 10 minutes www.cs.hmc.edu/picobot
HW problems 3 and 4: Picobot! Goal: full-room walls Picobot coverage with only local sensing … area not covered (yet!) area already covered Inspiration? Picobot can't tell…
HW problems 3 and 4: Picobot! Goal: full-room walls Picobot coverage with only local sensing … area not covered (yet!) area already covered Roomba! Picobot can't tell "vacuumed" can't tell… from "unvacuumed" area
Surroundings Picobot can only sense things N directly to the N, E, W, and S E W S For example, here its surroundings are N x W x N E W S Surroundings are always in NEWS order.
What are these surroundings? Surroundings are always in NEWS order. N E W S N x W x Wow - this one is disgusting!
Surroundings How many distinct N surroundings are there? E W S
Surroundings How many distinct N surroundings are there? E W 2 4 == 16 possible S xxxx Nxxx xExx xxWx xxxS NExx NxWx NxxS xEWx xExS xxWS NEWx NExS NxWS xEWS NEWS (won ’ ’ t happen) ’ ’
State I am in state 0. My surroundings are xx WS . Picobot's memory is a single number, called its state. 0 State is the internal context of a computation, i.e., the subtask . Picobot always starts in state 0. State and surroundings represent everything Picobot knows about the world self-contained but not simplistic
Rules I am in state 0. My surroundings are xx WS . Picobot acts through a set of rules : state surroundings direction new state xx WS 0 N 0 Picobot checks its rules from the top each time. Notes When it finds a matching rule, that rule runs.
Rules I am in state 0. My surroundings are xx WS . Picobot acts through a set of rules Each rule expresses your intent for Picobot! state surroundings direction new state xx WS 0 N 0 Then I move N orth, and If I'm now in state 0 seeing xx WS , "change" to state 0 .
Wildcards I only care about NORTH being EMPTY Asterisks * are wild cards. They match walls or empty space: state surroundings direction new state x*** 0 N 0 EWS may be wall or empty space N must be empty
(A) A rule that sends Picobot to the North as far as it can go: state surroundings direction new state x*** 0 -> N 0 (B) What does this next rule do? N*** 0 -> W 1 (C) What about this one? 1 ***x -> S 1 (D) How could we stop at the bottom and return up through the same column ?
Recommend
More recommend