BitBully
0.0.78
A fast, perfect-play Connect-4 engine in modern C++
Loading...
Searching...
No Matches
main.cpp
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
#include "Solver.hpp"
20
#include <iostream>
21
22
using namespace
GameSolver::Connect4;
23
35
int
main
(
int
argc,
char
** argv) {
36
Solver
solver;
37
bool
weak =
false
;
38
bool
analyze =
false
;
39
40
std::string opening_book =
"7x6.book"
;
41
for
(
int
i = 1; i < argc; i++) {
42
if
(argv[i][0] ==
'-'
) {
43
if
(argv[i][1] ==
'w'
) weak =
true
;
// parameter -w: use weak solver
44
else
if
(argv[i][1] ==
'b'
) {
// paramater -b: define an alternative opening book
45
if
(++i < argc) opening_book = std::string(argv[i]);
46
}
47
else
if
(argv[i][1] ==
'a'
) {
// paramater -a: make an analysis of all possible moves
48
analyze =
true
;
49
}
50
}
51
}
52
solver.loadBook(opening_book);
53
54
std::string line;
55
56
for
(
int
l = 1; std::getline(std::cin, line); l++) {
57
Position
P;
58
if
(P.
play
(line) != line.size()) {
59
std::cerr <<
"Line "
<< l <<
": Invalid move "
<< (P.
nbMoves
() + 1) <<
" \""
<< line <<
"\""
<< std::endl;
60
}
else
{
61
std::cout << line;
62
if
(analyze) {
63
std::vector<int> scores = solver.analyze(P, weak);
64
for
(
int
i = 0; i < Position::WIDTH; i++) std::cout <<
" "
<< scores[i];
65
}
66
else
{
67
int
score = solver.solve(P, weak);
68
std::cout <<
" "
<< score;
69
}
70
std::cout << std::endl;
71
}
72
}
73
}
GameSolver::Connect4::Position
A class storing a Connect 4 position.
Definition
Position.hpp:84
GameSolver::Connect4::Position::nbMoves
int nbMoves() const
Definition
Position.hpp:152
GameSolver::Connect4::Position::play
void play(position_t move)
Plays a possible move given by its bitmap representation.
Definition
Position.hpp:113
GameSolver::Connect4::Solver
Definition
Solver.hpp:31
main
int main(const int argc, const char *const argv[])
Entry point of the benchmark binary.
Definition
main.cpp:108
thirdParty
connect4
main.cpp
Generated by
1.16.1