public void SetUnits(PriorityQueueMin <UnitType> playerUnits) { Transform unitPanel = transform.Find("UnitPurchasePanel"); int unitPlace = 0; foreach (UnitType unit in playerUnits) { unitPanel.GetChild(unitPlace).GetComponent <Image>().sprite = Resources.Load("UnitSprites/" + unit.SpriteName, typeof(Sprite)) as Sprite; AvailableUnitTypes.Add(unit); unitPlace++; } for (int i = unitPlace; i < 4; i++) { unitPanel.GetChild(i).GetComponent <Button>().interactable = false; } }
public static List <PathNode> ShortestPath(TerrainTile[,] terrainLayout, bool[,] obstructed, int startX, int startY, int goalX, int goalY) { int[,] distanceMatrix = new int[terrainLayout.GetLength(0), terrainLayout.GetLength(1)]; for (int i = 0; i < distanceMatrix.GetLength(0); i++) { for (int j = 0; j < distanceMatrix.GetLength(1); j++) { distanceMatrix[i, j] = -1; } } distanceMatrix[startX, startY] = 0; // Add start node PriorityQueueMin <Node> openSet = new PriorityQueueMin <Node>(); Node initial = new Node(startX, startY, 0, ManhattanDistance(startX, startY, goalX, goalY), terrainLayout[startX, startY].MoveGroup, 0); initial.MoveCost = 10; openSet.Insert(initial); while (!openSet.IsEmpty()) { Node current = openSet.DelMin(); if (current.x == goalX && current.y == goalY) { List <PathNode> path = new List <PathNode>(); while (current.Parent != null) { path.Add(new PathNode(current.MoveCost, new int[] { current.x, current.y })); current = current.Parent; } path.Reverse(); return(path); } // search all the neighbours List <Node> neighbours = current.generateNeighbours(terrainLayout, obstructed, distanceMatrix, goalX, goalY); openSet.InsertRange(neighbours); } // we failed to find the goal return(null); }
// Use this for initialization void Start() { Garrison = new List <Stack>(); ProductionUnits = new PriorityQueueMin <UnitType>(); }
public StackData() { Units = new PriorityQueueMin <Unit>(); }