2011-05-04

//CS106A_Assignment01_Problem02


/*
 * 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.
 */

for more information on free classes, go to cs106a.standford.edu




//Lennard's Solution, May03_2011

import stanford.karel.*;

public class StoneMasonKarel extends SuperKarel {

public void run(){
while (frontIsClear()){
columnRun();
moveToNextColumn();
}
columnRun();
}

//checks initial spot for beeper, then turns and goes up and down
private void columnRun(){
while (noBeepersPresent()){
putBeeper();
}
turnLeft();
moveToTop();
turnAroundz();
placeBeepersOnEmptySquares();
turnLeft();
}

private void moveToNextColumn(){
for (int i=0; i<4; i++){
move();
}
}

// keeps karel moving until you hit the ceiling
private void moveToTop(){
while (frontIsClear()){
move();
}
}

private void turnAroundz(){
for (int i=0; i<2; i++){
turnLeft();
}
}

//simple command that tells karel to keep moving when front is clear and place beepers on empty spots as he is moving
private void placeBeepersOnEmptySquares(){
while (frontIsClear()){
if (noBeepersPresent()){
putBeeper();
move();
}else {
move();
}
}

}

}