本文整理汇总了C#中OrderedBag.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.Clear方法的具体用法?C# OrderedBag.Clear怎么用?C# OrderedBag.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeNextActions
private void ComputeNextActions()
{
float goalDestinationX = player.Location.X + 983;
HashSet<int> visited = new HashSet<int>();
orderedSet = new OrderedBag<PlayerNode>((a, b) => a.Destination((int)goalDestinationX).CompareTo(b.Destination((int)goalDestinationX)));
PlayerNode initialNode = new PlayerNode(null, sceneTime, 0, PlayerAction.None, player.Clone(), 0);
orderedSet.Add(initialNode);
visited.Add((int)initialNode.PlayerElement.Location.X << 10 + (int)initialNode.PlayerElement.Location.Y);
PlayerNode bestNode = initialNode;
bool foundBest = false;
while (orderedSet.Count > 0 && !foundBest)
{
PlayerNode current = orderedSet.RemoveFirst();
if (current.PlayerElement.IsOnGround() && bestNode.Destination((int)goalDestinationX) > current.Destination((int)goalDestinationX))
{
bestNode = current;
}
foreach (PlayerAction action in possibleActions)
{
if (action == PlayerAction.Jump && !current.PlayerElement.IsOnGround())
{
continue;
}
PlayerElement newPlayer = current.PlayerElement.Clone();
newPlayer.IsPlayerAGoat = true;
switch (action)
{
case PlayerAction.None:
newPlayer.Stop();
break;
case PlayerAction.MoveRight:
newPlayer.MoveForward();
break;
case PlayerAction.MoveLeft:
newPlayer.MoveBackward();
break;
case PlayerAction.Jump:
newPlayer.Jump();
break;
}
GameTime newTime = IncrementTime(current.Time);
newPlayer.Update(newTime);
Parallel.ForEach(timeDependentElements, element => element.Update(newTime));
HandleInteraction(newPlayer);
if (newPlayer.IsDead)
{
continue;
}
int hash = ((int)(newPlayer.Location.X * 10) << 7) + (int)newPlayer.Location.Y;
if (!visited.Add(hash))
{
continue;
}
PlayerNode newNode = new PlayerNode(current, newTime, current.Moves + 1, action, newPlayer, current.Jumps + (action == PlayerAction.Jump ? 1 : 0));
if (newPlayer.Location.X > goalDestinationX && newPlayer.IsOnGround() || newPlayer.HasWon)
{
bestNode = newNode;
foundBest = true;
break;
}
orderedSet.Add(newNode);
}
}
orderedSet.Clear();
if (bestNode == initialNode)
{
pendingActions.Enqueue(PlayerAction.None);
}
else
{
GetActionsFromNode(bestNode);
}
}