def simulate(robots, doubletime=False): AGENT = "heuristic" assert distance_constraint_holds(robots) GOAL, MISSION_TIME = calc_battle_plan(robots) assert all_can_reach_goal(robots, GOAL, MISSION_TIME) if doubletime: MISSION_TIME *= 2 STEPS = MISSION_TIME + 1 GOAL_X, GOAL_Y = GOAL data = np.zeros([STEPS, ROBO_COUNT, 2], dtype=np.int32) data[0] = robots traveled, collected = fhl.harvest(data, AGENT, GOAL_X, GOAL_Y, STEPS, ROBO_COUNT) #assert goal_was_reached(data, GOAL) print "Double: ", doubletime print "Robots: ", ROBO_COUNT print "Mission time: ", MISSION_TIME print "Goal: ", GOAL print "Traveled: ", traveled print "Collected: ", collected print "% harvested: ", collected / float(MISSION_TIME * ROBO_COUNT) animated(data,GOAL,interval=100) FILENAME = "test_{}_{}".format(ROBO_COUNT, AGENT) if doubletime: FILENAME += "_double" #svg(data, FILENAME + ".svg") #png(data, FILENAME + ".png")
import numpy as np import fharvest.logic as fhl ROBO_COUNT = 2 MISSION_TIME = 8 STEPS = MISSION_TIME + 1 GOAL_X = 2 GOAL_Y = 2 data = np.zeros([STEPS, ROBO_COUNT, 2], dtype=int) data[0][0] = 1, 2 data[0][1] = 3, 4 data[1][0] = 5, 6 data[1][1] = 7, 8 traveled, collected = fhl.harvest(data, "random", GOAL_X, GOAL_Y, STEPS, ROBO_COUNT) print data print "Traveled: ", traveled print "Collected: ", collected