ByPass.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from antstar.StickWallAntBrain import StickWallAntBrain
  2. from intelligine.cst import EXPLORATION_VECTOR, MOVE_BYBASS, MOVE_BYBASS_DISTANCE, MOVE_BYBASS_MEMORY, MOVE_BYBASS_WALL,\
  3. MOVE_BYBASS_PREV_WALL
  4. class ByPass(StickWallAntBrain):
  5. def __init__(self, host, home_vector, context, object_id):
  6. """
  7. Note: We broke Liskov principle here.
  8. :param host:
  9. :param home_vector:
  10. :param context:
  11. :param object_id:
  12. :return:
  13. """
  14. super().__init__(host, home_vector)
  15. self._context = context
  16. self._object_id = object_id
  17. self._memory_since_blocked = context.metas.value.get(MOVE_BYBASS_MEMORY,
  18. object_id,
  19. allow_empty=True,
  20. empty_value=[])
  21. self._by_passing = context.metas.value.get(MOVE_BYBASS,
  22. object_id,
  23. allow_empty=True,
  24. empty_value=False)
  25. self._distance_when_blocked = context.metas.value.get(MOVE_BYBASS_DISTANCE,
  26. object_id,
  27. allow_empty=True,
  28. empty_value=None)
  29. self._current_wall_position = context.metas.value.get(MOVE_BYBASS_WALL,
  30. object_id,
  31. allow_empty=True,
  32. empty_value=None)
  33. self._previous_wall_position = context.metas.value.get(MOVE_BYBASS_PREV_WALL,
  34. object_id,
  35. allow_empty=True,
  36. empty_value=None)
  37. def _set_home_vector(self, home_vector):
  38. super()._set_home_vector(home_vector)
  39. self._context.metas.value.set(EXPLORATION_VECTOR, self._object_id, home_vector)
  40. def _set_memory_since_blocked(self, memory_since_blocked):
  41. super()._set_memory_since_blocked(memory_since_blocked)
  42. self._context.metas.value.set(MOVE_BYBASS_MEMORY, self._object_id, memory_since_blocked)
  43. def _set_by_passing(self, by_passing):
  44. super()._set_by_passing(by_passing)
  45. self._context.metas.value.set(MOVE_BYBASS, self._object_id, by_passing)
  46. def _set_distance_when_blocked(self, distance):
  47. super()._set_distance_when_blocked(distance)
  48. self._context.metas.value.set(MOVE_BYBASS_DISTANCE, self._object_id, distance)
  49. def _set_current_wall_position(self, position):
  50. super()._set_current_wall_position(position)
  51. self._context.metas.value.set(MOVE_BYBASS_WALL, self._object_id, position)
  52. def _set_previous_wall_position(self, position):
  53. super()._set_previous_wall_position(position)
  54. self._context.metas.value.set(MOVE_BYBASS_PREV_WALL, self._object_id, position)