# Class: # Date: # Student Author: # Start by importing the libraries needed for the program from Myro import * from Graphics import * #------------------------------------------------------------------------ # solveMaze function: Students should replace the pass in the body here # with a sequence of Python statements to orient the # robot and move it through the maze until it "bumps # into" the red ball at the end of the maze. Students # should observe how the solveMaze() function is # invoked in the body of the main() function. #------------------------------------------------------------------------ def solveMaze(): pass #------------------------------------------------------------------------ # main function: defined by Dr. Bressoud, and should _not_ need mod # by the students #------------------------------------------------------------------------ def main(): # Initialize the basic simulated world width = 500 height = 400 sim = Simulation(width, height, True, True) # Get items in world: light = sim.window.canvas.shapes[0] left_wall = sim.window.canvas.shapes[1] top_wall = sim.window.canvas.shapes[2] right_wall = sim.window.canvas.shapes[3] bottom_wall = sim.window.canvas.shapes[4] pyramid = sim.window.canvas.shapes[5] ball = sim.window.canvas.shapes[6] # Get rid of original set of shapes in canvas: sim.window.canvas.shapes.Remove(ball) sim.window.canvas.shapes.Remove(pyramid) sim.window.canvas.shapes.Remove(bottom_wall) sim.window.canvas.shapes.Remove(right_wall) sim.window.canvas.shapes.Remove(top_wall) sim.window.canvas.shapes.Remove(left_wall) sim.window.canvas.shapes.Remove(light) # Add outer boundaries sim.addWall((0, 0), (width, 10), Color("blue")) sim.addWall((0, 0), (10, height), Color("blue")) sim.addWall((width - 10, 0), (width, height), Color("blue")) sim.addWall((0, height - 10), (width, height), Color("blue")) # Add the walls of the maze sim.addWall((90, 80), (100, 390), Color("lightblue")) sim.addWall((100, 80), (180, 90), Color("lightblue")) poly = Polygon((175, 90), (180, 80), (245, 250), (240, 260)) poly.bodyType = "static" poly.color = Color("lightblue") poly.outline = Color("black") sim.addShape(poly) sim.addWall((300, 310), (410, 320), Color("lightblue")) sim.addWall((400, 100), (410, 320), Color("lightblue")) sim.addWall((400, 90), (489, 99), Color("lightblue")) # Add the ball that is the objective of the exercise ball = Circle(Point(450, 140), 28) ball.color = Color("red") ball.outline = Color("black") ball.bodyType = "static" sim.addShape(ball) # Finally, put the robot into the maze in its initial position robot = makeRobot("SimScribbler", sim) sim.setPose(0, 50, 350, 20) # Start simulation loop: sim.setup() # The following invokes the solution function defined by the students solveMaze() # Keep the simulation going until the window is closed sim.loop() main()