Esempio n. 1
0
        robot_exit = False

        while run_active:

            # time checking
            total_time += 1
            if total_time > max_time:
                print "Allotted time exceeded."
                break
            # robot sees if its blocked or not, so it can react accordingly
            testrobot.walled = wall_sense(robot_pos['location'],
                                          robot_pos['heading'])
            # Mazey looks up/adds state to Qtable
            state = get_state(robot_pos['location'], robot_pos['heading'],
                              testrobot.color)
            testmaze.Qtable(state)
            # Mazey finds highest Q value in table for given state
            maxQ = testmaze.bestQ(state)
            # Takes action associated with Q value
            action = testmaze.choose_action(state, maxQ)
            # Lets you know which action was taken for a state
            print state
            print action
            # Action taken; wall built
            testmaze.build(action)
            # Robot checks again to see if its walled
            testrobot.walled = wall_sense(robot_pos['location'],
                                          robot_pos['heading'])
            # Robot makes its move based on color and walled status
            rotation, movement = testrobot.next_move()
            # perform rotation