Endgame-Analyzer/main.cpp

63 lines
No EOL
1.7 KiB
C++

//
// Created by maximilian on 7/13/23.
//
#include <boost/rational.hpp>
#include <cstdint>
#include <iostream>
#include <optional>
#include <vector>
#include "game_state.h"
#include "download.h"
#include "myassert.h"
namespace Hanabi {
void download(int game_id, int turn) {
auto game = Download::get_game(game_id, turn);
std::cout << "Analysing state: " << *game << std::endl;
auto res = game->backtrack(1);
std::cout.precision(10);
std::cout << "Probability with optimal play: " << res << std::endl;
std::cout << "Enumerated " << game->enumerated_states() << " states" << std::endl;
}
void print_sizes() {
std::cout << "size of card -> hand map: " << sizeof(HanabiState<5, 3, 4>)
<< std::endl;
unsigned exp = 32;
std::cout << "Pair size: " << sizeof(std::pair<std::uint32_t, float>)
<< std::endl;
std::cout << sizeof(boost::rational<int>) << std::endl;
std::cout << (1ul << exp) << std::endl;
}
void print_usage(const char* program_name) {
std::cout << "Usage: " << program_name << " GAME_ID TURN" << std::endl;
}
}
#define CHECK(test, condition) if (!(condition)) { std::cerr << "Test " << (test) << " failed." << std::endl; }
void test() {
{
auto game = Download::get_game("1005195", 43);
auto res = game->backtrack(1);
CHECK("1005195", res == static_cast<double>(7) / 8);
}
}
int main(int argc, char *argv[]) {
test();
if(argc == 3) {
std::string game (argv[1]);
std::string turn (argv[2]);
Hanabi::download(std::stoi(game), std::stoi(turn));
} else {
Hanabi::print_usage(argv[0]);
}
return 0;
}