| CONTENTS | |
| Preface | iii |
| Dedication | v |
| Chapter 1 The Robot World | 1 |
| 1.1 The Robot World | 1 |
| 1.2 Robot Capabilities | 3 |
| 1.3 Tasks and Situations | 4 |
| 1.4 Robots and Objects | 4 |
| 1.5 Important Ideas From This Chapter | 5 |
| 1.6 Problem Set | 5 |
| Chapter 2 Primitive Instructions and Simple Programs | 7 |
| 2.1 Changing Position | 7 |
| 2.2 Turning in Place | 8 |
| 2.3 Finishing a Task | 9 |
| 2.4 Handling Beepers | 9 |
| 2.5 Robot Descriptions | 9 |
| 2.6 A Complete Program | 11 |
| 2.6.1 Executing a Program | 12 |
| 2.6.2 The Form of Robot Programs | 14 |
| 2.7 Error Shutoffs | 15 |
| 2.8 Programming Errors | 16 |
| 2.8.1 Bugs and Debugging | 18 |
| 2.9 A Task for Two Robots | 19 |
| 2.10 An infinity of Beepers | 20 |
| 2.11 Some Terminology | 20 |
| 2.12 Important Ideas From This Chapter | 21 |
| 2.13 Problem Set | 21 |
| Chapter 3 Extending the Robot Programming Language | 30 |
| 3.1 Creating a More Natural Programming Language | 30 |
| 3.2 A Mechanism that Defines New Classes of Robots | 31 |
| 3.3 Defining the New Methods | 32 |
| 3.4 The Meaning and Correctness of New Methods | 35 |
| 3.5 Defining New Methods in a Program | 36 |
| 3.6 Modifying Inherited Methods | 39 |
| 3.7 An Ungrammatical Program | 41 |
| 3.8 Tools for Designing and Writing Robot Programs | 42 |
| 3.8.1 Stepwise Refinement-a Technique for Planning, Implementing, and | |
| Analyzing Robot Programs | 42 |
| 3.8.2 The Second Step-Planning harvestTwoRows and positionForNextHarvest | 46 |
| 3.8.3 The Third Step-Planning harvestOneRow and goToNextRow | 48 |
| 3.8.4 The Final Step-Verifying That the Complete Program is Correct | 50 |
| 3.9 Advantages of Using New Instructions | 52 |
| 3.9.1 Avoiding Errors | 53 |
| 3.9.2 Future Modifications | 54 |
| 3.9.3 A Program Without New instructions | 56 |
| 3.10 Writing Understandable Programs | 58 |
| 3.11 Important Ideas From This Chapter | 59 |
| 3.12 Problem Set | 59 |
| Chapter 4 Polymorphism | 65 |
| 4.1 Robot Teams | 65 |
| 4.2 Similar Tasks | 67 |
| 4.3 Choreographers | 70 |
| 4.4 Object Oriented Design -- Clients and Servers | 73 |
| 4.5 Using Polymorphism | 79 |
| 4.6 Still More on Polymorphism -- Strategy and Delegation | 83 |
| 4.7 Java Enumerations and More on Strategies | 89 |
| 4.8 Decorators | 93 |
| 4.9 Observers | 95 |
| 4.10 Final Words on Polymorphism | 97 |
| 4.11 Important Ideas From This Chapter | 98 |
| 4.12 Problem Set | 99 |
| Chapter 5 Conditionally Executing Instructions | 103 |
| 5.1 The IF Instruction | 103 |
| 5.2 The Conditions That Robots Can Test | 104 |
| 5.2.1 Writing New Predicates | 106 |
| 5.3 Simple Examples of the IF Instruction | 108 |
| 5.3.1 The harvestOneRow Method | 108 |
| 5.3.2 The faceNorthIfFacingSouth Method | 109 |
| 5.3.3 The faceNorth Method | 110 |
| 5.3.4 Determining the correctness of the IF Instruction | 112 |
| 5.4 The IF/ELSE Instruction | 113 |
| 5.5 Nested IF Instructions | 115 |
| 5.6 More Complex Tests | 119 |
| 5.7 When to Use an IF Instruction | 121 |
| 5.8 Transformations for Simplifying IF Instructions | 123 |
| 5.9 Polymorphism Revisited | 127 |
| 5.10 Important Ideas From This Chapter | 129 |
| 5.11 Problem Set | 129 |
| Chapter 6 Instructions That Repeat | 136 |
| 6.1 The FOR-LOOP Instruction | 136 |
| 6.2 The WHILE Instruction | 139 |
| 6.2.1 Why WHILE is Needed | 139 |
| 6.2.2 The Form of the WHILE Instruction | 139 |
| 6.2.3 Building a WHILE Loop - the Four Step Process | 140 |
| 6.2.4 A More Interesting Problem | 142 |
| 6.3 Errors to Avoid with WHILE Loops | 144 |
| 6.3.1 The Fence Post Problem | 145 |
| 6.3.2 Infinite Execution | 146 |
| 6.3.3 When the test of a WHILE is Checked | 147 |
| 6.4 Nested WHILE Loops | 148 |
| 6.4.1 A Good Example of Nesting | 148 |
| 6.4.2 A Bad Example of Nesting | 151 |
| 6.5 WHILE and IF Instructions | 157 |
| 6.6 Reasoning about Loops | 158 |
| 6.7 A Large Program Written by Stepwise Refinement | 161 |
| 6.8 Enumerations and the While Statement | 166 |
| 6.9 When to Use a Repeating Instruction | 167 |
| 6.10 Important Ideas From This Chapter | 169 |
| 6.11 Problem Set | 169 |
| Chapter 7 Advanced Techniques for Robots | 184 |
| 7.1 Introduction to Recursion | 184 |
| 7.2 More on Recursion | 186 |
| 7.3 Tail Recursion and Looping | 190 |
| 7.4 Going Formal | 191 |
| 7.5 Searching | 191 |
| 7.6 Doing Arithmetic | 196 |
| 7.7 Polymorphism--Why Write Many Programs When One Will Do? | 201 |
| 7.8 Conclusion | 203 |
| 7.9 Important Ideas From This Chapter | 204 |
| 7.10 Problem Set | 204 |
| Chapter 8 Concurrent Robot Programs | 209 |
| 8.1 Simple Concurrent Programs | 209 |
| 8.2 Robot Runs In Its Own Thread | 210 |
| 8.3 Cooperation | 211 |
| 8.4 Race Conditions | 212 |
| 8.5 Deadlock | 213 |
| 8.6 Important Ideas From This Chapter | 215 |
| 8.7 Problem Set | 215 |
| Appendix | 217 |
| 1 Java main | 217 |
| 2 KarelRunner | 218 |
| 3 Compiling and Executing Robot Code | 219 |
| 4 Constructors in Java | 220 |
| 5 Controllers and Inner Classes | 221 |
| 6 Java Cloning | 225 |
| Index of Terms | 227 |
| Index of Classes Used in the Book | 228 |
| Index of Methods Used in the Book | 229 |