1 / 17

LEARN TO CODE WORKSHOP

LEARN TO CODE WORKSHOP. LESSON 3: Robots that Survey the World George Kramer , george.Kramer@uconn.edu. +. +. Administrative. No workshop will be held on 10/16/2014 Remaining workshops will be pushed back by one week Look out for additional details in weekly ACM newsletter. Motivation.

Télécharger la présentation

LEARN TO CODE WORKSHOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LEARN TO CODE WORKSHOP LESSON 3: Robots that Survey the WorldGeorge Kramer, george.Kramer@uconn.edu + +

  2. Administrative • No workshop will be held on 10/16/2014 • Remaining workshops will be pushed back by one week • Look out for additional details in weekly ACM newsletter

  3. Motivation • Develop dynamic thought processes using logic statements • Want robots to survey their world to determine what to do next

  4. Translating Thought Processes • English language is ambiguous • First interpretations are difficult to change • Want to make informal logic statements formal

  5. Logic Statements • Are true or false but not both • Valid statements • 2 + 2 = 4 • 2 + 2 = 5 • Invalid statements • He is a college student • Statements may be combined using symbols and operators

  6. Logic Operators • Parenthesis can be used to override operator precedence

  7. Compound Logic Statements • English translations for given statements p and q • ~p = not p (Negation of p) • p ∧ q = p and q (Conjunction of p and q) • p ∨ q = p or q (Disjunction of p and q) • Symbolic translations for given English sentences • Let h = “It is hot” and s = “It is sunny” • It is not hot but it is sunny = ~h ∧ s • It is neither hot nor sunny = ~h ∧ ~s

  8. Truth Values • Recall statements must be either true or false • The truth or falsity of statements is determined by their truth value • Truth values can be determined from truth tables

  9. Truth Table: AND Operator • Both statements must be true for the overall statement to be true

  10. Truth Table: OR Operator • Only one of the statements needs to be true for the overall statement to be true

  11. Truth Table: NOT Operator • Consider the opposite value of the statement to be true

  12. Truth Table: Compound Statements

  13. Logic Statements in Java • Recall • Objects can do things • Objects can remember things… and tell you what they remember! • Objects can tell you true and false statements • Logic statements must be written to be grammatically correct

  14. Grammar of Logic Statements in Java if (statement1) { // Instructions to execute when statement1 is true } else if (statement2) { // Instructions to execute when statement1 is false but // statement2 is true } else { // Instructions to execute when all above statements are false }

  15. Statements for Karel J. Robot

  16. Example of Robot that Surveys the World SuperRobotkarel = new SuperRobot(1, 1, East, 0); if (!karel.frontIsClear() && !karel.rightIsClear()) { karel.turnLeft(); } else { karel.move(); }

  17. Now It’s Your Turn!!! • Download and work on first two problems of lesson 3 problem set

More Related