ChineseCheckers
This project is a solver for two players' Chinese Checkers game using the Alpha Beta pruning algorithm. The program is written in C++ and uses a number of heuristics to improve the performance of the algorithm. Overall, the Chinese Checkers solver program has been built with performance in mind, and is designed to deliver fast and efficient game play. Whether you are playing against a bot or using the program as a library in your own project, you can be confident that the program will deliver high-performance results.
Loading...
Searching...
No Matches
tournament.hpp
Go to the documentation of this file.
1/*
2 * This file is part of ChineseCheckers which is released under GNU General Public License v3.0.
3 * See file LICENSE or go to https://github.com/alexicanesse/ChineseCheckers/blob/main/LICENSE for full license details.
4 * Copyright 2022 - ENS de Lyon
5 */
6
15#ifndef INCLUDE_TOURNAMENT_HPP_
16#define INCLUDE_TOURNAMENT_HPP_
17
18/* C libraries */
19#include <numbers>
20
21/* C++ libraries */
22#include <vector>
23#include <random>
24#include <chrono>
25#include <cmath>
26#include <algorithm>
27#include <iomanip>
28#include <limits>
29#include <fstream>
30#include <thread>
31
32/* The following pragma are used to removed depraction warning from boost
33 * header files. Using them avoid to remove this warning from the entire project.
34 */
35#pragma GCC diagnostic push
36#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
37#include <boost/python.hpp>
38#pragma GCC diagnostic pop
39
40/* Other */
41#include "Types.hpp"
42#include "AlphaBeta.hpp"
43
44Result playGame(AlphaBeta &player0, AlphaBeta &player1, const int &depth);
45void print_matrix(const std::vector<double> &matrix);
46
52 private:
61 std::vector<double> win;
71 std::vector<double> lose;
76 double score;
77
78 public:
82 SolversIndividuals(std::vector<double> &win_, std::vector<double> &lose_);
83
88 friend bool operator<(SolversIndividuals const &s1,
89 SolversIndividuals const &s2);
95
105 std::vector<double> get_win();
115 std::vector<double> get_lose();
120 double get_score();
121
129 void init_at_random();
140 void set_win(const std::vector<double> &win_);
151 void set_lose(const std::vector<double> &lose_);
158 void set_score(const double &score_);
159
161 void mutate();
162
168 void print_info();
181 void print_info_as_matrix_to_file(std::ofstream &file);
182
183 void crossOver(const SolversIndividuals & Parent1, const SolversIndividuals & Parent2);
184};
185
188 private:
194 int depth;
195
196 public:
198 GamePlayer();
200 GamePlayer(int depth_);
203 SolversIndividuals &solver2,
204 int depth_ = 1);
205
210 double playGame();
211
232 void set_depth(const int &depth_);
233
235 void print_players_info();
236
238 int constructor_test();
239};
240
241
243 public:
244 int start;
245 int end;
248 void operator()(std::vector<SolversIndividuals> &population,bool is_white_evolving);/*std::vector<SolversIndividuals> &population,bool is_white_evolving*/
249};
250
251
252void write_scores(std::ofstream &file,
253 std::vector<SolversIndividuals> &population,
254 SolversIndividuals &best_to_write,
255 const int &gen);
256
257void evol(GamePlayer *gp,
258 std::vector<SolversIndividuals> &population,
259 SolversIndividuals *best_player,
260 bool is_white_evolving);
261
262void evol_thread(const std::vector<ThreadGamePlayer> & gps,
263 std::vector<SolversIndividuals> &population,
264 SolversIndividuals *best_player,
265 bool is_white_evolving);
266
267#endif // INCLUDE_TOURNAMENT_HPP_
Alpha-Beta algorithm declaration.
Types definition.
Result
Used to return the current state of a game.
Definition: Types.hpp:52
The AlphaBeta class inherits from the ChineseCheckers class and provides an implementation of the alp...
Definition: AlphaBeta.hpp:43
This class simulates a game between two solvers.
Definition: tournament.hpp:187
void set_black_player(SolversIndividuals &solver)
Sets black_player.
Definition: tournament.cpp:504
void set_white_player(SolversIndividuals &solver)
Sets white_player.
Definition: tournament.cpp:499
AlphaBeta white_player
A solver using AlphaBeta.
Definition: tournament.hpp:190
void print_players_info()
Prints information on the players.
Definition: tournament.cpp:565
AlphaBeta black_player
A solver using AlphaBeta.
Definition: tournament.hpp:192
int constructor_test()
Debug function used to test the constructors.
Definition: tournament.cpp:583
void set_depth(const int &depth_)
Sets depth.
Definition: tournament.cpp:509
int depth
The depth AlphaBeta will use.
Definition: tournament.hpp:194
double playGame()
Member used to simulate a game between white_player and black_player.
Definition: tournament.cpp:513
GamePlayer()
Default constructor.
Definition: tournament.cpp:483
This class is designed to represent individuals in a solver population and contains various methods f...
Definition: tournament.hpp:51
friend bool operator<(SolversIndividuals const &s1, SolversIndividuals const &s2)
Operator used to compare two SolversIndividuals.
Definition: tournament.cpp:297
SolversIndividuals()
Default constructor.
Definition: tournament.cpp:262
void print_info_as_matrix_to_file(std::ofstream &file)
Prints information on win and lose to a file given as a parameter.
Definition: tournament.cpp:426
void set_score(const double &score_)
Sets score with the parameter.
Definition: tournament.cpp:332
std::vector< double > lose
The matrix used to compute the heuristic value for the adversary of the player we are playing.
Definition: tournament.hpp:71
std::vector< double > get_lose()
Returns lose.
Definition: tournament.cpp:320
double score
The score the individual got at its last game.
Definition: tournament.hpp:76
std::vector< double > get_win()
Returns win.
Definition: tournament.cpp:316
void set_win(const std::vector< double > &win_)
Sets win with the parameter.
Definition: tournament.cpp:324
void set_lose(const std::vector< double > &lose_)
Sets lose with the parameter.
Definition: tournament.cpp:328
void print_info()
Print information about the SolversIndividuals.
Definition: tournament.cpp:369
void init_at_random()
Inits win and lose at random.
Definition: tournament.cpp:283
void mutate()
Mutates a solver.
Definition: tournament.cpp:341
std::vector< double > win
The matrix used to compute the heuristic value for the player we are playing.
Definition: tournament.hpp:61
void crossOver(const SolversIndividuals &Parent1, const SolversIndividuals &Parent2)
Definition: tournament.cpp:461
SolversIndividuals & operator=(const SolversIndividuals &other)
Operator used to compare two SolversIndividuals.
Definition: tournament.cpp:305
void print_info_as_matrix()
Prints information on win and lose.
Definition: tournament.cpp:390
double get_score()
Returns score.
Definition: tournament.cpp:336
Definition: tournament.hpp:242
void operator()(std::vector< SolversIndividuals > &population, bool is_white_evolving)
Definition: tournament.cpp:767
int end
Definition: tournament.hpp:245
ThreadGamePlayer()
Definition: tournament.cpp:764
int start
Definition: tournament.hpp:244
GamePlayer gp
Definition: tournament.hpp:246
void evol(GamePlayer *gp, std::vector< SolversIndividuals > &population, SolversIndividuals *best_player, bool is_white_evolving)
Definition: tournament.cpp:621
void evol_thread(const std::vector< ThreadGamePlayer > &gps, std::vector< SolversIndividuals > &population, SolversIndividuals *best_player, bool is_white_evolving)
Definition: tournament.cpp:695
void write_scores(std::ofstream &file, std::vector< SolversIndividuals > &population, SolversIndividuals &best_to_write, const int &gen)
Definition: tournament.cpp:606
void print_matrix(const std::vector< double > &matrix)
Definition: tournament.cpp:472
Result playGame(AlphaBeta &player0, AlphaBeta &player1, const int &depth)