Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BuildOrderTrackerClass::recordWinningBuild(bool isWinner)
- {
- ofstream config("bwapi-data/write/" + Broodwar->enemy()->getName() + ".txt", ios::trunc);
- string token;
- bool update;
- int offset = !isWinner;
- while (ss >> token)
- {
- if (update)
- {
- if (offset == 0)
- {
- update = false;
- config << stoi(token) + 1;
- continue;
- }
- else
- {
- offset--;
- }
- }
- if (token == currentBuild)
- {
- update = true;
- }
- config << token;
- }
- return;
- }
- void BuildOrderTrackerClass::loadConfig()
- {
- string build, buffer;
- int wins, losses, gamesPlayed;
- double best;
- ifstream config("bwapi-data/read/" + Broodwar->enemy()->getName() + ".txt");
- if (!config)
- {
- config.open("bwapi-data/write/" + Broodwar->enemy()->getName() + ".txt");
- }
- while (config >> buffer)
- {
- ss << buffer << " ";
- }
- stringstream ss2;
- ss2 << ss.rdbuf();
- while (!ss2.eof())
- {
- ss2 >> build >> wins >> losses;
- gamesPlayed += wins + losses;
- }
- ss2 << ss.rdbuf();
- while (!ss2.eof())
- {
- ss2 >> build >> wins >> losses;
- if ((wins + losses) <= 0)
- {
- currentBuild = build;
- return;
- }
- else
- {
- double winRate = gamesPlayed > 0 ? wins / static_cast<double>(gamesPlayed) : 0;
- double ucbVal = 0.5 * sqrt(log((double)gamesPlayed / gamesPlayed));
- double val = winRate + ucbVal;
- if (val > best)
- {
- best = val;
- currentBuild = build;
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement