int main() { HashTable table; //KEEP all roster data from roster file to "rosterData" vector<RosterInfo> rosterData; InputRosterData(rosterData); // Open bet file, get bet data vector<Bet> betData; //keep bet data InputBetData(betData); //Open match file ifstream infile; string matchFileName; cout << "Match file (no .txt): "; cin >> matchFileName; matchFileName += ".txt"; infile.open(matchFileName.c_str()); if (!infile.is_open()) { cerr << "Cannot open match file." << endl; return 0; } //Feature: add unknown team automatically or manually? //autoAdd = true -- automatically, false -- manually bool autoAdd = SetAutoAdd(); ofstream outFile("track_bet.txt"); //RUN through matches int rosterInfoIdx = 0; int betIdx = 0; double profit = 0.0; string line; getline(infile, line); while (infile.good()) { Match matchtemp(line); cout << "line: " << line << endl; //if roster date == match date --> AdjustNumPlay while (rosterInfoIdx < rosterData.size() && rosterData.at(rosterInfoIdx).Date() == matchtemp.Date()) { table.Search(rosterData.at(rosterInfoIdx).Team())->AdjustNumPlay(); rosterInfoIdx++; } // Perform bet while (betIdx < betData.size() && betData.at(betIdx).Date() == matchtemp.Date()) { profit += betData.at(betIdx).PerformBet(table, outFile); betIdx++; } UpdateRatingHelper(table, matchtemp, autoAdd); //UpdateRating! getline(infile, line); } outFile << profit; infile.close(); outFile.close(); return 0; }
double Bet::PerformBet(const HashTable& table, ostream& fileStream) { Team* tAptr = table.Search(teamA); //use method Search of HashTable class Team* tBptr = table.Search(teamB); double result = 0.0; if (tAptr != NULL && tBptr != NULL) { double expectedA, expectedB; CalCulateExpectedScore(tAptr, tBptr, expectedA, expectedB); //calculate expected score fileStream << date << "," << teamA << " - " << teamB << ",BO" << format << "," << expectedA << " - " << expectedB << "," << oddA << " - " << 1-oddA << ","; if (tAptr->NumPlay() >= 100 && tBptr->NumPlay() >= 100) { if (KellyBetSize(expectedA, oddA, format) > 0.01) { fileStream << teamA; switch (winner) { case 'a': result = KellyBetSize(expectedA, oddA, format) * ( (1-oddA)/oddA ) * 10; case 'b': result = -KellyBetSize(expectedA, oddA, format) * 10; } } else if (KellyBetSize(expectedB, 1-oddA, format) > 0.01) { fileStream << teamB; switch (winner) { case 'a': result = -KellyBetSize(expectedB, 1-oddA, format) * 10; case 'b': result = KellyBetSize(expectedB, 1-oddA, format) * ( oddA/(1-oddA) ) * 10; } } } fileStream << "," << result << endl; } return result; }
int main() { int d = 11; HashTable<int, int> *ht = new HashTable<int, int>(d); int a[] = {83, 14, 29, 70, 10, 55, 72, 45, 11, 67, 90, 24, 3, 72, 46}; int length = sizeof(a)/sizeof(a[0]); for(int i = 0; i < length; i++) { cout << "Inserting " << a[i] << "... "; cout << (ht->Insert(a[i]) ? " Done.\n" : ""); } for(int i = 0; i < length; i++) { int s = a[i]; cout << "Searching for " << s << "..." << endl; cout << (ht->Search(s, s) ? "Found " : "Could not find " ) << s << "." << endl; } return 0; }