-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathBotConfig.cpp
146 lines (130 loc) · 6.22 KB
/
BotConfig.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "BotConfig.h"
#include "JSONTools.h"
#include <iostream>
BotConfig::BotConfig()
{
ConfigFileFound = true;
ConfigFileParsed = true;
ConfigFileLocation = "BotConfig.txt";
BotName = "UAlbertaBot";
Authors = "Dave Churchill";
PrintInfoOnStart = false;
StrategyName = "Protoss_ZealotRush";
ReadDir = "read/";
WriteDir = "write/";
UseEnemySpecificStrategy = false;
FoundEnemySpecificStrategy = false;
UsingAutoObserver = false;
SetLocalSpeed = 10;
SetFrameSkip = 0;
UserInput = true;
CompleteMapInformation = false;
DrawGameInfo = true;
DrawProductionInfo = true;
DrawTileInfo = false;
DrawWalkableSectors = false;
DrawScoutInfo = false;
DrawResourceInfo = false;
DrawWorkerInfo = false;
DrawModuleTimers = false;
DrawReservedBuildingTiles = false;
DrawBuildingInfo = false;
DrawEnemyUnitInfo = false;
DrawLastSeenTileInfo = false;
DrawUnitTargetInfo = false;
DrawSquadInfo = false;
KiteWithRangedUnits = true;
ScoutHarassEnemy = true;
ColorLineTarget = CCColor(255, 255, 255);
ColorLineMineral = CCColor(0, 128, 128);
ColorUnitNearEnemy = CCColor(255, 0, 0);
ColorUnitNotNearEnemy = CCColor(0, 255, 0);
WorkersPerRefinery = 3;
BuildingSpacing = 1;
PylonSpacing = 3;
}
void BotConfig::readConfigFile()
{
std::string config = JSONTools::ReadFile(ConfigFileLocation);
if (config.length() == 0)
{
std::cerr << "Error: Config File Not Found or is Empty\n";
std::cerr << "Config Filename: " << ConfigFileLocation << "\n";
std::cerr << "The bot will not run without its configuration file\n";
std::cerr << "Please check that the file exists and is not empty. Incomplete paths are relative to the bot .exe file\n";
std::cerr << "You can change the config file location in Config::ConfigFile::ConfigFileLocation\n";
ConfigFileFound = false;
return;
}
std::ifstream file(ConfigFileLocation);
json j;
file >> j;
/*if (parsingFailed)
{
std::cerr << "Error: Config File Found, but could not be parsed\n";
std::cerr << "Config Filename: " << ConfigFileLocation << "\n";
std::cerr << "The bot will not run without its configuration file\n";
std::cerr << "Please check that the file exists, is not empty, and is valid JSON. Incomplete paths are relative to the bot .exe file\n";
std::cerr << "You can change the config file location in Config::ConfigFile::ConfigFileLocation\n";
ConfigFileParsed = false;
return;
}*/
// Parse the Bot Info
if (j.count("Bot Info") && j["Bot Info"].is_object())
{
const json & info = j["Bot Info"];
JSONTools::ReadString("BotName", info, BotName);
JSONTools::ReadString("Authors", info, Authors);
JSONTools::ReadBool("PrintInfoOnStart", info, PrintInfoOnStart);
}
// Parse the Micro Options
if (j.count("Micro") && j["Micro"].is_object())
{
const json & micro = j["Micro"];
JSONTools::ReadBool("KiteWithRangedUnits", micro, KiteWithRangedUnits);
JSONTools::ReadBool("ScoutHarassEnemy", micro, ScoutHarassEnemy);
}
// Parse the BWAPI Options
if (j.count("BWAPI") && j["BWAPI"].is_object())
{
const json & bwapi = j["BWAPI"];
JSONTools::ReadInt("SetLocalSpeed", bwapi, SetLocalSpeed);
JSONTools::ReadInt("SetFrameSkip", bwapi, SetFrameSkip);
JSONTools::ReadBool("UserInput", bwapi, UserInput);
JSONTools::ReadBool("CompleteMapInformation", bwapi, CompleteMapInformation);
}
// Parse the Macro Options
if (j.count("Macro") && j["Macro"].is_object())
{
const json & macro = j["Macro"];
JSONTools::ReadInt("BuildingSpacing", macro, BuildingSpacing);
JSONTools::ReadInt("PylongSpacing", macro, PylonSpacing);
JSONTools::ReadInt("WorkersPerRefinery", macro, WorkersPerRefinery);
}
// Parse the Debug Options
if (j.count("Debug") && j["Debug"].is_object())
{
const json & debug = j["Debug"];
JSONTools::ReadBool("DrawGameInfo", debug, DrawGameInfo);
JSONTools::ReadBool("DrawTileInfo", debug, DrawTileInfo);
JSONTools::ReadBool("DrawBaseLocationInfo", debug, DrawBaseLocationInfo);
JSONTools::ReadBool("DrawWalkableSectors", debug, DrawWalkableSectors);
JSONTools::ReadBool("DrawResourceInfo", debug, DrawResourceInfo);
JSONTools::ReadBool("DrawWorkerInfo", debug, DrawWorkerInfo);
JSONTools::ReadBool("DrawProductionInfo", debug, DrawProductionInfo);
JSONTools::ReadBool("DrawScoutInfo", debug, DrawScoutInfo);
JSONTools::ReadBool("DrawSquadInfo", debug, DrawSquadInfo);
JSONTools::ReadBool("DrawBuildingInfo", debug, DrawBuildingInfo);
JSONTools::ReadBool("DrawModuleTimers", debug, DrawModuleTimers);
JSONTools::ReadBool("DrawEnemyUnitInfo", debug, DrawEnemyUnitInfo);
JSONTools::ReadBool("DrawLastSeenTileInfo", debug, DrawLastSeenTileInfo);
JSONTools::ReadBool("DrawUnitTargetInfo", debug, DrawUnitTargetInfo);
JSONTools::ReadBool("DrawReservedBuildingTiles",debug, DrawReservedBuildingTiles);
}
// Parse the Module Options
if (j.count("Modules") && j["Modules"].is_object())
{
const json & module = j["Modules"];
JSONTools::ReadBool("UseAutoObserver", module, UsingAutoObserver);
}
}