run.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. """
  2. Engulf is simulation containing:
  3. * Subjects who need to:
  4. * eat
  5. * low energy ground stuff
  6. * other alive subjects
  7. * other dead subjects
  8. * sleep
  9. * want to be not alone
  10. * with non aggressive subjects
  11. * want to be alone
  12. * reproduce
  13. * with non aggressive subjects
  14. * and transmit tendencies because their cultures can be
  15. * eat: - eat background stuff, + eat subjects
  16. * alone/not alone: - be alone + not alone
  17. """
  18. from random import randint
  19. from sandbox.engulf.subject import Cell
  20. from synergine2.core import Core
  21. from synergine2.cycle import CycleManager
  22. from synergine2.terminals import TerminalManager, Terminal, TerminalPackage
  23. from synergine2.xyz import Simulation
  24. from synergine2.xyz import XYZSubjects
  25. class Engulf(Simulation):
  26. pass
  27. class GameTerminal(Terminal):
  28. subscribed_events = []
  29. def __init__(self):
  30. super().__init__()
  31. self.gui = None
  32. def receive(self, package: TerminalPackage):
  33. self.gui.before_received(package)
  34. super().receive(package)
  35. self.gui.after_received(package)
  36. def run(self):
  37. from sandbox.engulf import gui
  38. self.gui = gui.Game(self)
  39. self.gui.run()
  40. def get_random_subjects(
  41. simulation: Simulation,
  42. count: int,
  43. x_min: int,
  44. y_min: int,
  45. x_max: int,
  46. y_max: int,
  47. ) -> [Cell]:
  48. cells = XYZSubjects(simulation=simulation)
  49. while len(cells) < count:
  50. position = (
  51. randint(x_min, x_max+1),
  52. randint(y_min, y_max+1),
  53. 0
  54. )
  55. if position not in cells.xyz:
  56. cells.append(Cell(
  57. simulation=simulation,
  58. position=position,
  59. ))
  60. return cells
  61. def main():
  62. simulation = Engulf()
  63. subjects = get_random_subjects(
  64. simulation,
  65. 30,
  66. -34,
  67. -34,
  68. 34,
  69. 34,
  70. )
  71. simulation.subjects = subjects
  72. core = Core(
  73. simulation=simulation,
  74. cycle_manager=CycleManager(simulation=simulation),
  75. terminal_manager=TerminalManager([GameTerminal()]),
  76. )
  77. core.run()
  78. if __name__ == '__main__':
  79. main()