当前位置: 首页>>代码示例>>C#>>正文


C# Grid.GetRandomCell方法代码示例

本文整理汇总了C#中Grid.GetRandomCell方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.GetRandomCell方法的具体用法?C# Grid.GetRandomCell怎么用?C# Grid.GetRandomCell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grid的用法示例。


在下文中一共展示了Grid.GetRandomCell方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: On

        public static Grid On(Grid grid)
        {
            var current = grid.GetRandomCell();

            while (current != null)
            {
                var unvisitedNeighbors = current.Neighbors.Where(n => !n.Links.Any());

                if (unvisitedNeighbors.Any())
                {
                    var neighbor = unvisitedNeighbors.Random();
                    current.Link(neighbor);
                    current = neighbor;
                }
                else
                {
                    current = null;

                    foreach (Cell cell in grid)
                    {
                        var visitedNeighbors = cell.Neighbors.Where(n => n.Links.Any());
                        if (!cell.Links.Any() && visitedNeighbors.Any())
                        {
                            current = cell;
                            var neighbor = visitedNeighbors.Random();
                            current.Link(neighbor);
                            break;
                        }
                    }
                }
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:34,代码来源:HuntAndKill.cs

示例2: On

        public static Grid On(Grid grid, Cell start = null)
        {
            if (start == null)
            {
                start = grid.GetRandomCell();
            }

            var active = new List<Cell>();
            active.Add(start);

            while(active.Any())
            {
                var cell = active.Last();
                var neighbors = cell.Neighbors.Where(n => !n.Links.Any());

                if (neighbors.Any())
                {
                    var neighbor = neighbors.Random();
                    cell.Link(neighbor);
                    active.Add(neighbor);
                }
                else
                {
                    active.Remove(cell);
                }
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:29,代码来源:GrowingTree.cs

示例3: On

        public static Grid On(Grid grid, Cell start = null)
        {
            if (start == null)
            {
                start = grid.GetRandomCell();
            }

            var stack = new Stack<Cell>();
            stack.Push(start);

            while(stack.Any())
            {
                var current = stack.Peek();
                var neighbors = current.Neighbors.Where(n => !n.Links.Any());

                if (neighbors.Any())
                {
                    var neighbor = neighbors.Random();
                    current.Link(neighbor);
                    stack.Push(neighbor);
                }
                else
                {
                    stack.Pop();
                }
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:29,代码来源:RecursiveBacktracker.cs

示例4: On

        public static Grid On(Grid grid)
        {
            var cell = grid.GetRandomCell();
            var unvisited = grid.Count() - 1;

            while (unvisited > 0)
            {
                var neighbor = cell.Neighbors.Random();

                if (!neighbor.Links.Any())
                {
                    cell.Link(neighbor);
                    unvisited--;
                }

                cell = neighbor;
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:20,代码来源:AldousBroder.cs


注:本文中的Grid.GetRandomCell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。