move.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # coding: utf-8
  2. import typing
  3. from synergine2.config import Config
  4. from synergine2.simulation import SimulationBehaviour, SubjectBehaviour
  5. from synergine2.simulation import Intention
  6. from synergine2.simulation import Simulation
  7. from synergine2.simulation import Event
  8. from synergine2_xyz.simulation import XYZSimulation
  9. class MoveToIntention(Intention):
  10. def __init__(self, move_to: typing.Tuple[int, int]) -> None:
  11. self.move_to = move_to
  12. self.path = [] # type: typing.List[typing.Tuple[int, int]]
  13. self.path_progression = None # type: int
  14. class RequestMoveBehaviour(SimulationBehaviour):
  15. move_intention_class = MoveToIntention
  16. @classmethod
  17. def merge_data(cls, new_data, start_data=None):
  18. # TODO: behaviour/Thing dedicated to Gui -> Simulation ?
  19. pass # This behaviour is designed to be launch by terminal
  20. def __init__(
  21. self,
  22. config: Config,
  23. simulation: Simulation,
  24. ):
  25. super().__init__(config, simulation)
  26. self.simulation = typing.cast(XYZSimulation, self.simulation)
  27. def run(self, data):
  28. # TODO: behaviour/Thing dedicated to Gui -> Simulation ?
  29. pass # This behaviour is designed to be launch by terminal
  30. def action(self, data) -> typing.List[Event]:
  31. subject_id = data['subject_id']
  32. move_to = data['move_to']
  33. try:
  34. subject = self.simulation.subjects.index[subject_id]
  35. subject.intentions.append(self.move_intention_class(move_to))
  36. except KeyError:
  37. # TODO: log error here
  38. pass
  39. return []
  40. class MoveToBehaviour(SubjectBehaviour):
  41. def run(self, data):
  42. # TODO: progresser dans l'intention (comment implementer ça?)
  43. raise NotImplementedError()
  44. def action(self, data) -> [Event]:
  45. # TODO: effectuer un move vers une nouvelle position ou faire progresser "l'entre-deux"
  46. raise NotImplementedError()