本文整理汇总了C#中OrderedBag.GetFirst方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.GetFirst方法的具体用法?C# OrderedBag.GetFirst怎么用?C# OrderedBag.GetFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.GetFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AStar
/// <summary>
/// AStar - Performs the A* algorithm search to find a
/// solution of a given BoardNode.
/// </summary>
/// <param name="root">BoardNode to find a solution for</param>
/// <returns>BoardNode containing the solution. NULL if no solution found</returns>
public static BoardNode AStar(BoardNode root)
{
BoardNode current = root;
Comparison<BoardNode> compare = new Comparison<BoardNode>(compareFScore);
OrderedBag<BoardNode> openList = new OrderedBag<BoardNode>(compare);
OrderedBag<BoardNode> closedList = new OrderedBag<BoardNode>(compare);
int curGScore;
int heuristic;
curGScore = 0;
heuristic = current.board.numRemainingLights();
current.gScore = curGScore;
current.fScore = (curGScore + heuristic);
openList.Add(current);
while(openList.Count != 0)
{
current = openList.GetFirst();
if(current.clicked.Capacity >= 100000)
{
return null;
}
if(current.board.solved())
{
return current;
}
openList.Remove(current);
closedList.Add(current);
addChildren(current);
foreach (BoardNode child in current.children)
{
if (closedList.Contains(child))
{
;
}
else
{
curGScore = current.gScore + 1;
if (openList.Contains(child) == false || curGScore < child.gScore)
{
child.gScore = (curGScore);
heuristic = child.board.numRemainingLights();
child.fScore = (curGScore + heuristic);
if (openList.Contains(child) == false)
{
openList.Add(child);
}
}
}
}
}
return null;
}