本文整理汇总了C#中OrderedBag.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.Contains方法的具体用法?C# OrderedBag.Contains怎么用?C# OrderedBag.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPath
public IEnumerable<Point> FindPath(Point start, Point goal)
{
var startNode = Map[start.Row][start.Column];
var targetNode = Map[goal.Row][goal.Column];
var openNodes = new OrderedBag<Node>(PathComparison);
var closedNodes = new HashSet<Node>();
openNodes.Add(startNode);
while (openNodes.Count > 0)
{
var currentNode = openNodes.RemoveFirst();
closedNodes.Add(currentNode);
if (currentNode == targetNode)
{
return tracePath(targetNode);
}
var neighbours = getNeighbours(currentNode);
foreach (var neighbour in neighbours)
{
if (!neighbour.IsWalkable || closedNodes.Contains(neighbour))
{
continue;
}
var newCost = currentNode.GainedCost + getCost(currentNode, neighbour);
if (newCost < neighbour.GainedCost || !openNodes.Contains(neighbour))
{
neighbour.GainedCost = newCost;
neighbour.HeuristicCost = getDistance(neighbour, targetNode);
neighbour.Parent = currentNode;
if (!openNodes.Contains(neighbour))
{
openNodes.Add(neighbour);
}
}
}
}
//a path doesn't exist
return new List<Point>();
}
示例2: 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;
}
示例3: Main
static void Main()
{
OrderedBag<int> newBag = new OrderedBag<int>();
OrderedBag<int> newBag2 = new OrderedBag<int>();
OrderedBag<int> newBag3 = new OrderedBag<int>();
OrderedBag<int> newOrderedBag = new OrderedBag<int>();
OrderedBag<int> newOrderedBag2 = new OrderedBag<int>();
OrderedBag<int> newOrderedBag3 = new OrderedBag<int>();
for (int i = 4; i >= 0; i--)
{
newBag2.Add(numbers[i]);
newOrderedBag2.Add(numbers[i]);
}
for (int i = 5; i < 10; i++)
{
newBag.Add(numbers[i]);
newBag2.Add(numbers[i]);
newOrderedBag.Add(numbers[i]);
newOrderedBag2.Add(numbers[i]);
}
newBag3 = newBag2.Union(newBag);
Console.WriteLine("Union of 6-10 & 1-10 :");
Console.WriteLine("Unordered:");
Console.WriteLine();
foreach (int a in newBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Ordered:");
Console.WriteLine();
foreach (int a in newOrderedBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Adding 9-14 to ordered and unordered list.");
newBag2.Add(12);
newBag2.Add(10);
newBag2.Add(11);
newBag2.Add(14);
newBag2.Add(13);
newBag2.Add(9);
newOrderedBag2.Add(12);
newOrderedBag2.Add(10);
newOrderedBag2.Add(11);
newOrderedBag2.Add(14);
newOrderedBag2.Add(13);
newOrderedBag2.Add(9);
Console.WriteLine();
Console.WriteLine("Unordered Contains 23? : " + newBag3.Contains(23));
Console.WriteLine("Ordered Contains 23? : " + newOrderedBag3.Contains(23));
Console.WriteLine();
newBag3 = newBag.Intersection(newBag2);
newOrderedBag3 = newOrderedBag.Intersection(newOrderedBag2);
Console.WriteLine("Intersection of 6-10 & 1-10 :");
Console.WriteLine();
Console.WriteLine("Unordsered:");
Console.WriteLine();
foreach (int a in newBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Ordered:");
Console.WriteLine();
foreach (int a in newOrderedBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Unordered Contains 6? : " + newBag3.Contains(6));
Console.WriteLine();
Console.WriteLine("Ordered Contains 6? : " + newOrderedBag3.Contains(6));
Console.WriteLine();
newBag3.Remove(6);
newOrderedBag3.Remove(6);
Console.WriteLine();
Console.WriteLine("After removing 6, does unordered bag contain 6? : " + newBag3.Contains(6));
Console.WriteLine();
Console.WriteLine("After removing 6, does ordered bag contain 6? : " + newBag3.Contains(6));
}