11 #include "fmt/format.h" 14 #include <cereal/archives/json.hpp> 15 #include <cereal/types/memory.hpp> 16 #include <cereal/types/polymorphic.hpp> 17 #include <cereal/types/vector.hpp> 22 static const std::string kBanditNone(
"none");
23 static const std::string kBanditRandom(
"random");
24 static const std::string kBanditUCB1(
"ucb1");
25 static const std::string kBanditUCB1Rolling(
"ucb1rolling");
26 static const std::string kBanditUCB1Exploit(
"ucb1exploit");
27 static const std::string kBanditThompson(
"thompson");
28 static const std::string kBanditThompsonRolling(
"thompsonrolling");
29 static const std::string kBanditExpMooRolling(
"expmoorolling");
40 CPI_ARG(
bool, validOpening) =
false;
43 CPI_ARG(
bool, validSwitch) =
false;
46 CPI_ARG(
bool, switchEnabled) =
true;
52 CPI_ARG(std::vector<tc::BW::Race>, ourRaces) = {tc::BW::Race::Zerg};
55 CPI_ARG(std::vector<tc::BW::Race>, enemyRaces) = {tc::BW::Race::Terran,
56 tc::BW::Race::Protoss,
58 tc::BW::Race::Unknown};
61 typedef std::unordered_map<std::string, BuildOrderConfig>
71 const std::string& rawOpponentName);
76 const std::unordered_map<std::string, BuildOrderConfig>& configs,
78 tc::BW::Race enemyRace);
91 void updateLastGame(
bool won);
93 return std::accumulate(wins_.begin(), wins_.end(), 0);
99 return numGames() - numWins();
102 return numGames() == 0 ? 0.0f :
static_cast<float>(numWins()) / numGames();
104 const std::vector<bool>&
wins()
const {
111 return fmt::format(
"{0}/{1}", numWins(), numGames());
113 template <
class Archive>
115 ar(CEREAL_NVP(wins_));
127 std::vector<bool> wins_;
141 std::string enemyName,
142 std::string readFolder =
"bwapi-data/read/",
143 std::string writeFolder =
"bwapi-data/write/");
150 void addStartingGame(std::string buildOrder);
156 void updateLastGameToVictory(std::string buildOrder);
163 void printStatus()
const;
174 return readFolder_ +
"/" + enemyName_ +
".json";
181 return writeFolder_ +
"/" + enemyName_ +
".json";
185 friend class cereal::access;
186 std::string enemyName_;
187 std::string readFolder_;
188 std::string writeFolder_;
204 float thompsonSamplingScore(
211 float thompsonRollingSamplingScore(
215 float thompson_gamma);
222 int allStrategyGamesCount,
226 float ucb1RollingScore(
228 int allStrategyGamesCount,
233 float expMooRollingSamplingScore(
242 float maxExploitScore(
244 int allStrategyGamesCount,
251 std::string chooseBuildOrder(
252 std::map<std::string, cherrypi::model::BuildOrderCount>
const&
254 std::string scoreAlgorithm,
BuildOrderConfigurations buildOrdersForTournament(const std::string &rawOpponentName)
Returns tournament-specific build order configurations given an opponent.
Definition: banditconfigurations.cpp:24
Defines a build order, from the standpoint of strategy selection.
Definition: bandit.h:38
float winRate() const
Definition: bandit.h:101
std::unordered_map< std::string, BuildOrderCount > buildOrderCounts
map from build order to its counts (number of played games, won games etc...)
Definition: bandit.h:167
int numLosses() const
Definition: bandit.h:98
BuildOrderConfig config
Configuration for the build, providing acceptable races and priors This is not serialized, because the configuration needs to be implemented in one and only one location (see buildOrderConfigurations).
Definition: bandit.h:124
std::string writeFilepath() const
Path to the file where the history is recorded (used as default if readFilepath() does not exists) ...
Definition: bandit.h:180
int numGames() const
Definition: bandit.h:95
void serialize(Archive &ar)
Definition: bandit.h:114
Handle on a vector of victory status for each game, giving easy access to relevant figures...
Definition: bandit.h:82
std::unordered_map< std::string, BuildOrderConfig > BuildOrderConfigurations
Definition: bandit.h:62
BuildOrderCount()
Definition: bandit.h:84
BuildOrderConfigurations buildOrdersForTraining()
Implements the default configuration of each build order This function needs to be modified in order ...
Definition: banditconfigurations.cpp:210
int numWins() const
Definition: bandit.h:92
std::string statusString() const
Returns a string of type "{numWins}/{numGames}" which is only useful for fast debugging and testing...
Definition: bandit.h:110
Class holding a playedGames vector for a given enemy.
Definition: bandit.h:138
void addGame(bool won)
Adds a value to the win history vector.
Definition: bandit.h:87
CPI_ARG(bool, validOpening)
Whether this build order can be used from the beginning of the game.
const std::vector< bool > & wins() const
Definition: bandit.h:104
Main namespace for bot-related code.
Definition: areainfo.cpp:17
std::vector< std::string > acceptableBuildOrders(const std::unordered_map< std::string, BuildOrderConfig > &configs, tc::BW::Race ourRace, tc::BW::Race enemyRace)
Returns a vector of acceptable build orders for fighting against a given race.
Definition: bandit.cpp:32
std::string readFilepath() const
Path to the file where the history is recorded Defaults to returning writeFilepath if readFilepath do...
Definition: bandit.h:173