def run(self): self.running = True frames = 0 update_time = 0.0 draw_time = 0.0 t_start = time.now() while (self.running): time.clock.update(60, self.speed) frames += 1 t1 = time.now() self.update() t2 = time.now() update_time += t2 - t1 self.draw() t3 = time.now() draw_time += t3 - t2 self.events() self.running = len( self.ai_player.entities_where( lambda x: type(x).__name__ == "UnitSoldier")) < 20 t_end = time.now() print("--------------------- BARF FORTRESS --------------------") print("Elapsed time: " + str(t_end - t_start) + " ms") print("Frames: " + str(frames)) print("Update time: " + str(update_time) + " ms") print("Update efficiency: " + str(update_time / frames) + " ms/frame") print("Draw time: " + str(draw_time) + " ms") print("Draw efficiency: " + str(draw_time / frames) + " ms/frame")
def __init__(self) -> None: self.subject_id = _Attribute(0) self.target_id = _Attribute(0) self.position = _Attribute(None) self.object = _Attribute(None) self.update_time = time.now() self.fact_id = WorkingMemoryFact.fact_count self.fact_type = None WorkingMemoryFact.fact_count += 1
def run(self): self.running = True for agent in self.agents: agent.start_agent() # dragon scenario #agent.groups = g_map.sprite_group_units #agent.start_actor() frames = 0 update_time = 0.0 draw_time = 0.0 t_start = time.now() while (self.running): #time.clock.update(g_vars["Game"]["FPS"], self.speed) time.clock.update(60, self.speed) frames += 1 t1 = time.now() self.update() t2 = time.now() update_time += t2 - t1 self.draw() t3 = time.now() draw_time += t3 - t2 self.events() self.running = self.agents[0].count_units("Soldier") < 20 t_end = time.now() print("") print("------------------- BARF FORTRESS 2.0 --------------------") print("Elapsed time: " + str(t_end - t_start) + " ms") print("Frames: " + str(frames)) print("Update time: " + str(update_time) + " ms") print("Update efficiency: " + str(update_time / frames) + " ms/frame") print("Draw time: " + str(draw_time) + " ms") print("Draw efficiency: " + str(draw_time / frames) + " ms/frame")
def plan(self, agent, available_actions, world_state=None, goal=None): t1 = time.now() action_cost_table = {} for action in available_actions: # reset action? action.reset() # check available actions if action.check_precondition(agent): action_cost_table[action] = action.get_cost(agent) leaves = [] start = GOAPNode(None, 0, world_state, None) success = self.build_graph(start, leaves, action_cost_table, goal) if not success: # print("Failed to evaluate plan") return None cheapest_node = min(leaves, key=lambda x: x.cost) result = queue.deque() while cheapest_node: if cheapest_node.action: result.appendleft(cheapest_node.action) cheapest_node = cheapest_node.parent else: cheapest_node = None t2 = time.now() #print("planning time: " + str(t2 - t1) + " ms") return result
def run(self): self.running = True ## for x in range(0, 50): worker = Worker() agent = GOAPController() agent.setup(worker) agent.enable_navigation() agent.enable_targeting() agent.enable_sensors() agent.attach_sensor(ResourceSensor()) fact_x = WorkingMemoryFact() res_pos = g_player.get_resource_drop_off_loc() fact_x.set_pos(res_pos, 0.5).set_ftype(FactType.Delivery) agent.working_memory.create_fact(fact_x) agent.blackboard.set_position(Position(2, 2)) g_player.add_unit(agent) ## refinery = Refinery() agent = GOAPController() agent.setup(refinery) agent.blackboard.set_position(Position(4, 5)) agent.blackboard.set_required_artisan(Profession.Refiner) g_player.add_structure(agent) camp = Camp() agent = GOAPController() agent.setup(camp) agent.blackboard.set_is_built(True) agent.blackboard.set_position(Position(2, 2)) g_player.add_structure(agent) smelter = Smelter() agent = GOAPController() agent.setup(smelter) agent.blackboard.set_position(Position(4, 1)) agent.blackboard.set_required_artisan(Profession.Metallurgist) g_player.add_structure(agent) smithy = Smithy() agent = GOAPController() agent.setup(smithy) agent.blackboard.set_position(Position(1, 4)) agent.blackboard.set_required_artisan(Profession.Smith) g_player.add_structure(agent) encampment = Encampment() agent = GOAPController() agent.setup(encampment) agent.blackboard.set_position(Position(8, 1)) g_player.add_structure(agent) frames = 0 update_time = 0.0 draw_time = 0.0 t_start = time.now() while (self.running): #time.clock.update(g_vars["Game"]["FPS"], self.speed) time.clock.update(60, self.speed) frames += 1 t1 = time.now() self.update() t2 = time.now() update_time += t2 - t1 self.draw() t3 = time.now() draw_time += t3 - t2 self.events() self.running = len([u for u in g_player.units if type(u.entity).__name__ == "Soldier"]) < 20 t_end = time.now() print("") print("------------------- BARF FORTRESS 3.0 --------------------") print("Elapsed time: " + str(t_end - t_start) + " ms") print("Frames: " + str(frames)) print("Update time: " + str(update_time) + " ms") print("Update efficiency: " + str(update_time / frames) + " ms/frame") print("Draw time: " + str(draw_time) + " ms") print("Draw efficiency: " + str(draw_time / frames) + " ms/frame")