def __init__(self, methodName, prop_file="models/grid_for_test.props"): super().__init__(methodName=methodName) self.pa = props.read_props(MODEL_NM, prop_file) # Now we create a forest environment for our agents to act within: if self.pa["user_type"] == props.WEB: self.pa["base_dir"] = os.environ["base_dir"] # Now we create a minimal environment for our agents to act within: self.env = ge.GridEnv("Test grid env", self.pa["grid_width"], self.pa["grid_height"], torus=False, model_nm=MODEL_NM, preact=True, postact=True, props=self.pa) for i in range(self.pa["num_agents"]): self.env.add_agent(gm.TestGridAgent(name="agent" + str(i), goal="taking up a grid space!")) self.env.add_agent(gm.TestGridAgent(name="agent for tracking", goal="taking up a grid space!"))
def run(prop_dict=None): (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM) global pa if pa["user_type"] == props.WEB: pa["base_dir"] = os.environ["base_dir"] # Now we create a minimal environment for our agents to act within: env = ge.GridEnv("Test grid env", pa["grid_width"], pa["grid_height"], torus=False, model_nm=MODEL_NM, preact=True, postact=True, props=pa) # Now we loop creating multiple agents with numbered names # based on the loop variable: for i in range(pa["num_agents"]): env.add_agent( gm.TestGridAgent(name="agent" + str(i), goal="taking up a grid space!")) # let's test our iterator for cell in env: (x, y) = cell.coords logging.info("Contents of cell x = " + str(x) + " and y = " + str(y) + " is " + str(cell.contents)) return utils.run_model(env, prog_file, results_file)
def test_add_agent(self): announce('test_add_agent') self.env.add_agent(gm.TestGridAgent(name="new added agent", goal="taking up a grid space!")) # test if the add worked! # test by running new_agent = self.env.agent_inspect("new added agent") self.assertIsNotNone(new_agent)
def restore_agent(self, agent_json): new_agent = ta.TestGridAgent(agent_json["name"], agent_json["goal"], agent_json["max_move"], agent_json["max_detect"]) self.add_agent_to_grid(new_agent, agent_json)