# 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() layRowOne() layRowTwo() layRowThree() layRowFour() moveOutOfTheWay() # function to move Karel from origin to location of head pin # preconditions: At (1,1,East) w/10 beepers in bag # postconditions: At (6,2,North) Location of head pin 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 the first row of pins # preconditions: At (6,2,North) w/10 beepers in bag # postconditions: At (7,3, North) w/9 beepers in bag def layRowOne(): put_beeper() move() turn_right() move() turn_left() # function to lay the second row of pins # preconditions: At (7,3, North) w/9 beepers in bag # postconditions: At (8,4, North) w/7 beepers in bag def layRowTwo(): turn_left() for i in range(2): put_beeper() move() move() turn_around() for i in range(5): move() turn_left() move() # function to lay the third row of pins # precondition: At (8,4, North) w/7 beepers in bag # postconditions: At (9,5, NOrth) w/4 beepers in bag def layRowThree(): turn_left() for i in range(3): put_beeper() move() move() turn_around() for i in range(7): move() turn_left() move() # function to lay the fourth row of pins # precondition: At (9,5, North) w/4 beepers in bag # postconditions: At (10,6, NOrth) w/0 beepers in bag def layRowFour(): turn_left() for i in range(4): put_beeper() move() move() turn_around() for i in range(9): 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()