subject.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding: utf-8
  2. from sandbox.engulf.behaviour import GrowUp, SearchFood, Eat, Explore, CellBehaviourSelector, Hungry
  3. from sandbox.engulf.const import COLLECTION_CELL, COLLECTION_ALIVE, COLLECTION_EATABLE, COLLECTION_GRASS
  4. from synergine2.simulation import Subject
  5. from synergine2.xyz import XYZSubjectMixin
  6. class Cell(XYZSubjectMixin, Subject):
  7. collections = [
  8. COLLECTION_CELL,
  9. COLLECTION_ALIVE,
  10. COLLECTION_EATABLE,
  11. ]
  12. # TODO: Mettre en place la "selection/choix": car il y a deux move possible chaque cycle ci-dessous.
  13. behaviours_classes = [
  14. SearchFood,
  15. Eat,
  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 Grass(XYZSubjectMixin, Subject):
  35. collections = [
  36. COLLECTION_EATABLE,
  37. COLLECTION_GRASS,
  38. ]
  39. behaviours_classes = [
  40. GrowUp,
  41. ]
  42. def __init__(self, *args, **kwargs):
  43. self._density = kwargs.pop('density', 100.0)
  44. super().__init__(*args, **kwargs)
  45. @property
  46. def density(self) -> float:
  47. return self._density
  48. @density.setter
  49. def density(self, value: float) -> None:
  50. if value > 100:
  51. self._density = 100
  52. elif value < 0:
  53. self._density = 0
  54. else:
  55. self._density = value