BitBully 0.0.39
Loading...
Searching...
No Matches
Solver.hpp
1/*
2 * This file is part of Connect4 Game Solver <http://connect4.gamesolver.org>
3 * Copyright (C) 2017-2019 Pascal Pons <contact@gamesolver.org>
4 *
5 * Connect4 Game Solver is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Connect4 Game Solver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Connect4 Game Solver. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef SOLVER_HPP
20#define SOLVER_HPP
21
22#include <vector>
23#include <string>
24#include "Position.hpp"
25#include "TranspositionTable.hpp"
26#include "OpeningBook.hpp"
27
28namespace GameSolver {
29namespace Connect4 {
30
31class Solver {
32 private:
33 static constexpr int TABLE_SIZE = 24; // store 2^TABLE_SIZE elements in the transpositiontbale
34 TranspositionTable < uint_t < Position::WIDTH*(Position::HEIGHT + 1) - TABLE_SIZE >, Position::position_t, uint8_t, TABLE_SIZE > transTable;
35 OpeningBook book{Position::WIDTH, Position::HEIGHT}; // opening book
36 unsigned long long nodeCount; // counter of explored nodes.
37 int columnOrder[Position::WIDTH]; // column exploration order
38
50 int negamax(const Position &P, int alpha, int beta);
51
52 public:
53 static constexpr int INVALID_MOVE = -1000;
54
55 // Returns the score of a position
56 int solve(const Position &P, bool weak = false);
57
58 // Returns the score off all possible moves of a position as an array.
59 // Returns INVALID_MOVE for unplayable columns
60 std::vector<int> analyze(const Position &P, bool weak = false);
61
62 unsigned long long getNodeCount() const {
63 return nodeCount;
64 }
65
66 void reset() {
67 nodeCount = 0;
68 transTable.reset();
69 }
70
71 void loadBook(std::string book_file) {
72 book.load(book_file);
73 }
74
75 Solver(); // Constructor
76};
77
78} // namespace Connect4
79} // namespace GameSolver
80#endif