コード例 #1
0
def brute_force(max_steps):
    best_action_num = 0
    best_clean_cells = 0

    actions = [1, 4, 4, 1, 2, 2, 2, 2]

    agent = FakeMemorylessAgent(actions)

    n = 4
    m = 4
    p = 1.0

    ## Set up world environment
    environment = Environment(n, m, p)

    ## Main loop
    MAX_ACTIONS = max_steps # prevent from running forever
    num_actions = 0
    num_clean_cells = [0] * max_steps
    running = True
    while (running and num_actions < MAX_ACTIONS):
        # print current world
        print "Action " + str(num_actions)
        environment.printCurrentWorld()

        # set up percept
        percept = environment.getPercept()

        # agent performs a step
        action = agent.takeStep(percept)

        # update environment and counters
        running = environment.updateWorld(action)

        # print num actions & num clean cells
        num_clean_cells[num_actions] = environment.getNumCleanCells()
        num_actions += 1
        print str(num_actions) + ", " + str(num_clean_cells)

    return num_clean_cells
コード例 #2
0
ファイル: runAgent50Trails.py プロジェクト: mqtlam/osu-cs531
    print "******************************%d***************************************" % i
    ## Set up world environment
    environment = Environment(n, m, p)

    ## Main loop
    MAX_ACTIONS = 8000 # prevent from running forever
    num_actions = 0
    num_clean_cells = []
    running = True
    while (running and num_actions < MAX_ACTIONS):
        # print current world
        #print "Action " + str(num_actions)
        #environment.printCurrentWorld()

        # set up percept
        percept = environment.getPercept()

        # agent performs a step
        action = agent.takeStep(percept)
        print "---Action %d has been taken---" % action

        # update environment and counters
        running = environment.updateWorld(action)
        num_actions += 1

        # print num actions & num clean cells
        num_clean_cells.append(environment.getNumCleanCells())
        print "* " + str(num_actions) + ", " + str(num_clean_cells[num_actions-1])

        # for randomized agent experiments
        if num_clean_cells[num_actions-1] >= int(n*m*0.90):