本文整理汇总了C#中WorldState.contains方法的典型用法代码示例。如果您正苦于以下问题:C# WorldState.contains方法的具体用法?C# WorldState.contains怎么用?C# WorldState.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldState
的用法示例。
在下文中一共展示了WorldState.contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public List<AStarNode> Run(AStarNode startNode, AStarNode endNode)
{
AStarNode currentNode = startNode;
//Debug.Log("************ASTAR RUNNING************");
//Specialfall för första noden eftersom den INTE är något action utan en postCondition, räknar med att den aldrig kommer va mål!!!
List<AStarNode> neighbourList = currentNode.GetNeighbours(true); //ger lista med actions som har startNodes preCondition
foreach(AStarNode node in neighbourList)
{
node.SetF(ActionManager.Instance.getAction(node.GetName()).cost + HeuristicCost(node, endNode));
node.SetParent(startNode);
openList.Add(node); //Lägg till grannarna för start i openList
}
//Ta ut nod med lägsta f ur openList
while(openList.Count > 0)
{
int lowInd = 0;
for(int i = 0; i < openList.Count; i++)
{
if(openList[i].GetF() < openList[lowInd].GetF())
{
lowInd = i;
}
}
currentNode = openList[lowInd];
openList.Remove(currentNode);
closedList.Add(currentNode);
//Debug.Log("currentNode är nu: " + currentNode.getName());
//Check if we have reached the target
if(ActionManager.Instance.getAction(currentNode.GetName()).preConditions.contains(endNode.GetWorldState()))
{
return CreatePath(currentNode, startNode);
}
List<List<AStarNode>> lists = new List<List<AStarNode>>();
foreach(KeyValuePair<string, WorldStateValue> pair in ActionManager.Instance.getAction(currentNode.GetName()).preConditions.getProperties())
{
//Debug.Log("GDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" + pair.Value.propertyValues["amount"]);
for(int j = 0; j < (int)pair.Value.propertyValues["amount"]; j++)
{
//Debug.Log ("IIIIIIIIIIIIII: " + j);
AStar astar2 = new AStar();
AStarNode tempNode = new AStarNode();
WorldState tempWorldState = new WorldState();
tempWorldState.setProperty(pair.Key, pair.Value);
tempNode.SetWorldState(tempWorldState);
List<AStarNode> tempList = new List<AStarNode>();
tempList.AddRange(astar2.Run(tempNode, endNode));
tempList[tempList.Count-1].SetParent(currentNode); //nyligen tillagd
//Debug.Log(".................." + tempList[0].getName() + " får parent " + currentNode.getName());
if(tempList.Count > 0)
{
lists.Add(tempList);
}
else
{
if(!tempWorldState.contains(endNode.GetWorldState()))
{
return new List<AStarNode>();
}
}
}
}
//Sort by cost to make the plan prioritize actions with small costs
lists.Sort((a, b) => ActionManager.Instance.getAction(a[0].GetName()).cost.CompareTo(ActionManager.Instance.getAction(b[0].GetName()).cost));
foreach(List<AStarNode> list in lists)
{
pathList.AddRange(list);
}
return CreatePath(currentNode, startNode);
neighbourList = currentNode.GetNeighbours(false);
//Debug.Log ("antal grannar: " + neighbourList.Count);
for(int i = 0; i < neighbourList.Count; i++)
{
//Debug.Log ("***********CurretnNode: " + currentNode.getName() + " neigbour " + neighbourList[i].getName());
AStarNode currentNeighbour = neighbourList[i];
if(closedList.Contains(currentNeighbour))
{
//not a valid node
continue;
}
if(!openList.Contains(currentNeighbour))
{
//Debug.Log("namnet på grannen: " + currentNeighbour.getName());
//Debug.Log("kontroll om currentneighbour inte finns i openlist: " + !openList.Contains(currentNeighbour));
//.........这里部分代码省略.........