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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
#pragma once
#include <fstream>
#include <string>
#include <utility/debug.h>
/*
AB_COUNT is a macro that avoids the tedious #ifdef's at
the code places to be counted.
*/
#ifdef DDS_AB_STATS
#define AB_COUNT(a, b, c) thrp->ABStats.IncrPos(a, b, c)
#else
#define AB_COUNT(a, b, c)
#endif
enum ABCountType
{
AB_TARGET_REACHED = 0,
AB_DEPTH_ZERO = 1,
AB_QUICKTRICKS = 2,
AB_QUICKTRICKS_2ND = 3,
AB_LATERTRICKS = 4,
AB_MAIN_LOOKUP = 5,
AB_SIDE_LOOKUP = 6,
AB_MOVE_LOOP = 7,
AB_SIZE = 8
};
#define DDS_MAXDEPTH 49
struct ABtracker
{
int list[DDS_MAXDEPTH];
int sum;
int sumWeighted;
int sumCum;
int sumCumWeighted;
};
/**
* @brief Alpha-beta search statistics accumulator for bridge double dummy solver.
*
* The ABstats class accumulates, tracks, and reports statistics related to
* alpha-beta pruning and search operations during double dummy analysis. It
* provides detailed breakdowns by position, depth, and side, supporting
* performance tuning and debugging. Used internally for profiling.
*/
class ABstats
{
private:
std::string name[AB_SIZE];
// A node arises when a new move is generated.
// Not every move leads to an AB termination.
ABtracker ABnodes;
ABtracker ABnodesCum;
// AB terminations are tracked by side and position.
ABtracker ABsides[2];
ABtracker ABplaces[AB_SIZE];
void SetNames();
void PrintHeaderPosition(std::ofstream& fout) const;
void PrintStatsPosition(
std::ofstream& fout,
const int no,
const std::string& text,
const ABtracker& abt,
const ABtracker& divisor) const;
void PrintHeaderDepth(std::ofstream& fout) const;
void PrintStatsDepth(
std::ofstream& fout,
const int depth,
const int cum) const;
void PrintAverageDepth(
std::ofstream& fout,
const ABtracker& ABsidesSum) const;
void PrintHeaderDetail(std::ofstream& fout) const;
void PrintStatsDetail(
std::ofstream& fout,
const int depth) const;
void PrintSumDetail(std::ofstream& fout) const;
public:
/**
* @brief Construct a new ABstats object.
*
* Initializes the alpha-beta statistics accumulator.
*/
ABstats();
/**
* @brief Destroy the ABstats object and clean up resources.
*
* Releases all memory and resets the statistics state.
*/
~ABstats();
void Reset();
void ResetCum();
void IncrPos(
const ABCountType no,
const bool side,
const int depth);
void IncrNode(const int depth);
int GetNodes() const;
void PrintStats(std::ofstream& fout);
};