Endgame-Analyzer/src/check_games.cpp

52 lines
2.6 KiB
C++

#include <iostream>
#include "game_state.h"
#include "download.h"
void check_games(unsigned num_players, unsigned max_draw_pile_size, unsigned first_game = 0, unsigned last_game = 9999) {
std::vector<std::vector<Hanabi::probability_t>> winning_percentages(last_game + 2);
for(size_t draw_pile_size = 0; draw_pile_size <= max_draw_pile_size; draw_pile_size++) {
Hanabi::probability_t total_chance = 0;
const std::string output_fname = "games_" + std::to_string(num_players) + "p_draw_size_" + std::to_string(draw_pile_size) + ".txt";
std::ofstream file (output_fname);
for(size_t game_id = first_game; game_id <= last_game; game_id++) {
const std::string input_fname = "json/" + std::to_string(num_players) + "p/" + std::to_string(game_id) + ".json";
auto game = Download::get_game(input_fname.c_str(), 50, draw_pile_size);
const Hanabi::probability_t chance = game->evaluate_state();
winning_percentages[game_id].push_back(chance);
if(chance != 1) {
file << "Game " << game_id << ": " << chance << std::endl;
file << *game << std::endl << std::endl;
}
std::cout << "Finished game " << game_id << " with draw pile size " << draw_pile_size << ": " << chance << std::endl;
total_chance += chance;
}
const Hanabi::probability_t total_average = total_chance / (last_game - first_game + 1);
winning_percentages.back().push_back(total_average);
file << "Total chance found over " << last_game - first_game + 1 << " many games: " << total_average << std::endl;
file.close();
}
const std::string results_file_name {"results_" + std::to_string(num_players) + "p.txt"};
std::ofstream results_file (results_file_name);
results_file << "game_id, ";
for(size_t draw_pile_size = 0; draw_pile_size <= max_draw_pile_size; draw_pile_size++) {
results_file << std::to_string(draw_pile_size) << ", ";
}
results_file << "\n";
for(size_t game_id = first_game; game_id <= last_game; game_id++) {
results_file << game_id << ", ";
for(size_t draw_pile_size = 0; draw_pile_size <= max_draw_pile_size; draw_pile_size++) {
results_file << winning_percentages[game_id][draw_pile_size] << ", ";
}
results_file << std::endl;
}
results_file << "total, ";
for(size_t draw_pile_size = 0; draw_pile_size <= max_draw_pile_size; draw_pile_size++) {
results_file << winning_percentages.back()[draw_pile_size] << ", ";
}
results_file << std::endl;
results_file.close();
}