Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 : #include "logging.hpp"
5 : #include "position.hpp"
6 :
7 : struct Searcher;
8 :
9 : [[nodiscard]] std::string trim(const std::string& str, const std::string& whitespace = " \t");
10 :
11 : void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
12 : std::vector<std::string> tokenize(const std::string& str, const std::string& delimiters = " ");
13 :
14 : void debug_king_cap(const Position& p);
15 :
16 : [[nodiscard]] std::string ToString(const PVList& moves);
17 :
18 : [[nodiscard]] std::string ToString(const MiniMove& m);
19 :
20 : [[nodiscard]] std::string ToString(const Move& m, bool withScore = false);
21 :
22 : [[nodiscard]] std::string ToString(const Position& p, bool noEval = false);
23 :
24 : [[nodiscard]] std::string ToString(const Position::Material& mat);
25 :
26 : [[nodiscard]] std::string ToString(const BitBoard& b);
27 :
28 : template < typename T >
29 : [[nodiscard]] std::string ToString(const array1d<T,NbSquare>& a){
30 : std::stringstream ss;
31 : for (int j = 7; j >= 0; --j) {
32 : ss << "\n";
33 : ss << Logging::_protocolComment[Logging::ct] << "+---+---+---+---+---+---+---+---+"
34 : << "\n";
35 : ss << Logging::_protocolComment[Logging::ct] << "|";
36 : for (int i = 0; i < 8; ++i) ss << std::setw(3) << static_cast<int>(a[i + j * 8]) << '|';
37 : }
38 : ss << "\n";
39 : ss << Logging::_protocolComment[Logging::ct] << "+---+---+---+---+---+---+---+---+";
40 : return ss.str();
41 : }
42 :
43 : template<typename F, typename... Arguments>
44 50 : void threadedWork(F&& worker, const size_t nbthreads, const uint64_t size, Arguments... args) {
45 50 : std::vector<std::thread> threads(nbthreads);
46 50 : const size_t grainsize = size / nbthreads;
47 50 : size_t work_iter = 0;
48 53 : for (auto it = std::begin(threads); it != std::end(threads) - 1; ++it) {
49 3 : *it = std::thread(worker, work_iter, work_iter + grainsize, args...);
50 3 : work_iter += grainsize;
51 : }
52 100 : threads.back() = std::thread(worker, work_iter, size, args...);
53 103 : for (auto&& i : threads) { i.join(); }
54 50 : }
55 :
56 : bool checkEval(const Position & p, ScoreType e, Searcher & context, const std::string & txt);
57 :
58 : [[nodiscard]] std::string showAlgAbr(const Move m, const Position& p);
59 :
60 : /*
61 : #include <cassert>
62 : #include <list>
63 :
64 : class AbstractDestroyer {
65 : public:
66 : virtual ~AbstractDestroyer();
67 : protected:
68 : AbstractDestroyer();
69 : virtual void destroy() = 0;
70 : };
71 :
72 : class DestroyerContainer {
73 : public:
74 : DestroyerContainer();
75 : virtual ~DestroyerContainer();
76 : static DestroyerContainer& Get();
77 : void addBack (AbstractDestroyer* destroyer);
78 : void addFront(AbstractDestroyer* destroyer);
79 : private:
80 : std::list<AbstractDestroyer*> _destroyers;
81 : };
82 :
83 : template <class DOOMED>
84 : class Destroyer : public AbstractDestroyer {
85 : public:
86 : Destroyer(DOOMED * d):_doomed(d){ assert(d); }
87 : ~Destroyer(){ destroy(); }
88 : void destroy(){ if (_doomed) delete _doomed; _doomed = 0;}
89 : private:
90 : DOOMED * _doomed;
91 : Destroyer(const Destroyer &){}
92 : Destroyer& operator = (const Destroyer &){return *this;}
93 : };
94 : */
|