run.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # coding: utf-8
  2. import argparse
  3. import logging
  4. from random import seed
  5. from synergine2.log import get_default_logger
  6. from synergine2.config import Config
  7. from synergine2_cocos2d.const import SELECTION_COLOR_RGB
  8. from synergine2_cocos2d.util import get_map_file_path_from_dir
  9. from synergine2.core import Core
  10. from synergine2.cycle import CycleManager
  11. from synergine2.terminals import TerminalManager
  12. from opencc.const import FLAG, SIDE
  13. from opencc.const import FLAG_DE
  14. from opencc.const import DE_COLOR
  15. from opencc.const import URSS_COLOR
  16. from opencc.const import FLAG_URSS
  17. from opencc.simulation.subject import TileSubject
  18. from opencc.simulation.base import TileStrategySimulation
  19. from opencc.simulation.base import TileStrategySubjects
  20. from opencc.terminal.base import CocosTerminal
  21. def main(map_dir_path: str, seed_value: int=None):
  22. if seed_value is not None:
  23. seed(seed_value)
  24. config = Config()
  25. config.load_yaml('config.yaml')
  26. logger = get_default_logger(level=logging.ERROR)
  27. map_file_path = get_map_file_path_from_dir(map_dir_path)
  28. simulation = TileStrategySimulation(config, map_file_path=map_file_path)
  29. subjects = TileStrategySubjects(simulation=simulation)
  30. for position in ((10, 2), (11, 3), (11, 4), (12, 5),):
  31. man = TileSubject(
  32. config=config,
  33. simulation=simulation,
  34. position=position,
  35. properties={
  36. SELECTION_COLOR_RGB: DE_COLOR,
  37. FLAG: FLAG_DE,
  38. SIDE: 'AXIS',
  39. }
  40. )
  41. subjects.append(man)
  42. for position in ((30, 15), (31, 16), (32, 17), (33, 18),):
  43. man = TileSubject(
  44. config=config,
  45. simulation=simulation,
  46. position=position,
  47. properties={
  48. SELECTION_COLOR_RGB: URSS_COLOR,
  49. FLAG: FLAG_URSS,
  50. SIDE: 'ALLIES',
  51. }
  52. )
  53. subjects.append(man)
  54. simulation.subjects = subjects
  55. core = Core(
  56. config=config,
  57. logger=logger,
  58. simulation=simulation,
  59. cycle_manager=CycleManager(
  60. config=config,
  61. logger=logger,
  62. simulation=simulation,
  63. ),
  64. terminal_manager=TerminalManager(
  65. config=config,
  66. logger=logger,
  67. terminals=[CocosTerminal(
  68. config,
  69. logger,
  70. asynchronous=False,
  71. map_dir_path=map_dir_path,
  72. )]
  73. ),
  74. cycles_per_seconds=1 / config.resolve('core.cycle_duration'),
  75. )
  76. core.run()
  77. if __name__ == '__main__':
  78. parser = argparse.ArgumentParser(description='Run TileStrategy')
  79. parser.add_argument('map_dir_path', help='map directory path')
  80. parser.add_argument('--seed', dest='seed', default=None)
  81. args = parser.parse_args()
  82. main(args.map_dir_path, seed_value=args.seed)