| 01 | import stanford.karel.*; |
| 02 | |
| 03 | public class CheckerboardKarel extends SuperKarel { |
| 04 | |
| 05 | public void run() { |
| 06 | while (leftIsClear()) { |
| 07 | putBeepersInARow(); |
| 08 | goBackToStartOfRow(); |
| 09 | determineNextRow(); |
| 10 | } |
| 11 | putBeepersInARow(); |
| 12 | } |
| 13 | |
| 14 | public void putBeepersInARow() { |
| 15 | putBeeper(); |
| 16 | while (frontIsClear()) { |
| 17 | move(); |
| 18 | if (frontIsClear()) { |
| 19 | move(); |
| 20 | putBeeper(); |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public void goBackToStartOfRow() { |
| 26 | turnAround(); |
| 27 | while (frontIsClear()) { |
| 28 | move(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public void determineNextRow() { |
| 33 | if (beepersPresent()) { |
| 34 | turnRight(); |
| 35 | move(); |
| 36 | turnRight(); |
| 37 | move(); |
| 38 | } else { |
| 39 | turnRight(); |
| 40 | move(); |
| 41 | turnRight(); |
| 42 | } |
| 43 | } |
| 44 | } |
Doing something completely outside of my paradigm has been helping me think and behave in ways I wouldn’t normally think and behave. With each coding exercise, I’ve been learning a lot about myself.
Share and Enjoy:
These icons link to social bookmarking sites where readers can share and discover new web pages.