ThrowParams PlayerBestRandom::chooseParams(const Game & game) { int nbTries = _params["nbTries"]; ThrowParams bestParams = PlayerRandom::chooseParams(game); player_t currentPlayer = game.getCurrentPlayer(); for (int i=1; i<nbTries; i++) { ThrowParams testParams = PlayerRandom::chooseParams(game); Game testGame(game); testGame.throwBall(testParams); GameResult result = testGame.computeResult(); if (result._winningPlayer == currentPlayer) bestParams = testParams; // TODO test other reward policy (nb winning balls, min distance...) #ifdef LOG std::cout << testParams; if (result._winningPlayer == currentPlayer) { const BallResult & br = result._ballResults.front(); std::cout << " better" << " " << br._position << " " << std::setprecision(4) << br._distanceToJack; } std::cout << std::endl; #endif } return bestParams; }
int main() { printf("Block game generator.\n"); srandom(time(NULL)); testGame(); evaluateGame(); while (1) { createGame(); evaluateGame(); } return 0; }
int main() { Quackle::DataManager dataManager; dataManager.setAppDataDirectory("data"); dataManager.lexiconParameters()->loadDawg(Quackle::LexiconParameters::findDictionaryFile("twl06.dawg")); dataManager.lexiconParameters()->loadGaddag(Quackle::LexiconParameters::findDictionaryFile("twl06.gaddag")); dataManager.strategyParameters()->initialize("twl06"); dataManager.setBoardParameters(new Quackle::EnglishBoard()); const bool seedRandoms = false; if (seedRandoms) dataManager.seedRandomNumbers('E' + 'm' + 'i' + 'l' + 'y' + 'Y' + 'K' + 'o'); const int gameCnt = 1000; //const int gameCnt = 1; for (int game = 0; game < gameCnt; ++game) { testGame(); } return 0; }
static void detectGames(const Common::FSList &fslist, Common::List<DetectorResult> &results, const char *gameid) { DescMap fileMD5Map; DetectorResult dr; // Dive one level down since mac indy3/loom has its files split into directories. See Bug #1438631 composeFileHashMap(fslist, fileMD5Map, 2, directoryGlobs); // Iterate over all filename patterns. for (const GameFilenamePattern *gfp = gameFilenamesTable; gfp->gameid; ++gfp) { // If a gameid was specified, we only try to detect that specific game, // so we can just skip over everything with a differing gameid. if (gameid && scumm_stricmp(gameid, gfp->gameid)) continue; // Generate the detectname corresponding to the gfp. If the file doesn't // exist in the directory we are looking at, we can skip to the next // one immediately. Common::String file(generateFilenameForDetection(gfp->pattern, gfp->genMethod)); if (!fileMD5Map.contains(file)) continue; // Reset the DetectorResult variable dr.fp.pattern = gfp->pattern; dr.fp.genMethod = gfp->genMethod; dr.game.gameid = 0; dr.language = gfp->language; dr.md5.clear(); dr.extra = 0; // ____ _ _ // | _ \ __ _ _ __| |_ / | // | |_) / _` | '__| __| | | // | __/ (_| | | | |_ | | // |_| \__,_|_| \__| |_| // // PART 1: Trying to find an exact match using MD5. // // // Background: We found a valid detection file. Check if its MD5 // checksum occurs in our MD5 table. If it does, try to use that // to find an exact match. // // We only do that if the MD5 hadn't already been computed (since // we may look at some detection files multiple times). // DetectorDesc &d = fileMD5Map[file]; if (d.md5.empty()) { Common::SeekableReadStream *tmp = 0; bool isDiskImg = (file.hasSuffix(".d64") || file.hasSuffix(".dsk") || file.hasSuffix(".prg")); if (isDiskImg) { tmp = openDiskImage(d.node, gfp); debug(2, "Falling back to disk-based detection"); } else { tmp = d.node.createReadStream(); } Common::String md5str; if (tmp) md5str = computeStreamMD5AsString(*tmp, kMD5FileSizeLimit); if (!md5str.empty()) { d.md5 = md5str; d.md5Entry = findInMD5Table(md5str.c_str()); dr.md5 = d.md5; if (d.md5Entry) { // Exact match found. Compute the precise game settings. computeGameSettingsFromMD5(fslist, gfp, d.md5Entry, dr); // Print some debug info int filesize = tmp->size(); if (d.md5Entry->filesize != filesize) debug(1, "SCUMM detector found matching file '%s' with MD5 %s, size %d\n", file.c_str(), md5str.c_str(), filesize); // Sanity check: We *should* have found a matching gameid / variant at this point. // If not, then there's a bug in our data tables... assert(dr.game.gameid != 0); // Add it to the list of detected games results.push_back(dr); } } if (isDiskImg) closeDiskImage((ScummDiskImage*)tmp); delete tmp; } // If an exact match for this file has already been found, don't bother // looking at it anymore. if (d.md5Entry) continue; // ____ _ ____ // | _ \ __ _ _ __| |_ |___ \ * // | |_) / _` | '__| __| __) | // | __/ (_| | | | |_ / __/ // |_| \__,_|_| \__| |_____| // // PART 2: Fuzzy matching for files with unknown MD5. // // We loop over the game variants matching the gameid associated to // the gfp record. We then try to decide for each whether it could be // appropriate or not. dr.md5 = d.md5; for (const GameSettings *g = gameVariantsTable; g->gameid; ++g) { // Skip over entries with a different gameid. if (g->gameid[0] == 0 || scumm_stricmp(gfp->gameid, g->gameid)) continue; dr.game = *g; dr.extra = g->variant; // FIXME: We (ab)use 'variant' for the 'extra' description for now. if (gfp->platform != Common::kPlatformUnknown) dr.game.platform = gfp->platform; // If a variant has been specified, use that! if (gfp->variant) { if (!scumm_stricmp(gfp->variant, g->variant)) { // perfect match found results.push_back(dr); break; } continue; } // HACK: Perhaps it is some modified translation? dr.language = detectLanguage(fslist, g->id); // Add the game/variant to the candidates list if it is consistent // with the file(s) we are seeing. if (testGame(g, fileMD5Map, file)) results.push_back(dr); } } }