subject.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # coding: utf-8
  2. from sandbox.engulf.behaviour import GrowUp, SearchGrass, EatGrass, Explore, CellBehaviourSelector, Hungry, Attack, \
  3. SearchPrey, EatPrey
  4. from sandbox.engulf.const import COLLECTION_CELL, COLLECTION_ALIVE, COLLECTION_EATABLE, COLLECTION_GRASS, \
  5. COLLECTION_PREY, COLLECTION_PREDATOR
  6. from synergine2.simulation import Subject
  7. from synergine2.xyz import XYZSubjectMixin
  8. class Cell(XYZSubjectMixin, Subject):
  9. collections = [
  10. COLLECTION_CELL,
  11. COLLECTION_ALIVE,
  12. COLLECTION_EATABLE,
  13. ]
  14. # TODO: Mettre en place la "selection/choix": car il y a deux move possible chaque cycle ci-dessous.
  15. behaviours_classes = [
  16. Explore,
  17. Hungry,
  18. ]
  19. behaviour_selector_class = CellBehaviourSelector
  20. def __init__(self, *args, **kwargs):
  21. super().__init__(*args, **kwargs)
  22. self._appetite = self.config.simulation.start_appetite # /100
  23. @property
  24. def appetite(self) -> float:
  25. return self._appetite
  26. @appetite.setter
  27. def appetite(self, value) -> None:
  28. if value > 100:
  29. self._appetite = 100
  30. elif value < 0:
  31. self._appetite = 0
  32. else:
  33. self._appetite = value
  34. class PreyCell(Cell):
  35. collections = Cell.collections[:] + [COLLECTION_PREY]
  36. behaviours_classes = Cell.behaviours_classes[:] + [SearchGrass, EatGrass]
  37. class PredatorCell(Cell):
  38. collections = Cell.collections[:] + [COLLECTION_PREDATOR]
  39. behaviours_classes = Cell.behaviours_classes[:] + [SearchPrey, Attack, EatPrey]
  40. class Grass(XYZSubjectMixin, Subject):
  41. collections = [
  42. COLLECTION_EATABLE,
  43. COLLECTION_GRASS,
  44. ]
  45. behaviours_classes = [
  46. GrowUp,
  47. ]
  48. def __init__(self, *args, **kwargs):
  49. self._density = kwargs.pop('density', 100.0)
  50. super().__init__(*args, **kwargs)
  51. @property
  52. def density(self) -> float:
  53. return self._density
  54. @density.setter
  55. def density(self, value: float) -> None:
  56. if value > 100:
  57. self._density = 100
  58. elif value < 0:
  59. self._density = 0
  60. else:
  61. self._density = value