run.py 2.3KB

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