void OpponentModeller::create(string filename) { char* fn = Util::sToC(filename); _db = new Database(fn); // Check to see if DB Exists. If it does, then we are already connected. If not, create it. //if (!_db->open(fn)) //_db->query("CREATE TABLE PlayerModel ( id INTEGER PRIMARY KEY NOT NULL, hand text, player_type INTEGER );"); delete [] fn; // Session 1 example: // Create a session; Reference that session in creating the players; // Insert into Session the session number // Insert into Player the players in the session // Insert Values into Hand with player number, hand // At the end of the game, alter the players to add in turnCount(turns_participated), play_percentage(playCount), passPercentage(turnCount-playCount), win_percentage(winCount / turnCount * 100), loss_percentage (100-win_percentage); // CHANGE: Move Win/Loss count to Session // CREATE TABLE Player ( player_id INTEGER PRIMARY KEY NOT NULL, session_id INTEGER, player_type INTEGER, turns_participated INTEGER, play_percentage DOUBLE, pass_percentage DOUBLE, FOREIGN KEY(session_id) REFERENCES Session ); _db->query("CREATE TABLE IF NOT EXISTS Player ( player_id INTEGER PRIMARY KEY NOT NULL, session_id INTEGER, player_type INTEGER, turns_participated INTEGER, play_percentage DOUBLE, pass_percentage DOUBLE, FOREIGN KEY(session_id) REFERENCES Session );"); // CREATE TABLE Session ( session_id INTEGER PRIMARY KEY NOT NULL, num_players INTEGER, session_winner INTEGER ); _db->query("CREATE TABLE IF NOT EXISTS Session ( session_id INTEGER PRIMARY KEY NOT NULL, num_players INTEGER, session_winner INTEGER );"); // CREATE TABLE Hand ( hand_id INTEGER PRIMARY KEY NOT NULL, player_id INTEGER FOREIGN KEY REFERENCES Player (player_id), hand TEXT, hand_type INTEGER ); _db->query("CREATE TABLE IF NOT EXISTS Hand ( hand_id INTEGER PRIMARY KEY NOT NULL, player_id INTEGER, hand TEXT, hand_type INTEGER, is_winning_hand INTEGER, FOREIGN KEY(player_id) REFERENCES Player);"); // CREATE TABLE ActionUtilities ( action_id INTEGER PRIMARY KEY NOT NULL, action_a_util DOUBLE, action_b_util DOUBLE, action_c_util DOUBLE, action_d_util DOUBLE, action_e_util DOUBLE, action_f_util DOUBLE, action_g_util DOUBLE, action_h_util DOUBLE, action_i_util DOUBLE ); _db->query("CREATE TABLE IF NOT EXISTS ActionUtilities ( action_id INTEGER PRIMARY KEY NOT NULL, action_a_util DOUBLE, action_b_util DOUBLE, action_c_util DOUBLE, action_d_util DOUBLE, action_e_util DOUBLE, action_f_util DOUBLE, action_g_util DOUBLE, action_h_util DOUBLE, action_i_util DOUBLE );"); createUtilities(); }
int main(int argc, const char * argv[]) { printVersion(); // check number of arguments and if all arguments can be read if (argc < 3 || !readArguments(argc, argv)) { printUsage(); return -1; } // check if the input path exist if (!FS_NAMESPACE::exists(inFilePath)) { std::cout << "Error: Invalid input file/directory \"" << inFilePath.string() << "\"!" << std::endl; return -2; } if (createBinary) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -b is used!" << std::endl; return -2; } } else if (appendFile) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -a is used!" << std::endl; return -2; } } else if (FS_NAMESPACE::is_directory(inFilePath) != FS_NAMESPACE::is_directory(outFilePath)) { // check if output directory exists if (FS_NAMESPACE::is_directory(outFilePath) && !FS_NAMESPACE::exists(outFilePath)) { std::cout << "Error: Invalid output directory \"" << outFilePath.string() << "\"!" << std::endl; return -2; } // check if arguments 1 and 2 are both files or both directories std::cout << "Error: Input and output file must be both either a file or a directory!" << std::endl; return -2; } if (appendFile) { // append file a to b if (!appendAtoB(outFilePath, inFilePath)) { std::cout << "Error: Failed to append data to executable!" << std::endl; return -3; } } else { // build list of files to process std::vector<FileData> fileList; if (FS_NAMESPACE::is_directory(inFilePath) && FS_NAMESPACE::is_directory(inFilePath)) { // both files are directories, build file ist fileList = getFileDataFrom(inFilePath, outFilePath, inFilePath, useRecursion); if (fileList.empty()) { std::cout << "Error: No files to convert!" << std::endl; return -3; } } else { // just add single input/output file FileData temp; temp.inPath = inFilePath; temp.outPath = outFilePath; temp.internalName = inFilePath.filename().string(); // remove all, but the file name and extension if (beVerbose) { std::cout << "Found input file " << inFilePath << std::endl; std::cout << "Internal name will be \"" << temp.internalName << "\"" << std::endl; std::cout << "Output path is " << temp.outPath << std::endl; } // get file size try { temp.size = static_cast<uint64_t>(FS_NAMESPACE::file_size(inFilePath)); if (beVerbose) { std::cout << "Size is " << temp.size << " bytes." << std::endl; } } catch (...) { std::cout << "Error: Failed to get size of " << inFilePath << "!" << std::endl; temp.size = 0; } fileList.push_back(temp); } // does the user want an binary file? if (createBinary) { // yes. build it. if (!createBlob(fileList, outFilePath)) { std::cout << "Error: Failed to convert to binary file!" << std::endl; return -4; } } else { // no. convert files to .c/.cpp. loop through list, converting files for (auto fdIt = fileList.begin(); fdIt != fileList.cend(); ++fdIt) { if (!convertFile(*fdIt, commonHeaderFilePath)) { std::cout << "Error: Failed to convert all files. Aborting!" << std::endl; return -4; } } // do we need to write a header file? if (!commonHeaderFilePath.empty()) { if (!createCommonHeader(fileList, commonHeaderFilePath, !utilitiesFilePath.empty(), useC)) { return -5; } // do we need to create utilities? if (!utilitiesFilePath.empty()) { if (!createUtilities(fileList, utilitiesFilePath, commonHeaderFilePath, useC, combineResults)) { return -6; } } } } } // if (!appendFile) { // profit!!! std::cout << "res2h succeeded." << std::endl; return 0; }