run.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # coding: utf-8
  2. import argparse
  3. import os
  4. import sys
  5. import logging
  6. from random import seed
  7. from sandbox.tile.simulation.subject import Man
  8. synergine2_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../'))
  9. sys.path.append(synergine2_path)
  10. from sandbox.tile.simulation.base import TileStrategySimulation
  11. from sandbox.tile.simulation.base import TileStrategySubjects
  12. from synergine2.log import get_default_logger
  13. from synergine2.config import Config
  14. from sandbox.tile.terminal.base import CocosTerminal
  15. from synergine2.core import Core
  16. from synergine2.cycle import CycleManager
  17. from synergine2.terminals import TerminalManager
  18. def main(map_dir_path: str, seed_value: int=42):
  19. seed(seed_value)
  20. config = Config()
  21. config.load_files(['sandbox/engulf/config.yaml'])
  22. logger = get_default_logger(level=logging.ERROR)
  23. simulation = TileStrategySimulation(config)
  24. subjects = TileStrategySubjects(simulation=simulation)
  25. for position in ((0, 0), (5, 3), (10, 6)):
  26. man = Man(
  27. config=config,
  28. simulation=simulation,
  29. position=position,
  30. )
  31. subjects.append(man)
  32. simulation.subjects = subjects
  33. core = Core(
  34. config=config,
  35. logger=logger,
  36. simulation=simulation,
  37. cycle_manager=CycleManager(
  38. config=config,
  39. logger=logger,
  40. simulation=simulation,
  41. ),
  42. terminal_manager=TerminalManager(
  43. config=config,
  44. logger=logger,
  45. terminals=[CocosTerminal(
  46. config,
  47. logger,
  48. asynchronous=False,
  49. map_dir_path=map_dir_path,
  50. )]
  51. ),
  52. cycles_per_seconds=1 / config.core.cycle_duration,
  53. )
  54. core.run()
  55. if __name__ == '__main__':
  56. parser = argparse.ArgumentParser(description='Run TileStrategy')
  57. parser.add_argument('map_dir_path', help='map directory path')
  58. parser.add_argument('--seed', dest='seed', default=42)
  59. args = parser.parse_args()
  60. main(args.map_dir_path, seed_value=args.seed)