Created
October 28, 2011 04:22
-
-
Save NatashaTheRobot/1321614 to your computer and use it in GitHub Desktop.
This is the solution to the StoneMasonKarel problem in the online Stanford CS 106A class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: StoneMasonKarel.java | |
* -------------------------- | |
* The StoneMasonKarel subclass as it appears here does nothing. | |
* When you finish writing it, it should solve the "repair the quad" | |
* problem from Assignment 1. In addition to editing the program, | |
* you should be sure to edit this comment so that it no longer | |
* indicates that the program does nothing. | |
*/ | |
import stanford.karel.*; | |
public class StoneMasonKarel extends SuperKarel { | |
public void run () { | |
while (frontIsClear()) { | |
BeeperUp(); | |
MoveUp(); | |
BeeperDown(); | |
MoveDown(); | |
} | |
} | |
private void BeeperUp() { | |
turnLeft(); | |
while (frontIsClear()) { | |
if (noBeepersPresent()) { | |
putBeeper(); | |
} | |
move(); | |
} | |
} | |
private void BeeperDown() { | |
turnRight(); | |
while (frontIsClear()) { | |
if (noBeepersPresent()) { | |
putBeeper(); | |
} | |
move(); | |
} | |
} | |
private void MoveUp() { | |
turnRight(); | |
for (int i=0; i<4; i++) { | |
move(); | |
} | |
} | |
private void MoveDown() { | |
turnLeft(); | |
if (frontIsClear()) { | |
for (int i=0; i<4; i++) { | |
move(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/* Hey Check out my solution for Stone Mason Karek the robot problem */
import stanford.karel.*;
public class StoneMasonKarel extends SuperKarel {
}