| 274 | } |
| 275 | |
| 276 | shared_ptr<GameTreeNode> GameTree::recurrentGenerateTreeNode(json node_json, const shared_ptr<GameTreeNode>& parent) { |
| 277 | json meta = node_json["meta"]; |
| 278 | string round = meta["round"]; |
| 279 | if(round.empty()){ |
| 280 | throw runtime_error("node json get round null pointer"); |
| 281 | } |
| 282 | |
| 283 | if(! (round == "preflop" |
| 284 | || round == "flop" |
| 285 | || round == "turn" |
| 286 | || round == "river" |
| 287 | ) |
| 288 | ){ |
| 289 | throw runtime_error(tfm::format("round %s not found",round)); |
| 290 | } |
| 291 | |
| 292 | string node_type = meta["node_type"]; |
| 293 | if(node_type.empty()){ |
| 294 | throw runtime_error("node json get round null pointer"); |
| 295 | } |
| 296 | if (! ( node_type == "Terminal" |
| 297 | || node_type == "Showdown" |
| 298 | || node_type == "Action" |
| 299 | || node_type == "Chance" |
| 300 | ) |
| 301 | ){ |
| 302 | throw runtime_error(tfm::format("node type %s not found",node_type)); |
| 303 | } |
| 304 | |
| 305 | if(node_type == "Action") { |
| 306 | // 孩子节点的动作,存在list里 |
| 307 | auto childrens_actions = node_json["children_actions"].get<std::vector<string>>(); |
| 308 | // 孩子节点本身,同样存在list里,和上面的children_actions 一一对应,事实上两者的长度一致 |
| 309 | vector<json> childrens = node_json["children"].get<std::vector<json>>(); |
| 310 | if (childrens.size() != childrens_actions.size()) { |
| 311 | throw runtime_error("action node child length mismatch"); |
| 312 | } |
| 313 | return std::dynamic_pointer_cast<GameTreeNode>(this->generateActionNode(meta, childrens_actions, childrens, round,parent)); |
| 314 | } |
| 315 | else if(node_type == "Showdown") { |
| 316 | return std::dynamic_pointer_cast<GameTreeNode>(this->generateShowdownNode(meta, round,parent)); |
| 317 | } |
| 318 | else if(node_type == "Terminal") { |
| 319 | return std::dynamic_pointer_cast<GameTreeNode>(this->generateTerminalNode(meta, round,parent)); |
| 320 | } |
| 321 | else if(node_type == "Chance") { |
| 322 | auto childrens = node_json["children"].get<std::vector<json>>(); |
| 323 | if(childrens.size() != 1) throw runtime_error("Chance node should have only one child"); |
| 324 | return std::dynamic_pointer_cast<GameTreeNode>(this->generateChanceNode(meta, childrens[0], round,parent)); |
| 325 | } |
| 326 | else{ |
| 327 | throw runtime_error(tfm::format("node type %s not found",node_type)); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | shared_ptr<ActionNode> |
| 332 | GameTree::generateActionNode(json meta, vector<string> childrens_actions, vector<json> childrens_nodes, const string& round, |
no test coverage detected