@@ -559,62 +559,55 @@ GameNode gbtTreeLayout::NextSameLevel(const GameNode &p_node) const
559559 return nullptr ;
560560}
561561
562- int gbtTreeLayout::LayoutSubtree (const GameNode &p_node, const BehaviorSupportProfile &p_support,
563- int &p_maxy, int &p_miny, int &p_ycoord)
562+ void gbtTreeLayout::LayoutSubtree (const GameNode &p_node, const BehaviorSupportProfile &p_support,
563+ int &p_maxy, int &p_miny, int &p_ycoord)
564564{
565- int y1 = -1 , yn = 0 ;
566- const gbtStyle &settings = m_doc->GetStyle ();
565+ const auto &settings = m_doc->GetStyle ();
567566
568- auto entry = GetNodeEntry (p_node);
569- entry->SetNextMember (nullptr );
567+ const auto entry = GetNodeEntry (p_node);
570568 if (m_doc->GetStyle ().RootReachable () && p_node->GetInfoset () &&
571569 !p_node->GetInfoset ()->GetPlayer ()->IsChance ()) {
572- const GameInfoset infoset = p_node->GetInfoset ();
573- for (auto action : p_support.GetActions (infoset)) {
574- yn = LayoutSubtree (p_node->GetChild (action), p_support, p_maxy, p_miny, p_ycoord);
575- if (y1 == -1 ) {
576- y1 = yn;
570+ const auto actions = p_support.GetActions (p_node->GetInfoset ());
571+ for (const auto &action : actions) {
572+ LayoutSubtree (p_node->GetChild (action), p_support, p_maxy, p_miny, p_ycoord);
573+ }
574+ entry->m_y = (GetNodeEntry (p_node->GetChild (actions.front ()))->m_y +
575+ GetNodeEntry (p_node->GetChild (actions.back ()))->m_y ) /
576+ 2 ;
577+ }
578+ else if (!p_node->IsTerminal ()) {
579+ const auto actions = p_node->GetInfoset ()->GetActions ();
580+ for (const auto &action : actions) {
581+ const auto child = p_node->GetChild (action);
582+ LayoutSubtree (child, p_support, p_maxy, p_miny, p_ycoord);
583+ if (!p_node->GetPlayer ()->IsChance () && !p_support.Contains (action)) {
584+ GetNodeEntry (child)->m_inSupport = false ;
577585 }
578586 }
579- entry->m_y = (y1 + yn) / 2 ;
587+ entry->m_y = (GetNodeEntry (p_node->GetChild (actions.front ()))->m_y +
588+ GetNodeEntry (p_node->GetChild (actions.back ()))->m_y ) /
589+ 2 ;
580590 }
581591 else {
582- if (!p_node->IsTerminal ()) {
583- for (const auto &action : p_node->GetInfoset ()->GetActions ()) {
584- yn = LayoutSubtree (p_node->GetChild (action), p_support, p_maxy, p_miny, p_ycoord);
585- if (y1 == -1 ) {
586- y1 = yn;
587- }
588-
589- if (!p_node->GetPlayer ()->IsChance () && !p_support.Contains (action)) {
590- GetNodeEntry (p_node->GetChild (action))->m_inSupport = false ;
591- }
592- }
593- entry->m_y = (y1 + yn) / 2 ;
594- }
595- else {
596- entry->m_y = p_ycoord;
597- p_ycoord += settings.TerminalSpacing ();
598- }
592+ entry->m_y = p_ycoord;
593+ p_ycoord += settings.TerminalSpacing ();
599594 }
600595
601596 if (settings.GetBranchStyle () == GBT_BRANCH_STYLE_LINE) {
602597 entry->m_x =
603- c_leftMargin + entry->GetLevel () * (settings.NodeSize () + settings.GetBranchLength ());
598+ c_leftMargin + entry->GetLevel () * (settings.GetNodeSize () + settings.GetBranchLength ());
604599 }
605600 else {
606- entry->m_x = c_leftMargin +
607- entry->GetLevel () *
608- (settings. NodeSize () + settings. GetBranchLength () + settings.GetTineLength ());
601+ entry->m_x =
602+ c_leftMargin + entry->GetLevel () * (settings. GetNodeSize () + settings. GetBranchLength () +
603+ settings.GetTineLength ());
609604 }
610605
611- entry->SetSize ( settings.NodeSize () );
612- entry->SetBranchLength ( settings.GetBranchLength () );
606+ entry->m_size = settings.GetNodeSize ( );
607+ entry->m_branchLength = settings.GetBranchLength ();
613608
614609 p_maxy = std::max (entry->m_y , p_maxy);
615610 p_miny = std::min (entry->m_y , p_miny);
616-
617- return entry->m_y ;
618611}
619612
620613//
@@ -660,7 +653,7 @@ void gbtTreeLayout::CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &e)
660653 e->GetLevel () == e1 ->GetLevel () && e1 ->GetSublevel () > 0 ) {
661654 e->SetSublevel (e1 ->GetSublevel ());
662655 if (infoset_entry) {
663- e->SetNextMember ( infoset_entry) ;
656+ e->m_nextMember = infoset_entry;
664657 }
665658 return ;
666659 }
@@ -684,18 +677,18 @@ void gbtTreeLayout::CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &e)
684677 }
685678 num++;
686679 e->SetSublevel (num);
687- e->SetNextMember ( infoset_entry) ;
680+ e->m_nextMember = infoset_entry;
688681}
689682
690- void gbtTreeLayout::FillInfosetTable (const GameNode &n, const BehaviorSupportProfile &cur_sup )
683+ void gbtTreeLayout::FillInfosetTable (const GameNode &n, const BehaviorSupportProfile &p_support )
691684{
692685 const gbtStyle &draw_settings = m_doc->GetStyle ();
693686 auto entry = GetNodeEntry (n);
694687 if (!n->IsTerminal ()) {
695688 for (const auto &action : n->GetInfoset ()->GetActions ()) {
696- const bool in_sup = n->GetPlayer ()->IsChance () || cur_sup .Contains (action);
689+ const bool in_sup = n->GetPlayer ()->IsChance () || p_support .Contains (action);
697690 if (in_sup || !draw_settings.RootReachable ()) {
698- FillInfosetTable (n->GetChild (action), cur_sup );
691+ FillInfosetTable (n->GetChild (action), p_support );
699692 }
700693 }
701694 }
@@ -755,7 +748,9 @@ void gbtTreeLayout::Layout(const BehaviorSupportProfile &p_support)
755748
756749 const gbtStyle &draw_settings = m_doc->GetStyle ();
757750 if (draw_settings.GetInfosetConnect () != GBT_INFOSET_CONNECT_NONE) {
758- // FIXME! This causes lines to disappear... sometimes.
751+ std::for_each (
752+ m_nodeList.begin (), m_nodeList.end (),
753+ [](const std::shared_ptr<gbtNodeEntry> &p_entry) { p_entry->m_nextMember = nullptr ; });
759754 FillInfosetTable (m_doc->GetGame ()->GetRoot (), p_support);
760755 UpdateTableInfosets ();
761756 }
0 commit comments