# function to setup a standard set of bowling pins # preconditions: at origin with 10 beepers in bag # postconditions: at (6,6, South) with all pins deployed def setUpPins(): moveToStart() for i in range(4): layRow(i) moveOutOfTheWay() # function to move Karel from origin to right edge of row 1 # preconditions: At (1,1,East) w/10 beepers in bag # postconditions: At (6,2,North): right edge of row 1 def moveToStart(): for i in range(5): move() turn_left() move() # function to move to ending location after all pins set up # preconditions: At right edge of imaginary row 5 # postconditions: at (6,6, South) with all pins deployed def moveOutOfTheWay(): turn_left() for i in range(4): move() turn_left() # function to lay a row of pins # preconditions: At right edge of row to lay facing north # postconditions: At right edge of row i+1 facing north def layRow(cnt): turn_left() for i in range(cnt+1): put_beeper() move() move() turn_around() for i in range((2*(cnt+1))+1): move() turn_left() move() #utility functions def turn_around(): turn_left() turn_left() def turn_right(): for i in range(3): turn_left() # program to set up bowling pins set_trace_style(colour='white') setUpPins() turn_off()