generated from AresSC2/ares-sc2-bot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
109 lines (94 loc) · 3.41 KB
/
run.py
File metadata and controls
109 lines (94 loc) · 3.41 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import platform
import random
import sys
from os import path
from pathlib import Path
from typing import List
from loguru import logger
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
plt = platform.system()
# change if non default setup / linux
# if having issues with this, modify `map_list` below manually
if plt == "Windows":
MAPS_PATH: str = "C:\\Program Files (x86)\\StarCraft II\\Maps"
elif plt == "Darwin":
MAPS_PATH: str = "/Applications/StarCraft II/Maps"
elif plt == "Linux":
# path would look a bit like this on linux after installing
# SC2 via lutris
MAPS_PATH: str = (
"~/<username>/Games/battlenet/drive_c/Program Files (x86)/StarCraft II/Maps"
)
else:
logger.error(f"{plt} not supported")
sys.exit()
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()
]
if len(map_list) == 0:
logger.error(f"Can't find maps, please check `MAPS_PATH` in `run.py'")
logger.info("Trying back up option")
logger.info(
f"\nLooking for maps in {MAPS_PATH} but didn't find anything. \n"
f"If this path is correct please ensure maps are present. \n"
f"If this path is incorrect please edit the `MAPS_PATH` in `run.py` \n"
f"Tip: If you're using linux, MAPS_PATH will definitely need updating\n"
)
# see if user has any recent ladder maps
map_list: List[str] = [
"PylonAIE_v4",
"PersephoneAIE_v4",
"TorchesAIE_v4",
"IncorporealAIE_v4",
"MagannathaAIE_v2",
"UltraloveAIE_v2"
]
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.VeryHard, ai_build=AIBuild.Macro),
],
realtime=False,
)
# Start game
if __name__ == "__main__":
main()