diff options
| -rw-r--r-- | centre.cpp | 18 | ||||
| -rw-r--r-- | metasol.cpp | 37 | ||||
| -rw-r--r-- | metasol.hpp | 3 |
3 files changed, 55 insertions, 3 deletions
@@ -20,10 +20,12 @@ Usage: centre <rules_file> [options] Options: --dealseed SEED Specify a seed to use when randomly generating a game (set to 0 to use an unspecified seed). + --dealseedfile FILE Specify a list of seeds to use when randomly + generating games. -h --help Display this help. -f --forever Run forever, on as many games as possible. -g FILE --game FILE Specify a file describing a game-state. - --limitnodes Specify a limit to the number of nodes traversible by + --limitnodes NODES Specify a limit to the number of nodes traversible by a single run of Solvitaire (supercedes --limittime). --limittime MSECONDS Specify a time limit used for each individual run of Solvitaire, in milliseconds (superceded by @@ -309,6 +311,7 @@ typedef struct user_data { unsigned run_cache_size; uint64_t run_timeout; uint64_t run_node_limit; + const char *deal_seed_file; } user_data; void print_sgs(ms_game_state *gs, ms_rules *r) { @@ -1138,6 +1141,10 @@ ms_settings make_settings(std::map<std::string, docopt::value> &args, json_settings(&s, d, filename); } + if (args["--dealseedfile"]) { + d->deal_seed_file = args["--dealseedfile"].asString().c_str(); + } + if (args["--limitnodes"]) { d->run_node_limit = args["--limitnodes"].asLong(); } @@ -1170,9 +1177,14 @@ int main(int argc, char **argv) { if (s.forever) { return ms_run_many(&r, &s); } else { - ms_game_state gs = make_game_state(&r, args); ctpl::thread_pool tp(s.max_concurrent_threads); - return ms_run(&gs, &r, &s, &tp); + if (d.deal_seed_file) { + return ms_run_from_file(&r, &s, d.deal_seed_file, &tp); + } else { + ms_game_state gs = make_game_state(&r, args); + + return ms_run(&gs, &r, &s, &tp); + } } } diff --git a/metasol.cpp b/metasol.cpp index fa57ff4..daac9ad 100644 --- a/metasol.cpp +++ b/metasol.cpp @@ -939,6 +939,11 @@ int run_single(ms_rules *r, ms_settings *s, unsigned long seed, return ms_run(&gs, r, s, tp); } +int ms_run_id(int id, unsigned long seed, ms_rules *r, ms_settings *s, + ctpl::thread_pool *tp) { + return run_single(r, s, seed, tp); +} + int ms_run_single(ms_rules *r, ms_settings *s, unsigned long seed) { ctpl::thread_pool tp(s->max_concurrent_threads); return run_single(r, s, seed, &tp); @@ -981,6 +986,38 @@ int ms_run_many(ms_rules *r, ms_settings *s) { return 0; } +int ms_run_from_file(ms_rules *r, ms_settings *s, const char *filename, + ctpl::thread_pool *tp) { + + FILE *fp = fopen(filename, "r"); + char *line = NULL; + size_t len = 0; + ssize_t read; + std::vector<std::future<int>> fs; + + ctpl::thread_pool main_tp(s->max_concurrent_games); + + while ((read = getline(&line, &len, fp)) != EOF) { + unsigned long seed = strtoll(line, NULL, 0); + fs.push_back(main_tp.push(ms_run_id, seed, r, s, tp)); + } + + main_thread_pool = &main_tp; + + /* + * these will run forever, unless stopped by ^C + */ + for (auto &f : fs) { + assert(f.valid()); + f.wait(); + } + + fclose(fp); + free(line); + + return 0; +} + ms_rules fetch_default_rules() { ms_rules dr; diff --git a/metasol.hpp b/metasol.hpp index 69bf73c..573e741 100644 --- a/metasol.hpp +++ b/metasol.hpp @@ -862,4 +862,7 @@ int ms_run_single(ms_rules *rules, ms_settings *settings, unsigned long seed); */ int ms_run_many(ms_rules *rules, ms_settings *settings); +int ms_run_from_file(ms_rules *rules, ms_settings *settings, + const char *filename, ctpl::thread_pool *tp); + #endif /* METASOL_H */ |
