Belofte version 2.2.0
A promising chess program using the UCI or Winboard interface
configurablegame.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: configurablegame.cpp
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#include "belofte.h"
9
15
17{
18 clearAlgorithm();
19 clearEval();
20}
21
22void bConfigurableGame::setAlgorithm(std::string const& alg)
23{
24 clearAlgorithm();
25 if (alg == "Random") {
26 m_algo = new SearchRandom();
27 App().setConfig("random", 1); // random algorithm always activate random
28 Game()->getLevel().setDepthCommand(1); // and depth 1
29 } else if (alg == "StaticEval") {
30 m_algo = new SearchEvalPosOnly();
31 Game()->getLevel().setDepthCommand(1); // static eval is always depth 1
32 } else if (alg == "BruteForce") {
33 m_algo = new SearchBruteForce();
34 } else if (alg == "SearchIterativeBF") {
35 m_algo = new SearchIterativeBF();
36 } else if (alg == "MiniMax") {
37 m_algo = new SearchMiniMax();
38 } else if (alg == "AB") {
39 m_algo = new SearchAlphaBeta();
40 } else if (alg == "ABFS") {
41 m_algo = new SearchAlphaBeta();
42 } else if (alg == "ABFH") {
43 m_algo = new SearchAlphaBetaFH();
44 } else { // SearchAlphaBeta is default
45 m_algo = new SearchAlphaBeta();
46 }
47}
48
50{
51 if (m_algo == nullptr) throw std::logic_error("no algorithm defined");
52 return m_algo;
53}
54
55void bConfigurableGame::clearAlgorithm()
56{
57 delete m_algo;
58 m_algo = nullptr;
59}
60
61void bConfigurableGame::setEval(std::string const& e)
62{
63 clearEval();
64 if (e == "None") {
65 m_eval = new bPositionEvaluation();
66 } else if (e == "PiecesOnly") {
67 m_eval = new PosEvalPiecesOnly();
68 } else if (e == "StaticBoard") {
69 m_eval = new PosEvalStaticBoard();
70 } else if (e == "PositionalBoard") {
71 m_eval = new PosEvalPositionalBoard();
72 } else { // PosEvalPositionalBoard is default
73 m_eval = new PosEvalPositionalBoard();
74 }
75}
76
78{
79 if (m_eval == nullptr) throw std::logic_error("no eval defined");
80 return m_eval;
81}
82
83void bConfigurableGame::clearEval()
84{
85 delete m_eval;
86 m_eval = nullptr;
87}
88
89// eof
appInstance & App()
Definition belofte.cpp:242
bGame * Game()
Definition belofte.cpp:253
This is the main include file, needs to be included before any other include.
void setConfig(std::string const &s, int64_t v)
Definition belofte.cpp:194
void setAlgorithm(std::string const &alg)
void setEval(std::string const &e)
bSearchAlgorithm * getAlgorithm() const
bPositionEvaluation * getEval() const
bLevel & getLevel()
Definition game.h:59
void setDepthCommand(depth_t const d)
Definition level.cpp:226