ByPass.py 3.2KB

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