run.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 opencombat.const import FLAG, SIDE
  13. from opencombat.const import FLAG_DE
  14. from opencombat.const import DE_COLOR
  15. from opencombat.const import URSS_COLOR
  16. from opencombat.const import FLAG_URSS
  17. from opencombat.simulation.subject import TileSubject
  18. from opencombat.simulation.base import TileStrategySimulation
  19. from opencombat.simulation.base import TileStrategySubjects
  20. from opencombat.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. level = logging.getLevelName(config.resolve('global.logging_level', 'ERROR'))
  27. logger = get_default_logger(level=level)
  28. map_file_path = get_map_file_path_from_dir(map_dir_path)
  29. simulation = TileStrategySimulation(config, map_file_path=map_file_path)
  30. subjects = TileStrategySubjects(simulation=simulation)
  31. for position in ((10, 2), (11, 3), (11, 4), (12, 5),):
  32. man = TileSubject(
  33. config=config,
  34. simulation=simulation,
  35. position=position,
  36. properties={
  37. SELECTION_COLOR_RGB: DE_COLOR,
  38. FLAG: FLAG_DE,
  39. SIDE: 'AXIS',
  40. }
  41. )
  42. subjects.append(man)
  43. for position in ((30, 15), (31, 16), (32, 17), (33, 18),):
  44. man = TileSubject(
  45. config=config,
  46. simulation=simulation,
  47. position=position,
  48. properties={
  49. SELECTION_COLOR_RGB: URSS_COLOR,
  50. FLAG: FLAG_URSS,
  51. SIDE: 'ALLIES',
  52. }
  53. )
  54. subjects.append(man)
  55. simulation.subjects = subjects
  56. core = Core(
  57. config=config,
  58. simulation=simulation,
  59. cycle_manager=CycleManager(
  60. config=config,
  61. simulation=simulation,
  62. ),
  63. terminal_manager=TerminalManager(
  64. config=config,
  65. terminals=[CocosTerminal(
  66. config,
  67. asynchronous=False,
  68. map_dir_path=map_dir_path,
  69. )]
  70. ),
  71. cycles_per_seconds=1 / config.resolve('core.cycle_duration'),
  72. )
  73. core.run()
  74. if __name__ == '__main__':
  75. parser = argparse.ArgumentParser(description='Run TileStrategy')
  76. parser.add_argument('map_dir_path', help='map directory path')
  77. parser.add_argument('--seed', dest='seed', default=None)
  78. args = parser.parse_args()
  79. main(args.map_dir_path, seed_value=args.seed)