-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
83 lines (70 loc) · 2.43 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import random
import sys
from os import path
from pathlib import Path
from typing import List
from sc2 import maps
from sc2.data import AIBuild, Difficulty, Race
from sc2.main import run_game
from sc2.player import Bot, Computer
sys.path.append("ares-sc2/src/ares")
sys.path.append("ares-sc2/src")
sys.path.append("ares-sc2")
import yaml
from bot.main import MyBot
from ladder import run_ladder_game
# change if non default setup / linux
# if having issues with this, modify `map_list` below manually
MAPS_PATH: str = "C:\\Program Files (x86)\\StarCraft II\\Maps"
CONFIG_FILE: str = "config.yml"
MAP_FILE_EXT: str = "SC2Map"
MY_BOT_NAME: str = "MyBotName"
MY_BOT_RACE: str = "MyBotRace"
def main():
bot_name: str = "MyBot"
race: Race = Race.Random
__user_config_location__: str = path.abspath(".")
user_config_path: str = path.join(__user_config_location__, CONFIG_FILE)
# attempt to get race and bot name from config file if they exist
if path.isfile(user_config_path):
with open(user_config_path) as config_file:
config: dict = yaml.safe_load(config_file)
if MY_BOT_NAME in config:
bot_name = config[MY_BOT_NAME]
if MY_BOT_RACE in config:
race = Race[config[MY_BOT_RACE].title()]
bot1 = Bot(race, MyBot(), bot_name)
if "--LadderServer" in sys.argv:
# Ladder game started by LadderManager
print("Starting ladder game...")
result, opponentid = run_ladder_game(bot1)
print(result, " against opponent ", opponentid)
else:
# Local game
map_list: List[str] = [
p.name.replace(f".{MAP_FILE_EXT}", "")
for p in Path(MAPS_PATH).glob(f"*.{MAP_FILE_EXT}")
if p.is_file()
]
# alternative example code if finding the map path is problematic
# map_list: List[str] = [
# "BerlingradAIE",
# "InsideAndOutAIE",
# "MoondanceAIE",
# "StargazersAIE",
# "WaterfallAIE",
# "HardwireAIE",
# ]
random_race = random.choice([Race.Zerg, Race.Terran, Race.Protoss])
print("Starting local game...")
run_game(
maps.get(random.choice(map_list)),
[
bot1,
Computer(random_race, Difficulty.CheatVision, ai_build=AIBuild.Macro),
],
realtime=False,
)
# Start game
if __name__ == "__main__":
main()