void MapDataReader::saveFile() { string filename = getWriteFilename(); ofstream outFile; outFile.open(filename.c_str()); if (!outFile) { Broodwar->printf("Unable to write data to %s", filename.c_str()); } else { for (int i = 0; i < (int)data.size(); i++) { stringstream s2; s2 << data.at(i).basePos.x(); s2 << " "; s2 << data.at(i).basePos.y(); s2 << " "; s2 << data.at(i).pos.x(); s2 << " "; s2 << data.at(i).pos.y(); s2 << " "; s2 << data.at(i).dist; s2 << "\n"; outFile << s2.str(); } outFile.close(); } }
void StrategySelector::saveStats() { if (!active) return; //Fill entries in stats file for combinations that have //not yet been played. string mapHash = Broodwar->mapHash(); string opponentRace = Broodwar->enemy()->getRace().getName(); string ownRace = Broodwar->self()->getRace().getName(); for (int i = 0; i < (int)strategies.size(); i++) { bool found = false; for (int s = 0; s < (int)stats.size(); s++) { if (strategies.at(i).strategyId == stats.at(s).strategyId && mapHash == stats.at(s).mapHash && opponentRace == stats.at(s).opponentRace) { //Matches found = true; break; } } if (!found) { //Only fill in the strategies for //the same race if (ownRace == strategies.at(i).race.getName()) { //Add entry StrategyStats s = StrategyStats(); s.mapHash = mapHash; s.mapName = Broodwar->mapFileName(); s.opponentRace = opponentRace; s.ownRace = strategies.at(i).race.getName(); s.strategyId = strategies.at(i).strategyId; stats.push_back(s); } } } //Save the file string filename = getWriteFilename(); ofstream outFile; outFile.open(filename.c_str()); if (!outFile) { Broodwar << "Error writing to stats file!" << endl; } else { for (int i = 0; i < (int)stats.size(); i++) { stringstream s2; s2 << stats.at(i).strategyId; s2 << ";"; s2 << stats.at(i).ownRace; s2 << ";"; s2 << stats.at(i).opponentRace; s2 << ";"; s2 << stats.at(i).won; s2 << ";"; s2 << stats.at(i).lost; s2 << ";"; s2 << stats.at(i).draw; s2 << ";"; s2 << stats.at(i).total; s2 << ";"; s2 << stats.at(i).mapName; s2 << ";"; s2 << stats.at(i).mapHash; s2 << ";\n"; outFile << s2.str(); } outFile.close(); } }