public float GetInfluence(LocationRecord locationRecord) { LocationRecord mapRecord = this.Closed.SearchInClosed(locationRecord); if (mapRecord == null) return 0.0f; else return mapRecord.Influence; }
public LocationRecord SearchInOpen(LocationRecord nodeRecord) { //here I cannot use the == comparer because the nodeRecord will likely be a different computational object //and therefore pointer comparison will not work, we need to use Equals //LINQ with a lambda expression return this.NodeRecords.FirstOrDefault(n => n.Equals(nodeRecord)); }
public LocationRecord SearchInOpen(LocationRecord nodeRecord) { //here I cannot use the == comparer because the nodeRecord will likely be a different computational object //and therefore pointer comparison will not work, we need to use Equals //LINQ with a lambda expression return(this.NodeRecords.FirstOrDefault(n => n.Equals(nodeRecord))); }
public void Replace(LocationRecord nodeToBeReplaced, LocationRecord nodeToReplace) { //since the list is not ordered we do not need to remove the node and add the new one, just copy the different values //remember that if NodeRecord is a struct, for this to work we need to receive a reference nodeToBeReplaced.Parent = nodeToReplace.Parent; nodeToBeReplaced.Influence = nodeToReplace.Influence; nodeToBeReplaced.StrongestInfluenceUnit = nodeToReplace.StrongestInfluenceUnit; }
public void Replace(LocationRecord nodeToBeReplaced, LocationRecord nodeToReplace) { //since the list is not ordered we do not need to remove the node and add the new one, just copy the different values //remember that if NodeRecord is a struct, for this to work we need to receive a reference nodeToBeReplaced.Parent = nodeToReplace.Parent; nodeToBeReplaced.Influence = nodeToReplace.Influence; nodeToBeReplaced.StrongestInfluenceUnit = nodeToReplace.StrongestInfluenceUnit; }
public LocationRecord SearchInClosed(LocationRecord nodeRecord) { if (this.Closed.ContainsKey(nodeRecord.Location)) { return this.Closed[nodeRecord.Location]; } else return null; }
public LocationRecord SearchInClosed(LocationRecord nodeRecord) { if (this.Closed.ContainsKey(nodeRecord.Location)) { return(this.Closed[nodeRecord.Location]); } else { return(null); } }
public void RemoveFromClosed(LocationRecord nodeRecord) { this.Closed.Remove(nodeRecord.Location); }
public void AddToOpen(LocationRecord nodeRecord) { this.NodeRecords.Add(nodeRecord); }
public void Initialize(List<IInfluenceUnit> units) { this.Open.Initialize(); this.Closed.Initialize(); this.Units = units; foreach (var unit in units) { //I need to do this because in Recast NavMesh graph, the edges of polygons are considered to be nodes and not the connections. //Theoretically the Quantize method should then return the appropriate edge, but instead it returns a polygon //Therefore, we need to create one explicit connection between the polygon and each edge of the corresponding polygon for the search algorithm to work ((NavMeshPoly)unit.Location).AddConnectedPoly(unit.Location.Position); var locationRecord = new LocationRecord { Influence = unit.DirectInfluence, StrongestInfluenceUnit = unit, Location = unit.Location }; Open.AddToOpen(locationRecord); } this.InProgress = true; }
public void AddToClosed(LocationRecord nodeRecord) { this.Closed.Add(nodeRecord.Location, nodeRecord); }
public void ProcessInfluenceRecord(LocationRecord locationRecord) { float redInfluence = this.RedInfluenceMap.GetInfluence(locationRecord); float greenInfluence = this.GreenInfluenceMap.GetInfluence(locationRecord); float resourcesInfluence = this.ResourceInfluenceMap.GetInfluence(locationRecord); float security = redInfluence - greenInfluence; if ((security <= 0.0f) && (greenInfluence <= redInfluence)) { security = 1.0f; } float combinedInfluence = (security * resourcesInfluence) / (redInfluence + 1.0f); this.CombinedInfluence.Add(locationRecord, combinedInfluence); if (combinedInfluence > this.BestCombinedInfluence) { this.BestCombinedInfluence = combinedInfluence; this.BestFlagPosition = locationRecord.Location.Position; } }
public float GetInfluence(NavigationGraphNode node) { LocationRecord locationRecord = new LocationRecord(); locationRecord.Location = node; LocationRecord mapRecord = this.Closed.SearchInClosed(locationRecord); if (mapRecord == null) return 0.0f; else return mapRecord.Influence; }
//this method should return true if it finished processing, and false if it still needs to continue public bool MapFloodDijkstra() { var processedNodes = 0; while (this.Open.CountOpen() > 0) { if(processedNodes > this.NodesPerFlood) { this.InProgress = true; return false; } LocationRecord currentRecord = this.Open.GetBestAndRemove(); this.Closed.AddToClosed(currentRecord); processedNodes++; var outConnections = currentRecord.Location.OutEdgeCount; for (int i = 0; i < outConnections; i++) { LocationRecord child = new LocationRecord(); child.Location = currentRecord.Location.EdgeOut(i).ToNode; this.ProcessChildNode(currentRecord, child); } } this.InProgress = false; // this.CleanUp(); return true; }
protected void ProcessChildNode(LocationRecord bestRecord, LocationRecord child) { float influence = this.InfluenceFunction.DetermineInfluence(bestRecord.StrongestInfluenceUnit, child.Location.Position); if (influence < this.InfluenceThreshold) return; LocationRecord neighborRecord = this.Closed.SearchInClosed(child); if(neighborRecord != null) { if (neighborRecord.Influence >= influence) return; else this.Closed.RemoveFromClosed(neighborRecord); } else { neighborRecord = this.Open.SearchInOpen(child); if(neighborRecord != null) { if(neighborRecord.Influence < influence) { neighborRecord.StrongestInfluenceUnit = bestRecord.StrongestInfluenceUnit; neighborRecord.Influence = influence; } return; } else { neighborRecord = child; } } neighborRecord.StrongestInfluenceUnit = bestRecord.StrongestInfluenceUnit; neighborRecord.Influence = influence; this.Open.AddToOpen(neighborRecord); }
public int CompareTo(LocationRecord other) { return(other.Influence.CompareTo(this.Influence)); }
public int CompareTo(LocationRecord other) { return other.Influence.CompareTo(this.Influence); }
public void RemoveFromOpen(LocationRecord nodeRecord) { this.NodeRecords.Remove(nodeRecord); }
public void RemoveFromOpen(LocationRecord nodeRecord) { this.NodeRecords.Remove(nodeRecord); }
public void AddToOpen(LocationRecord nodeRecord) { this.NodeRecords.Add(nodeRecord); }
public void AddToClosed(LocationRecord nodeRecord) { this.Closed.Add(nodeRecord.Location,nodeRecord); }
public void RemoveFromClosed(LocationRecord nodeRecord) { this.Closed.Remove(nodeRecord.Location); }