#include "stlplus.hpp"
#include <vector>
using namespace std;
#define WON 1
#define LOSS 0
void hD_initGraph(digraph<string,int>& graph){
digraph<string,int>::iterator node1 = graph.insert("1");
digraph<string,int>::iterator node2 = graph.insert("3");
digraph<string,int>::iterator node3 = graph.insert("7");
digraph<string,int>::iterator node4 = graph.insert("15");
digraph<string,int>::arc_iterator arc1 = graph.arc_insert(node1, node2, LOSS);
digraph<string,int>::arc_iterator arc2 = graph.arc_insert(node2, node3, LOSS);
digraph<string,int>::arc_iterator arc3 = graph.arc_insert(node3, node4, LOSS);
digraph<string,int>::arc_iterator arc5 = graph.arc_insert(node1, node1, WON);
digraph<string,int>::arc_iterator arc6 = graph.arc_insert(node2, node1, WON);
digraph<string,int>::arc_iterator arc7 = graph.arc_insert(node3, node1, WON);
digraph<string,int>::arc_iterator arc8 = graph.arc_insert(node4, node1, WON);
digraph<string,int>::arc_iterator arc9 = graph.arc_insert(node4, node1, LOSS);
}//hD_initGraph
digraph<string,int>::const_iterator getNextNode(const digraph<string,int>& graph, const digraph<string,int>::const_iterator node, int lastBetResult){
static char lastBetResult_ch[10];
digraph<string,int>::const_arc_iterator out_arc;
digraph<string,int>::const_iterator nextNODE;
if (lastBetResult==LOSS)
sprintf(lastBetResult_ch, "%s", "LOSS");
else if (lastBetResult==WON)
sprintf(lastBetResult_ch, "%s", "WON");
for (unsigned it = 0; it < graph.fanout(node); it++)
{
out_arc = graph.output(node, it);
if (*out_arc==lastBetResult)
{
nextNODE=graph.arc_to(out_arc);
fout << "for node: " << *node << " next selected node: " << *nextNODE << " if " << lastBetResult << " " << lastBetResult_ch << endl;
}
}
return (nextNODE);
}//getNextNode
static void hD_traverse (const digraph<string,int>& graph)
{
fout << "***********************************>>>>>>>>>>>>>>>" << endl;
digraph<string,int>::const_iterator theNextNode;
for (digraph<string,int>::const_iterator thisNode = graph.begin(); thisNode!= graph.end(); thisNode++)
{
fout << " " << *thisNode << " is a node, " << endl;
theNextNode=getNextNode(graph, thisNode, WON);
fout << "theNextNode " << *theNextNode << endl;
theNextNode=getNextNode(graph, thisNode, LOSS);
fout << "theNextNode " << *theNextNode << endl;
}//for
fout << "... END hD_traverse" << endl;
}//hD_traverse
int main(int argc, char* argv[])
{
digraph<string,int> graph;
hD_initGraph(graph);
hD_traverse(graph);
}