MCPcopy Create free account
hub / github.com/bupticybee/TexasSolver / recurrentGenerateTreeNode

Method recurrentGenerateTreeNode

src/GameTree.cpp:276–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276shared_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
331shared_ptr<ActionNode>
332GameTree::generateActionNode(json meta, vector<string> childrens_actions, vector<json> childrens_nodes, const string& round,

Callers 1

GameTreeMethod · 0.95

Calls 7

generateActionNodeMethod · 0.95
generateShowdownNodeMethod · 0.95
generateTerminalNodeMethod · 0.95
generateChanceNodeMethod · 0.95
formatFunction · 0.85
sizeMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected