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
#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): running = 0 ## Results #print "Number of actions: " + str(num_actions) #print "Number of clean cells: " + str(num_clean_cells) + "/" + str(n*m) #environment.performance(num_clean_cells, 1) all_num_clean_cells.append(num_clean_cells) number_actions_to_take.append(num_actions-1) pylab.plot(range(1,len(num_clean_cells)+1), num_clean_cells)