Endgame-Analyzer/main.cpp

72 lines
1.7 KiB
C++
Raw Normal View History

2023-08-04 16:28:41 +02:00
//
// 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"
2023-08-06 15:02:50 +02:00
#include "myassert.h"
2023-08-04 16:28:41 +02:00
namespace Hanabi {
2023-08-04 16:28:41 +02:00
void test_game() {
HanabiState<2, 2, 5> state;
2023-08-04 16:28:41 +02:00
state._stacks[0] = 2;
state._stacks[1] = 3;
Card r41 = {0, 4, 1};
2023-08-04 16:28:41 +02:00
state._draw_pile.push_back({r41, 1});
state._hands[0] = {y0, y1, y2, r0, r1};
state._hands[1] = {r1, r1, y1, r3, r2};
2023-08-06 14:06:41 +02:00
// state._card_positions[r1] = 0;
2023-08-06 11:54:57 +02:00
state._weighted_draw_pile_size = 1;
2023-08-04 16:28:41 +02:00
auto state2 = state;
auto a = state.play(4);
std::cout << state;
state.revert_play(a, false);
2023-08-04 16:28:41 +02:00
std::cout << state << std::endl;
std::cout << state2 << std::endl;
2023-08-06 15:02:50 +02:00
ASSERT(state._hands == state2._hands);
ASSERT(state._draw_pile == state2._draw_pile);
// ASSERT(state._card_positions == state2._card_positions);
ASSERT(state == state2);
2023-08-04 16:28:41 +02:00
}
2023-08-06 15:02:50 +02:00
void download(int turn) {
auto game = Download::get_game<6,5,4>("996518", turn);
2023-08-06 15:02:50 +02:00
std::cout << "Analysing state: " << game << std::endl;
2023-08-06 13:53:18 +02:00
auto res = game.backtrack(1);
std::cout << "Probability with optimal play: " << res << std::endl;
2023-08-06 15:02:50 +02:00
std::cout << "Enumerated " << game._enumerated_states << " states" << std::endl;
2023-08-06 11:54:57 +02:00
}
2023-08-04 16:28:41 +02:00
void print_sizes() {
std::cout << "size of card -> hand map: " << sizeof(HanabiState<5, 3, 4>)
<< std::endl;
2023-08-04 16:28:41 +02:00
unsigned exp = 32;
std::cout << "Pair size: " << sizeof(std::pair<std::uint32_t, float>)
<< std::endl;
2023-08-04 16:28:41 +02:00
std::cout << sizeof(boost::rational<int>) << std::endl;
std::cout << (1ul << exp) << std::endl;
}
}
2023-08-06 15:02:50 +02:00
int main(int argc, char *argv[]) {
// Hanabi::test_game();
2023-08-06 15:02:50 +02:00
if(argc == 2) {
std::string turn (argv[1]);
Hanabi::download(std::stoi(turn));
}
2023-08-04 16:28:41 +02:00
return 0;
}