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

Method recurrentPrintTree

src/GameTree.cpp:532–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

530}
531
532void GameTree::recurrentPrintTree(const shared_ptr<GameTreeNode>& node, int depth, int depth_limit) {
533 if(depth_limit != -1 && depth >= depth_limit){
534 return;
535 }
536
537 if(node->getType() == GameTreeNode::ACTION){
538 shared_ptr<ActionNode> action_node = std::dynamic_pointer_cast<ActionNode>(node);
539 vector<shared_ptr<GameTreeNode>> childrens = action_node->getChildrens();
540 vector<GameActions> actions = action_node->getActions();
541
542 for(int i = 0;i < childrens.size();i++){
543 shared_ptr<GameTreeNode> one_child = childrens[i];
544 GameActions one_action = actions[i];
545
546 string prefix;
547 for(int j = 0;j < depth;j++) prefix += "\t";
548 cout << (tfm::format(
549 "%sp%s: %s",prefix,action_node->getPlayer(),one_action.toString()
550 )) << endl;
551 recurrentPrintTree(one_child,depth + 1,depth_limit);
552 }
553 }else if(node->getType() == GameTreeNode::SHOWDOWN){
554 shared_ptr<ShowdownNode> showdown_node = std::dynamic_pointer_cast<ShowdownNode>(node);
555 string prefix;
556 for(int j = 0;j < depth;j++) prefix += "\t";
557 cout << (tfm::format(
558 "%s SHOWDOWN pot %s ",prefix,showdown_node->getPot()
559 )) << endl;
560
561 prefix += "\t";
562 for(int i = 0;i < showdown_node->get_payoffs(ShowdownNode::ShowDownResult::TIE,-1).size();i++) {
563 cout << (tfm::format("%sif player %s wins, payoff :", prefix,i));
564 vector<double> payoffs = showdown_node->get_payoffs(ShowdownNode::ShowDownResult::NOTTIE, i);
565
566 for (int player_id = 0; player_id < payoffs.size(); player_id++) {
567 cout << (
568 tfm::format(" p%s %s ", player_id, payoffs[player_id])
569 );
570 }
571 cout << endl;
572 }
573 cout << (tfm::format("%sif Tie, payoff :", prefix));
574 vector<double> payoffs = showdown_node->get_payoffs(ShowdownNode::ShowDownResult::TIE, -1);
575
576 for (int player_id = 0; player_id < payoffs.size(); player_id++) {
577 cout << (
578 tfm::format(" p%s %s ", player_id, payoffs[player_id])
579 );
580 }
581 cout << endl;
582 }else if(node->getType() == GameTreeNode::TERMINAL){
583 shared_ptr<TerminalNode> terminal_node = std::dynamic_pointer_cast<TerminalNode>(node);
584 string prefix;
585 for(int j = 0;j < depth;j++) prefix += "\t";
586 cout << (tfm::format(
587 "%s TERMINAL pot %s ",prefix,terminal_node->getPot()
588 )) << endl;
589

Callers 1

printTreeMethod · 0.95

Calls 8

formatFunction · 0.85
sizeMethod · 0.80
getPotMethod · 0.80
getChildrenMethod · 0.80
getTypeMethod · 0.45
getPlayerMethod · 0.45
toStringMethod · 0.45
get_payoffsMethod · 0.45

Tested by

no test coverage detected