simulation.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding: utf-8
  2. import typing
  3. from dijkstar import Graph
  4. from synergine2.config import Config
  5. from synergine2.simulation import Simulation as BaseSimulation
  6. from synergine2_xyz.subjects import XYZSubjects
  7. from synergine2_xyz.subjects import XYZSubject
  8. class XYZSimulation(BaseSimulation):
  9. accepted_subject_class = XYZSubjects
  10. def __init__(
  11. self,
  12. config: Config,
  13. ) -> None:
  14. super().__init__(config)
  15. self.graph = Graph()
  16. # TODO: Le graph devra être calculé à partir de données comme tmx
  17. for y in range(40):
  18. for x in range(70):
  19. position = '{}.{}'.format(x, y)
  20. neighbors = []
  21. for modifier_x, modifier_y in (
  22. (+1, +1),
  23. (+1, +0),
  24. (+1, -1),
  25. (+0, -1),
  26. (-1, -1),
  27. (-1, +0),
  28. (-1, -1),
  29. (+0, +1),
  30. ):
  31. try:
  32. neighbors.append('{}.{}'.format(x+modifier_x, y+modifier_y))
  33. except ValueError:
  34. pass
  35. for neighbor in neighbors:
  36. neighbor_x, neighbor_y = map(int, neighbor.split('.'))
  37. if neighbor_x > 39 or neighbor_x < 0:
  38. continue
  39. if neighbor_y > 69 or neighbor_y < 0:
  40. continue
  41. # TODO: Voir https://pypi.python.org/pypi/Dijkstar/2.2
  42. self.graph.add_edge(position, neighbor, 1)
  43. def is_possible_subject_position(self, subject: XYZSubject, position: tuple) -> bool:
  44. return self.is_possible_position(position)
  45. def is_possible_position(self, position: tuple) -> bool:
  46. return True