-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearchinfo.h
executable file
·103 lines (83 loc) · 2.27 KB
/
searchinfo.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
98
99
100
101
102
103
#ifndef SEARCHINFO_H
#define SEARCHINFO_H
#include "constants.h"
#include "stopwatch.h"
#include "piece.h"
namespace Napoleon
{
class Move;
class SearchInfo
{
public:
enum class Time : int { Infinite = -1 };
SearchInfo(int time = int(Time::Infinite), int maxDepth = 1, int nodes = 0);
void NewSearch(int time = int(Time::Infinite));
void StopSearch();
int IncrementDepth();
int MaxDepth();
int Nodes();
bool TimeOver();
void ResetNodes();
void VisitNode();
void SetKillers(Move, int);
void SetHistory(Move, Color, int);
void SetDepthLimit(int);
void SetGameTime(int);
Move FirstKiller(int);
Move SecondKiller(int);
int HistoryScore(Move, Color);
double ElapsedTime();
int MaxPly;
private:
int depthLimit;
int maxDepth;
int nodes;
int history[2][64*64];
int allocatedTime; // milliseconds
Move killers[Constants::MaxPly][2];
StopWatch timer;
};
inline bool SearchInfo::TimeOver()
{
if (allocatedTime == int(Time::Infinite) && maxDepth <= depthLimit)
return false;
return (timer.ElapsedMilliseconds() >= allocatedTime || timer.ElapsedMilliseconds() / allocatedTime >= 0.85);
}
inline int SearchInfo::Nodes()
{
return nodes;
}
inline void SearchInfo::VisitNode()
{
++nodes;
}
inline Move SearchInfo::FirstKiller(int depth)
{
return killers[depth][0];
}
inline Move SearchInfo::SecondKiller(int depth)
{
return killers[depth][1];
}
inline int SearchInfo::HistoryScore(Move move, Color color)
{
return history[color][move.ButterflyIndex()];
}
inline double SearchInfo::ElapsedTime()
{
return timer.ElapsedMilliseconds();
}
inline void SearchInfo::SetKillers(Move move, int depth)
{
if (move != killers[depth][0])
{
killers[depth][1] = killers[depth][0];
}
killers[depth][0] = move;
}
inline void SearchInfo::SetHistory(Move move, Color color, int depth)
{
history[color][move.ButterflyIndex()] += (1 << depth);
}
}
#endif // SEARCHINFO_H