forked from QueensGambit/CrazyAra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodedata.h
124 lines (100 loc) · 3.01 KB
/
nodedata.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
CrazyAra, a deep learning chess variant engine
Copyright (C) 2018 Johannes Czech, Moritz Willig, Alena Beyer
Copyright (C) 2019-2020 Johannes Czech
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/>.
*/
/*
* @file: nodedata.h
* Created on 25.04.2020
* @author: queensgambit
*
* Node data is a data container which is unavailable for all nodes <= 1 to reduce memory consumption.
*/
#ifndef NODEDATA_H
#define NODEDATA_H
#include <iostream>
#include <mutex>
#include <unordered_map>
#include <blaze/Math.h>
#include "agents/config/searchsettings.h"
using blaze::HybridVector;
using blaze::DynamicVector;
using namespace std;
enum NodeType : uint8_t {
WIN,
DRAW,
LOSS,
#ifdef MCTS_TB_SUPPORT
TB_WIN,
TB_DRAW,
TB_LOSS,
#endif
UNSOLVED
};
/**
* @brief is_loss_node_type Returns true if given node type belongs to a loosing node type
* @param nodeType
* @return bool
*/
bool is_loss_node_type(NodeType nodeType);
/**
* @brief is_win_node_type Returns true if given node type belongs to a win node type
* @param nodeType
* @return bool
*/
bool is_win_node_type(NodeType nodeType);
/**
* @brief is_draw_node_type Returns true if given node type belongs to a drawubg node type
* @param nodeType
* @return bool
*/
bool is_draw_node_type(NodeType nodeType);
/**
* @brief is_unsolved_or_tablebase Checks if the given node type is a win, draw, loss or a different type.
* @param nodeType given node type
* @return bool
*/
bool is_unsolved_or_tablebase(NodeType nodeType);
class Node;
/**
* @brief The NodeData struct stores the member variables for all expanded child nodes which have at least been visited two times
*/
struct NodeData
{
DynamicVector<uint32_t> childNumberVisits;
DynamicVector<float> qValues;
vector<shared_ptr<Node>> childNodes;
DynamicVector<uint8_t> virtualLossCounter;
DynamicVector<NodeType> nodeTypes;
uint32_t freeVisits;
uint32_t visitSum;
uint16_t checkmateIdx;
uint16_t endInPly;
uint16_t noVisitIdx;
uint16_t numberUnsolvedChildNodes;
NodeType nodeType;
bool inspected;
NodeData();
NodeData(size_t numberChildNodes);
auto get_q_values();
public:
/**
* @brief add_empty_node Adds a new empty node to its child nodes
*/
void add_empty_node();
/**
* @brief reserve_initial_space Reserves memory for PRESERVED_ITEMS number of child nodes
*/
void reserve_initial_space();
};
#endif // NODEDATA_H