From 00de4082c38cc2e9e01dfc4ca6a8308a74c5d779 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 8 Apr 2019 19:56:44 +0100 Subject: Enable reading deal seeds from a file --- metasol.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'metasol.cpp') 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> 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; -- cgit v1.2.1