# This program will have Karel build a tower on
# every odd avenue. A tower consists of 3 tennis balls
# stacked on top of each other.
# This function moves Karel to the wall.
def go_down():
while front_is_clear():
move()
# This function has Karel build a tower that is three balls high.
# Precondition: Karel is facing east at the location to build the tower.
# Postcondition: Karel has built the tower, and is back at the base
# facing east.
def build_tower():
turn_left()
for i in range(3):
put_ball()
move()
turn_around()
go_down()
turn_left()
build_tower()
while front_is_clear():
move()
if front_is_clear():
move()
build_tower()/* Karel needs to move to the opposite
* corner of the world facing East. */
function main() {
moveToWall();
turnLeft();
moveToWall();
turnRight();
}
/* This function moves Karel to the end
* of the row.
*/
function moveToWall() {
while (frontIsClear()) {
move();
}
}
main();