-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameTreeNode.cpp
139 lines (124 loc) · 4.16 KB
/
GameTreeNode.cpp
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
//
// Created by Xuefeng Huang on 2020/1/29.
//
#include "include/nodes/GameTreeNode.h"
#include <utility>
GameTreeNode::GameTreeNode() {
}
GameTreeNode::GameTreeNode(GameTreeNode::GameRound round, double pot, shared_ptr<GameTreeNode> parent) {
this->round = round;
this->pot = pot;
this->parent = std::move(parent);
}
int GameTreeNode::gameRound2int(GameTreeNode::GameRound gameRound) {
if(gameRound == GameRound::PREFLOP) {
return 0;
}else if(gameRound == GameRound::FLOP){
return 1;
} else if(gameRound == GameRound::TURN) {
return 2;
} else if(gameRound == GameRound::RIVER) {
return 3;
}
throw runtime_error("round not found");
}
shared_ptr<GameTreeNode>GameTreeNode::getParent() {
return this->parent.lock();
}
void GameTreeNode::setParent(shared_ptr<GameTreeNode>parent) {
this->parent = parent;
}
GameTreeNode::GameRound GameTreeNode::getRound() {
return this->round;
}
double GameTreeNode::getPot() {
return this->pot;
}
void GameTreeNode::printHistory() {
//GameTreeNode::printNodeHistory(this);
}
GameTreeNode::GameRound GameTreeNode::intToGameRound(int round){
GameTreeNode::GameRound game_round;
switch(round){
case 0:{
game_round = GameTreeNode::GameRound::PREFLOP;
break;
}
case 1:{
game_round = GameTreeNode::GameRound::FLOP;
break;
}
case 2:{
game_round = GameTreeNode::GameRound::TURN;
break;
}
case 3:{
game_round = GameTreeNode::GameRound::RIVER;
break;
}
default:{
throw runtime_error(tfm::format("round %s not found",round));
}
}
return game_round;
}
string GameTreeNode::toString(){
/*
shared_ptr<GameTreeNode>parent_node = node->parent;
string round;
if (parent_node == nullptr) return tfm::format("%s begin",round);
if(parent_node->getType() == GameTreeNodeType::ACTION){
ActionNode action_node = (ActionNode)parent_node;
for(int i = 0;i < action_node.getActions().size();i ++){
if(action_node.getChildrens().get(i) == node){
System.out.print(String.format("<- (player %s %s)",
action_node.getPlayer(),
action_node.getActions().get(i).toString()
));
}
}
}else if(parent_node->getType() == GameTreeNodeType::CHANCE){
ChanceNode chance_node = (ChanceNode)parent_node;
for(int i = 0;i < chance_node.getChildrens().size();i ++){
if(chance_node.getChildrens().get(i) == node){
System.out.print(String.format("<- (deal card %s)",
chance_node.getCards().get(i).toString()
));
}
}
*/
return "";
}
void GameTreeNode::printNodeHistory(GameTreeNode* node) {
/*
while(node != nullptr) {
shared_ptr<GameTreeNode>parent_node = node->parent;
if (parent_node == nullptr) break;
if(parent_node instanceof ActionNode){
ActionNode action_node = (ActionNode)parent_node;
for(int i = 0;i < action_node.getActions().size();i ++){
if(action_node.getChildrens().get(i) == node){
System.out.print(String.format("<- (player %s %s)",
action_node.getPlayer(),
action_node.getActions().get(i).toString()
));
}
}
}else if(parent_node instanceof ChanceNode) {
ChanceNode chance_node = (ChanceNode)parent_node;
for(int i = 0;i < chance_node.getChildrens().size();i ++){
if(chance_node.getChildrens().get(i) == node){
System.out.print(String.format("<- (deal card %s)",
chance_node.getCards().get(i).toString()
));
}
}
}else{
System.out.print(String.format("<- (%s)",node.toString()));
}
node = parent_node;
}
System.out.println()
}
*/
}