From 313a15d86daffd0db6935faeb0888003c6d518a0 Mon Sep 17 00:00:00 2001 From: s475275 Date: Sun, 26 Mar 2023 20:57:59 +0200 Subject: [PATCH] =?UTF-8?q?Graf=20dr=C3=B3g=20dla=20agenta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agent.py | 17 ++++++++++++++--- src/simulation.py | 11 +++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/agent.py b/src/agent.py index 1bacb73..6d03eec 100644 --- a/src/agent.py +++ b/src/agent.py @@ -1,6 +1,17 @@ class Agent: def __init__(self): - self.graph = [] + self.graph = {} + self.poi = {} - def inform(self, coordinate_set): - pass + def inform(self, roads_pos, entities): + for index, pos in enumerate(roads_pos): + for another_pos in roads_pos[index:]: + if pos == another_pos: + continue + if abs(pos[0] - another_pos[0]) <= 1 and abs(pos[1] - another_pos[1]) <= 1: + if pos not in self.graph.keys(): + self.graph[pos] = set() + if another_pos not in self.graph.keys(): + self.graph[another_pos] = set() + self.graph[pos].add(another_pos) + self.graph[another_pos].add(pos) diff --git a/src/simulation.py b/src/simulation.py index b67e81b..1c72fa9 100644 --- a/src/simulation.py +++ b/src/simulation.py @@ -49,10 +49,17 @@ class TruckEntity(Entity): self.position = proposed_pos +class Bin: + def __init__(self, size, trash_type): + self.size = size + self.trash_type = trash_type + + class HouseEntity(Entity): def __init__(self, state, position): super().__init__(state, position) self.tile = HOUSE_SPRITES[0] + self.bins = [] class DumpEntity(Entity): @@ -68,6 +75,7 @@ class SimulationState: self.dumps_pos = [] self.entities = [] + # stworzenie mapy i jednostek na podstawie pliku txt map_path = Path("../res/map.txt") with open(map_path, "r") as map_file: map_data = map_file.readlines() @@ -109,7 +117,6 @@ class SimulationState: for entity in self.entities: if entity.__class__ is TruckEntity: entity.move(move_agent) - break class Layer: @@ -233,7 +240,7 @@ class Interface: pg.display.update() def loop(self): - self.agent.inform(set()) + self.agent.inform([(int(pos.x), int(pos.y)) for pos in self.simulation_state.roads_pos], self.simulation_state.entities) while self.run_simulation: self.processUserInput() if not self.debug_mode: