-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsearch.h
97 lines (79 loc) · 3.78 KB
/
search.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Clarity
Copyright (C) 2024 Joseph Pasfield
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "globals.h"
#include "tt.h"
#include "corrhist.h"
extern std::atomic<bool> timesUp;
constexpr int depthLimit = 120;
constexpr int16_t matedScore = -32000;
struct StackEntry {
std::array<Move, depthLimit> pvTable;
int pvLength;
// conthist!
CHEntry *ch_entry;
Move move;
// killer move
Move killer;
// static eval used for improving
int staticEval;
bool inCheck;
// excluded move
Move excluded;
int doubleExtensions;
};
struct Engine {
public:
void resetEngine();
Move think(Board board, int softBound, int hardBound, bool info);
Move getBestMove();
int benchSearch(Board board, int depthToSearch);
Move fixedDepthSearch(Board board, int depthToSearch, bool info);
std::pair<Move, int> dataGenSearch(Board board, uint64_t nodeCap);
Move fixedNodesSearch(Board board, int nodeCount, bool info);
Engine(TranspositionTable *tt) {
conthistTable = std::make_unique<CHTable>();
TT = tt;
}
uint64_t nodes = 0;
private:
bool useNodeCap = false;
Move rootBestMove = Move();
int hardLimit = 0;
int seldepth = 0;
std::array<StackEntry, depthLimit> stack;
TranspositionTable* TT;
std::array<std::array<std::array<std::array<std::array<int16_t, 2>, 64>, 2>, 64>, 2> historyTable;
std::array<std::array<std::array<std::array<int16_t, 7>, 64>, 7>, 2> noisyHistoryTable;
std::array<std::array<std::array<std::array<int16_t, 7>, 64>, 7>, 2> qsHistoryTable;
std::array<std::array<std::array<std::array<int16_t, 64>, 7>, 2>, 32768> pawnHistoryTable;
Corrhist corrhist;
std::unique_ptr<CHTable> conthistTable;
std::array<std::array<Move, 64>, 64> counterMoves;
std::array<std::array<int, 64>, 64> nodeTMTable;
std::chrono::steady_clock::time_point begin;
void clearHistory();
int estimateMoveValue(const Board& board, const int end, const int flag);
bool see(const Board& board, Move move, int threshold);
void scoreMoves(const Board& board, std::array<Move, 256> &moves, std::array<int, 256> &values, int numMoves, Move ttMove, int16_t ply);
void scoreMovesQS(const Board& board, std::array<Move, 256> &moves, std::array<int, 256> &values, int numMoves, Move ttMove);
int16_t qSearch(Board &board, int alpha, int beta, int16_t ply);
void updateHistory(const int colorToMove, const int start, const int end, const int piece, const int bonus, const int16_t ply, const int hash, const bool startAttack, const bool endAttack);
void updateNoisyHistory(const int colorToMove, const int piece, const int end, const int victim, const int bonus);
void updateQSHistory(const int colorToMove, const int piece, const int end, const int victim, const int bonus);
int16_t negamax(Board &board, int depth, int alpha, int beta, int16_t ply, bool nmpAllowed, bool isCutNode);
std::string getPV();
void outputInfo(const Board& board, int score, int depth, int elapsedTime);
};