added target agent test and fixed tsp agents

This commit is contained in:
Chanumask
2024-01-18 13:32:30 +01:00
parent ecf53e7d64
commit 51612812b0
6 changed files with 100 additions and 27 deletions

View File

@ -11,10 +11,11 @@ class TSPDirtAgent(TSPBaseAgent):
super(TSPDirtAgent, self).__init__(*args, **kwargs)
def predict(self, *_, **__):
if self._env.state[di.DIRT].by_pos(self.state.pos) is not None:
dirt_at_position = self._env.state[di.DIRT].by_pos(self.state.pos)
if dirt_at_position:
# 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(self._env):
elif door := self._door_is_close(self._env.state):
action = self._use_door_or_move(door, di.DIRT)
else:
action = self._predict_move(di.DIRT)

View File

@ -18,13 +18,15 @@ class TSPItemAgent(TSPBaseAgent):
self.mode = mode
def predict(self, *_, **__):
if self._env.state[i.ITEM].by_pos(self.state.pos) is not None:
item_at_position = self._env.state[i.ITEM].by_pos(self.state.pos)
dropoff_at_position = self._env.state[i.DROP_OFF].by_pos(self.state.pos)
if item_at_position:
# Translate the action_object to an integer to have the same output as any other model
action = i.ITEM_ACTION
elif self._env.state[i.DROP_OFF].by_pos(self.state.pos) is not None:
elif dropoff_at_position:
# 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(self._env):
elif door := self._door_is_close(self._env.state):
action = self._use_door_or_move(door, i.DROP_OFF if self.mode == MODE_BRING else i.ITEM)
else:
action = self._choose()

View File

@ -20,7 +20,7 @@ class TSPTargetAgent(TSPBaseAgent):
return None
def predict(self, *_, **__):
if door := self._door_is_close(self._env):
if door := self._door_is_close(self._env.state):
action = self._use_door_or_move(door, d.DESTINATION)
else:
action = self._predict_move(d.DESTINATION)