2#include "OpeningBook.hpp"
7#include <unordered_set>
9using namespace GameSolver::Connect4;
11std::unordered_set<uint64_t> visited;
17void explore(
const Position &P,
char* pos_str,
const int depth) {
18 uint64_t key = P.
key3();
19 if(!visited.insert(key).second)
24 std::cout << pos_str << std::endl;
25 if(nb_moves >= depth)
return;
27 for(
int i = 0; i < Position::WIDTH; i++)
31 pos_str[nb_moves] =
'1' + i;
32 explore(P2, pos_str, depth);
33 pos_str[nb_moves] = 0;
43void generate_opening_book() {
44 static constexpr int BOOK_SIZE = 23;
45 static constexpr int DEPTH = 14;
46 static constexpr double LOG_3 = 1.58496250072;
47 TranspositionTable<uint_t<int((DEPTH + Position::WIDTH -1) * LOG_3) + 1 - BOOK_SIZE>, Position::position_t, uint8_t, BOOK_SIZE> *table =
48 new TranspositionTable<uint_t<int((DEPTH + Position::WIDTH -1) * LOG_3) + 1 - BOOK_SIZE>, Position::position_t, uint8_t, BOOK_SIZE>();
51 for(std::string line; getline(std::cin, line); count++) {
52 if(line.length() == 0)
break;
53 std::istringstream iss(line);
55 getline(iss, pos,
' ');
60 if(iss.fail() || !iss.eof()
61 || P.
play(pos) != pos.length()
62 || score < Position::MIN_SCORE || score > Position::MAX_SCORE) {
63 std::cerr <<
"Invalid line (line ignored): " << line << std::endl;
66 table->put(P.
key3(), score - Position::MIN_SCORE + 1);
67 if(count % 1000000 == 0) std::cerr << count << std::endl;
70 OpeningBook book{Position::WIDTH, Position::HEIGHT, DEPTH, table};
72 std::ostringstream book_file;
73 book_file << Position::WIDTH <<
"x" << Position::HEIGHT <<
".book";
74 book.save(book_file.str());
81int main(
int argc,
char** argv) {
83 int depth = atoi(argv[1]);
84 char pos_str[depth + 1] = {0};
86 }
else generate_opening_book();
bool canPlay(int col) const
bool isWinningMove(int col) const
void play(position_t move)