Graf dróg dla agenta

This commit is contained in:
s475275 2023-03-26 20:57:59 +02:00
parent 681719df65
commit 313a15d86d
2 changed files with 23 additions and 5 deletions

View File

@ -1,6 +1,17 @@
class Agent: class Agent:
def __init__(self): def __init__(self):
self.graph = [] self.graph = {}
self.poi = {}
def inform(self, coordinate_set): def inform(self, roads_pos, entities):
pass 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)

View File

@ -49,10 +49,17 @@ class TruckEntity(Entity):
self.position = proposed_pos self.position = proposed_pos
class Bin:
def __init__(self, size, trash_type):
self.size = size
self.trash_type = trash_type
class HouseEntity(Entity): class HouseEntity(Entity):
def __init__(self, state, position): def __init__(self, state, position):
super().__init__(state, position) super().__init__(state, position)
self.tile = HOUSE_SPRITES[0] self.tile = HOUSE_SPRITES[0]
self.bins = []
class DumpEntity(Entity): class DumpEntity(Entity):
@ -68,6 +75,7 @@ class SimulationState:
self.dumps_pos = [] self.dumps_pos = []
self.entities = [] self.entities = []
# stworzenie mapy i jednostek na podstawie pliku txt
map_path = Path("../res/map.txt") map_path = Path("../res/map.txt")
with open(map_path, "r") as map_file: with open(map_path, "r") as map_file:
map_data = map_file.readlines() map_data = map_file.readlines()
@ -109,7 +117,6 @@ class SimulationState:
for entity in self.entities: for entity in self.entities:
if entity.__class__ is TruckEntity: if entity.__class__ is TruckEntity:
entity.move(move_agent) entity.move(move_agent)
break
class Layer: class Layer:
@ -233,7 +240,7 @@ class Interface:
pg.display.update() pg.display.update()
def loop(self): 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: while self.run_simulation:
self.processUserInput() self.processUserInput()
if not self.debug_mode: if not self.debug_mode: