« CS106A: Programming Methodology Assignment 1.4 | Main | CS106A: Programming Methodology Assignment 1.2 »
Wednesday
Dec052012

CS106A: Programming Methodology Assignment 1.3


import stanford.karel.*;

public class CheckerboardKarel extends SuperKarel {

	public void run() {
		if (frontIsClear()){
		horizontalPlacement();
		while (frontIsClear()){
			nextRow();
			horizontalPlacement();
		}
		} else {
			verticalPlacement();
		}
	}
	
	public void verticalPlacement() {
		turnLeft();
		while (frontIsClear()){
			if (frontIsClear()){
				putBeeper();
				move();
			}
			if (frontIsClear()){
				move();
			}
			}
	}
	
	public void horizontalPlacement() {
		while (frontIsClear()){
		if (frontIsClear()){
			putBeeper();
			move();
		}
		if (frontIsClear()){
			move();
		}
		}
		
		if (facingEast()){
			turnLeft();
		} else if (facingWest()){
			turnRight();
		}
	}

	public void nextRow() {
		move();
		turnRight();
		if (frontIsBlocked()){
			turnAround();
		}
	}
	
	
}