Which data structure for representing possible navigations between a game’s screens?

I am trying to find an appropriate data structure for representing available navigations between a game’s screens.

  • Using a linked list, a node can only have one node after it : inappropriate.

  • Using a tree seems up to the job as nodes can have many children nodes but it’s inconsistent in the sense that a supposedly children item Options can have a parent Title as a children. Also how am I supposed to represent the infinite sequence of the case Title -> Race -> Title -> Race … without endlessly repeating it in my tree ? Still, this is the best structure I found to accomplish the job.

Here is an example of the possible sequences :

  1. Title
    • Options
    • Race
  2. Options
    • Title
    • Race
  3. Race
    • Options
    • Title

Do you know whether a tree is the way to go or if there’s a better structure for this job ?


Edit:

There is a great library for creating graphs for C#/WPF : http://graphsharp.codeplex.com/

It uses http://quickgraph.codeplex.com/ internally.

Here’s a small example :

enter image description here

Code-behind:

using System.Collections.Generic;
using System.Windows;
using GraphSharp.Controls;
using QuickGraph;

namespace WpfApplication15graph
{
    internal class ScreenVertex
    {
        public string Hello { get; set; }
    }

    internal class ScreenEdge : Edge<ScreenVertex>
    {
        public ScreenEdge(ScreenVertex source, ScreenVertex target)
            : base(source, target)
        {
        }
    }

    internal class ScreenLayout : GraphLayout<ScreenVertex, ScreenEdge, ScreenGraph>
    {
    }

    internal class ScreenGraph : BidirectionalGraph<ScreenVertex, ScreenEdge>
    {
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // build graph
            var screenGraph = new ScreenGraph();
            var screenVertex1 = new ScreenVertex {Hello = "1"};
            var screenVertex2 = new ScreenVertex {Hello = "2"};
            var screenVertex3 = new ScreenVertex {Hello = "3"};
            screenGraph.AddVertex(screenVertex1);
            screenGraph.AddVertex(screenVertex2);
            screenGraph.AddVertex(screenVertex3);
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex2));
            screenGraph.AddEdge(new ScreenEdge(screenVertex2, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex3));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex2));
            ScreenLayout.Graph = screenGraph;

            // get connections for a particular vertex
            IEnumerable<ScreenEdge> inEdges = screenGraph.InEdges(screenVertex3);
            IEnumerable<ScreenEdge> outEdges = screenGraph.OutEdges(screenVertex3);
        }
    }
}

XAML :

<Window x:Class="WpfApplication15graph.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        xmlns:controls1="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:wpfApplication15Graph="clr-namespace:WpfApplication15graph"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <DataTemplate x:Key="SvTemplate" DataType="wpfApplication15Graph:ScreenVertex">
            <Grid>
                <TextBlock Text="{Binding Hello}" />
            </Grid>
        </DataTemplate>
        <Style TargetType="controls1:VertexControl">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls1:VertexControl">
                            <Border CornerRadius="5" Width="50" Height="50" Background="LightBlue">
                                <ContentPresenter Content="{TemplateBinding Vertex}"
                                                  ContentTemplate="{DynamicResource SvTemplate}" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>
    </Window.Resources>
    <Grid>
        <controls:ZoomControl>
            <wpfApplication15Graph:ScreenLayout x:Name="ScreenLayout"
                                                HighlightAlgorithmType="Simple"
                                                LayoutAlgorithmType="Circular"
                                                OverlapRemovalAlgorithmType="FSA" />
        </controls:ZoomControl>
    </Grid>
</Window>

2

You may want to consider a Directed Graph.

It’s similar to a tree, but with fewer restrictions. You just have nodes with one-way links between them. You can make the structure as clean/well-organized/neat/messy/chaotic as you wish.

Be careful if your menu system becomes complicated – DGs can get messy.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Which data structure for representing possible navigations between a game’s screens?

I am trying to find an appropriate data structure for representing available navigations between a game’s screens.

  • Using a linked list, a node can only have one node after it : inappropriate.

  • Using a tree seems up to the job as nodes can have many children nodes but it’s inconsistent in the sense that a supposedly children item Options can have a parent Title as a children. Also how am I supposed to represent the infinite sequence of the case Title -> Race -> Title -> Race … without endlessly repeating it in my tree ? Still, this is the best structure I found to accomplish the job.

Here is an example of the possible sequences :

  1. Title
    • Options
    • Race
  2. Options
    • Title
    • Race
  3. Race
    • Options
    • Title

Do you know whether a tree is the way to go or if there’s a better structure for this job ?


Edit:

There is a great library for creating graphs for C#/WPF : http://graphsharp.codeplex.com/

It uses http://quickgraph.codeplex.com/ internally.

Here’s a small example :

enter image description here

Code-behind:

using System.Collections.Generic;
using System.Windows;
using GraphSharp.Controls;
using QuickGraph;

namespace WpfApplication15graph
{
    internal class ScreenVertex
    {
        public string Hello { get; set; }
    }

    internal class ScreenEdge : Edge<ScreenVertex>
    {
        public ScreenEdge(ScreenVertex source, ScreenVertex target)
            : base(source, target)
        {
        }
    }

    internal class ScreenLayout : GraphLayout<ScreenVertex, ScreenEdge, ScreenGraph>
    {
    }

    internal class ScreenGraph : BidirectionalGraph<ScreenVertex, ScreenEdge>
    {
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // build graph
            var screenGraph = new ScreenGraph();
            var screenVertex1 = new ScreenVertex {Hello = "1"};
            var screenVertex2 = new ScreenVertex {Hello = "2"};
            var screenVertex3 = new ScreenVertex {Hello = "3"};
            screenGraph.AddVertex(screenVertex1);
            screenGraph.AddVertex(screenVertex2);
            screenGraph.AddVertex(screenVertex3);
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex2));
            screenGraph.AddEdge(new ScreenEdge(screenVertex2, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex3));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex2));
            ScreenLayout.Graph = screenGraph;

            // get connections for a particular vertex
            IEnumerable<ScreenEdge> inEdges = screenGraph.InEdges(screenVertex3);
            IEnumerable<ScreenEdge> outEdges = screenGraph.OutEdges(screenVertex3);
        }
    }
}

XAML :

<Window x:Class="WpfApplication15graph.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        xmlns:controls1="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:wpfApplication15Graph="clr-namespace:WpfApplication15graph"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <DataTemplate x:Key="SvTemplate" DataType="wpfApplication15Graph:ScreenVertex">
            <Grid>
                <TextBlock Text="{Binding Hello}" />
            </Grid>
        </DataTemplate>
        <Style TargetType="controls1:VertexControl">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls1:VertexControl">
                            <Border CornerRadius="5" Width="50" Height="50" Background="LightBlue">
                                <ContentPresenter Content="{TemplateBinding Vertex}"
                                                  ContentTemplate="{DynamicResource SvTemplate}" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>
    </Window.Resources>
    <Grid>
        <controls:ZoomControl>
            <wpfApplication15Graph:ScreenLayout x:Name="ScreenLayout"
                                                HighlightAlgorithmType="Simple"
                                                LayoutAlgorithmType="Circular"
                                                OverlapRemovalAlgorithmType="FSA" />
        </controls:ZoomControl>
    </Grid>
</Window>

2

You may want to consider a Directed Graph.

It’s similar to a tree, but with fewer restrictions. You just have nodes with one-way links between them. You can make the structure as clean/well-organized/neat/messy/chaotic as you wish.

Be careful if your menu system becomes complicated – DGs can get messy.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Which data structure for representing possible navigations between a game’s screens?

I am trying to find an appropriate data structure for representing available navigations between a game’s screens.

  • Using a linked list, a node can only have one node after it : inappropriate.

  • Using a tree seems up to the job as nodes can have many children nodes but it’s inconsistent in the sense that a supposedly children item Options can have a parent Title as a children. Also how am I supposed to represent the infinite sequence of the case Title -> Race -> Title -> Race … without endlessly repeating it in my tree ? Still, this is the best structure I found to accomplish the job.

Here is an example of the possible sequences :

  1. Title
    • Options
    • Race
  2. Options
    • Title
    • Race
  3. Race
    • Options
    • Title

Do you know whether a tree is the way to go or if there’s a better structure for this job ?


Edit:

There is a great library for creating graphs for C#/WPF : http://graphsharp.codeplex.com/

It uses http://quickgraph.codeplex.com/ internally.

Here’s a small example :

enter image description here

Code-behind:

using System.Collections.Generic;
using System.Windows;
using GraphSharp.Controls;
using QuickGraph;

namespace WpfApplication15graph
{
    internal class ScreenVertex
    {
        public string Hello { get; set; }
    }

    internal class ScreenEdge : Edge<ScreenVertex>
    {
        public ScreenEdge(ScreenVertex source, ScreenVertex target)
            : base(source, target)
        {
        }
    }

    internal class ScreenLayout : GraphLayout<ScreenVertex, ScreenEdge, ScreenGraph>
    {
    }

    internal class ScreenGraph : BidirectionalGraph<ScreenVertex, ScreenEdge>
    {
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // build graph
            var screenGraph = new ScreenGraph();
            var screenVertex1 = new ScreenVertex {Hello = "1"};
            var screenVertex2 = new ScreenVertex {Hello = "2"};
            var screenVertex3 = new ScreenVertex {Hello = "3"};
            screenGraph.AddVertex(screenVertex1);
            screenGraph.AddVertex(screenVertex2);
            screenGraph.AddVertex(screenVertex3);
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex2));
            screenGraph.AddEdge(new ScreenEdge(screenVertex2, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex3));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex2));
            ScreenLayout.Graph = screenGraph;

            // get connections for a particular vertex
            IEnumerable<ScreenEdge> inEdges = screenGraph.InEdges(screenVertex3);
            IEnumerable<ScreenEdge> outEdges = screenGraph.OutEdges(screenVertex3);
        }
    }
}

XAML :

<Window x:Class="WpfApplication15graph.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        xmlns:controls1="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:wpfApplication15Graph="clr-namespace:WpfApplication15graph"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <DataTemplate x:Key="SvTemplate" DataType="wpfApplication15Graph:ScreenVertex">
            <Grid>
                <TextBlock Text="{Binding Hello}" />
            </Grid>
        </DataTemplate>
        <Style TargetType="controls1:VertexControl">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls1:VertexControl">
                            <Border CornerRadius="5" Width="50" Height="50" Background="LightBlue">
                                <ContentPresenter Content="{TemplateBinding Vertex}"
                                                  ContentTemplate="{DynamicResource SvTemplate}" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>
    </Window.Resources>
    <Grid>
        <controls:ZoomControl>
            <wpfApplication15Graph:ScreenLayout x:Name="ScreenLayout"
                                                HighlightAlgorithmType="Simple"
                                                LayoutAlgorithmType="Circular"
                                                OverlapRemovalAlgorithmType="FSA" />
        </controls:ZoomControl>
    </Grid>
</Window>

2

You may want to consider a Directed Graph.

It’s similar to a tree, but with fewer restrictions. You just have nodes with one-way links between them. You can make the structure as clean/well-organized/neat/messy/chaotic as you wish.

Be careful if your menu system becomes complicated – DGs can get messy.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Which data structure for representing possible navigations between a game’s screens?

I am trying to find an appropriate data structure for representing available navigations between a game’s screens.

  • Using a linked list, a node can only have one node after it : inappropriate.

  • Using a tree seems up to the job as nodes can have many children nodes but it’s inconsistent in the sense that a supposedly children item Options can have a parent Title as a children. Also how am I supposed to represent the infinite sequence of the case Title -> Race -> Title -> Race … without endlessly repeating it in my tree ? Still, this is the best structure I found to accomplish the job.

Here is an example of the possible sequences :

  1. Title
    • Options
    • Race
  2. Options
    • Title
    • Race
  3. Race
    • Options
    • Title

Do you know whether a tree is the way to go or if there’s a better structure for this job ?


Edit:

There is a great library for creating graphs for C#/WPF : http://graphsharp.codeplex.com/

It uses http://quickgraph.codeplex.com/ internally.

Here’s a small example :

enter image description here

Code-behind:

using System.Collections.Generic;
using System.Windows;
using GraphSharp.Controls;
using QuickGraph;

namespace WpfApplication15graph
{
    internal class ScreenVertex
    {
        public string Hello { get; set; }
    }

    internal class ScreenEdge : Edge<ScreenVertex>
    {
        public ScreenEdge(ScreenVertex source, ScreenVertex target)
            : base(source, target)
        {
        }
    }

    internal class ScreenLayout : GraphLayout<ScreenVertex, ScreenEdge, ScreenGraph>
    {
    }

    internal class ScreenGraph : BidirectionalGraph<ScreenVertex, ScreenEdge>
    {
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // build graph
            var screenGraph = new ScreenGraph();
            var screenVertex1 = new ScreenVertex {Hello = "1"};
            var screenVertex2 = new ScreenVertex {Hello = "2"};
            var screenVertex3 = new ScreenVertex {Hello = "3"};
            screenGraph.AddVertex(screenVertex1);
            screenGraph.AddVertex(screenVertex2);
            screenGraph.AddVertex(screenVertex3);
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex2));
            screenGraph.AddEdge(new ScreenEdge(screenVertex2, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex1, screenVertex3));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex1));
            screenGraph.AddEdge(new ScreenEdge(screenVertex3, screenVertex2));
            ScreenLayout.Graph = screenGraph;

            // get connections for a particular vertex
            IEnumerable<ScreenEdge> inEdges = screenGraph.InEdges(screenVertex3);
            IEnumerable<ScreenEdge> outEdges = screenGraph.OutEdges(screenVertex3);
        }
    }
}

XAML :

<Window x:Class="WpfApplication15graph.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        xmlns:controls1="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:wpfApplication15Graph="clr-namespace:WpfApplication15graph"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <DataTemplate x:Key="SvTemplate" DataType="wpfApplication15Graph:ScreenVertex">
            <Grid>
                <TextBlock Text="{Binding Hello}" />
            </Grid>
        </DataTemplate>
        <Style TargetType="controls1:VertexControl">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls1:VertexControl">
                            <Border CornerRadius="5" Width="50" Height="50" Background="LightBlue">
                                <ContentPresenter Content="{TemplateBinding Vertex}"
                                                  ContentTemplate="{DynamicResource SvTemplate}" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>
    </Window.Resources>
    <Grid>
        <controls:ZoomControl>
            <wpfApplication15Graph:ScreenLayout x:Name="ScreenLayout"
                                                HighlightAlgorithmType="Simple"
                                                LayoutAlgorithmType="Circular"
                                                OverlapRemovalAlgorithmType="FSA" />
        </controls:ZoomControl>
    </Grid>
</Window>

2

You may want to consider a Directed Graph.

It’s similar to a tree, but with fewer restrictions. You just have nodes with one-way links between them. You can make the structure as clean/well-organized/neat/messy/chaotic as you wish.

Be careful if your menu system becomes complicated – DGs can get messy.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật