Пример #1
0
        public float GetInfluence(LocationRecord locationRecord)
        {
            LocationRecord mapRecord = this.Closed.SearchInClosed(locationRecord);

            if (mapRecord == null) return 0.0f;
            else return mapRecord.Influence;
        }
Пример #2
0
 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));
 }
Пример #3
0
 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)));
 }
Пример #4
0
 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;
 }
Пример #5
0
 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;
 }
Пример #6
0
 public LocationRecord SearchInClosed(LocationRecord nodeRecord)
 {
     if (this.Closed.ContainsKey(nodeRecord.Location))
     {
         return this.Closed[nodeRecord.Location];
     }
     else return null;
 }
Пример #7
0
 public LocationRecord SearchInClosed(LocationRecord nodeRecord)
 {
     if (this.Closed.ContainsKey(nodeRecord.Location))
     {
         return(this.Closed[nodeRecord.Location]);
     }
     else
     {
         return(null);
     }
 }
Пример #8
0
 public void RemoveFromClosed(LocationRecord nodeRecord)
 {
     this.Closed.Remove(nodeRecord.Location);
 }
Пример #9
0
 public void AddToOpen(LocationRecord nodeRecord)
 {
     this.NodeRecords.Add(nodeRecord);
 }
Пример #10
0
        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;
        }
Пример #11
0
 public void AddToClosed(LocationRecord nodeRecord)
 {
     this.Closed.Add(nodeRecord.Location, nodeRecord);
 }
Пример #12
0
        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;
            }
        }
Пример #13
0
        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;
        }
Пример #14
0
        //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;
        }
Пример #15
0
        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);
        }
Пример #16
0
 public int CompareTo(LocationRecord other)
 {
     return(other.Influence.CompareTo(this.Influence));
 }
Пример #17
0
 public int CompareTo(LocationRecord other)
 {
     return other.Influence.CompareTo(this.Influence);
 }
Пример #18
0
 public void RemoveFromOpen(LocationRecord nodeRecord)
 {
     this.NodeRecords.Remove(nodeRecord);
 }
Пример #19
0
 public void RemoveFromOpen(LocationRecord nodeRecord)
 {
     this.NodeRecords.Remove(nodeRecord);
 }
Пример #20
0
 public void AddToOpen(LocationRecord nodeRecord)
 {
     this.NodeRecords.Add(nodeRecord);
 }
Пример #21
0
 public void AddToClosed(LocationRecord nodeRecord)
 {
     this.Closed.Add(nodeRecord.Location,nodeRecord);
 }
Пример #22
0
 public void RemoveFromClosed(LocationRecord nodeRecord)
 {
     this.Closed.Remove(nodeRecord.Location);
 }