mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-18 18:52:52 +02:00
WIP: removing tiles
This commit is contained in:
@ -54,9 +54,10 @@ class TSPBaseAgent(ABC):
|
||||
nodes=nodes, cycle=True, method=tsp.greedy_tsp)
|
||||
return route
|
||||
|
||||
def _door_is_close(self):
|
||||
def _door_is_close(self, state):
|
||||
try:
|
||||
return next(y for x in self.state.tile.neighboring_floor for y in x.guests if do.DOOR in y.name)
|
||||
# return next(y for x in self.state.tile.neighboring_floor for y in x.guests if do.DOOR in y.name)
|
||||
return next(y for x in state.entities.neighboring_positions(self.state.pos) for y in state.entities.pos_dict[x] if do.DOOR in y.name)
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
|
@ -14,7 +14,7 @@ class TSPDirtAgent(TSPBaseAgent):
|
||||
if self._env.state[di.DIRT].by_pos(self.state.pos) is not None:
|
||||
# Translate the action_object to an integer to have the same output as any other model
|
||||
action = di.CLEAN_UP
|
||||
elif door := self._door_is_close():
|
||||
elif door := self._door_is_close(self._env):
|
||||
action = self._use_door_or_move(door, di.DIRT)
|
||||
else:
|
||||
action = self._predict_move(di.DIRT)
|
||||
|
@ -24,7 +24,7 @@ class TSPItemAgent(TSPBaseAgent):
|
||||
elif self._env.state[i.DROP_OFF].by_pos(self.state.pos) is not None:
|
||||
# Translate the action_object to an integer to have the same output as any other model
|
||||
action = i.ITEM_ACTION
|
||||
elif door := self._door_is_close():
|
||||
elif door := self._door_is_close(self._env):
|
||||
action = self._use_door_or_move(door, i.DROP_OFF if self.mode == MODE_BRING else i.ITEM)
|
||||
else:
|
||||
action = self._choose()
|
||||
|
@ -11,15 +11,16 @@ class TSPTargetAgent(TSPBaseAgent):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TSPTargetAgent, self).__init__(*args, **kwargs)
|
||||
|
||||
def _handle_doors(self):
|
||||
def _handle_doors(self, state):
|
||||
|
||||
try:
|
||||
return next(y for x in self.state.tile.neighboring_floor for y in x.guests if do.DOOR in y.name)
|
||||
# return next(y for x in self.state.tile.neighboring_floor for y in x.guests if do.DOOR in y.name)
|
||||
return next(y for x in state.entities.neighboring_positions(self.state.pos) for y in state.entities.pos_dict[x] if do.DOOR in y.name)
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
def predict(self, *_, **__):
|
||||
if door := self._door_is_close():
|
||||
if door := self._door_is_close(self._env):
|
||||
action = self._use_door_or_move(door, d.DESTINATION)
|
||||
else:
|
||||
action = self._predict_move(d.DESTINATION)
|
||||
|
Reference in New Issue
Block a user