| 875 | } |
| 876 | |
| 877 | void PCfrSolver::reConvertJson(const shared_ptr<GameTreeNode>& node,json& strategy,string key,int depth,int max_depth,vector<string> prefix,int deal,vector<vector<int>> exchange_color_list) { |
| 878 | if(depth >= max_depth) return; |
| 879 | if(node->getType() == GameTreeNode::GameTreeNodeType::ACTION) { |
| 880 | json* retval; |
| 881 | if(key != ""){ |
| 882 | strategy[key] = json(); |
| 883 | retval = &(strategy[key]); |
| 884 | }else{ |
| 885 | retval = &strategy; |
| 886 | } |
| 887 | |
| 888 | shared_ptr<ActionNode> one_node = std::dynamic_pointer_cast<ActionNode>(node); |
| 889 | |
| 890 | vector<string> actions_str; |
| 891 | for(GameActions one_action:one_node->getActions()) actions_str.push_back(one_action.toString()); |
| 892 | |
| 893 | (*retval)["actions"] = actions_str; |
| 894 | (*retval)["player"] = one_node->getPlayer(); |
| 895 | |
| 896 | (*retval)["childrens"] = json(); |
| 897 | json& childrens = (*retval)["childrens"]; |
| 898 | |
| 899 | for(int i = 0;i < one_node->getActions().size();i ++){ |
| 900 | GameActions& one_action = one_node->getActions()[i]; |
| 901 | shared_ptr<GameTreeNode> one_child = one_node->getChildrens()[i]; |
| 902 | vector<string> new_prefix(prefix); |
| 903 | new_prefix.push_back(one_action.toString()); |
| 904 | this->reConvertJson(one_child,childrens,one_action.toString(),depth,max_depth,new_prefix,deal,exchange_color_list); |
| 905 | } |
| 906 | if((*retval)["childrens"].empty()){ |
| 907 | (*retval).erase("childrens"); |
| 908 | } |
| 909 | shared_ptr<Trainable> trainable = one_node->getTrainable(deal,false); |
| 910 | if(trainable != nullptr) { |
| 911 | (*retval)["strategy"] = trainable->dump_strategy(false); |
| 912 | for(vector<int> one_exchange:exchange_color_list){ |
| 913 | int rank1 = one_exchange[0]; |
| 914 | int rank2 = one_exchange[1]; |
| 915 | this->exchangeRange((*retval)["strategy"]["strategy"],rank1,rank2,one_node); |
| 916 | |
| 917 | } |
| 918 | } |
| 919 | (*retval)["node_type"] = "action_node"; |
| 920 | |
| 921 | }else if(node->getType() == GameTreeNode::GameTreeNodeType::SHOWDOWN) { |
| 922 | }else if(node->getType() == GameTreeNode::GameTreeNodeType::TERMINAL) { |
| 923 | }else if(node->getType() == GameTreeNode::GameTreeNodeType::CHANCE) { |
| 924 | json* retval; |
| 925 | if(key != ""){ |
| 926 | strategy[key] = json(); |
| 927 | retval = &(strategy[key]); |
| 928 | }else{ |
| 929 | retval = &strategy; |
| 930 | } |
| 931 | |
| 932 | shared_ptr<ChanceNode> chanceNode = std::dynamic_pointer_cast<ChanceNode>(node); |
| 933 | const vector<Card>& cards = chanceNode->getCards(); |
| 934 | shared_ptr<GameTreeNode> childerns = chanceNode->getChildren(); |
no test coverage detected