本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}