run.py 3.2KB

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