示例#1
0
        public void start(Board board, Agent agent, Territory start, Territory finish)
        {
            // must create a path from start territory to finish territory
            TerritoryList territories = board.Territories;

            OpenSet.Add(new StarTile(start.Name, start));

            Dictionary<string, int> sldMap = CalculateSLD(finish.Name);

            // loop through A* steps until goal is reached
            while (!IsGoalFound)
            {
                StarTile current = GetMinFValue();

                // there are no more members of the OpenSet to examine
                if(current == null)
                {
                    break;
                }

                // current territory is finish territory
                if(current.Id == finish.Name)
                {
                    // do something?
                }

                List<StarTile> frontier = GetFrontier(current);

                // loop through frontier and calculate heuristic for current territory
                foreach(StarTile t in frontier)
                {
                    // associate frontier territory to parent tile
                    t.Parent = current; // is this really necessary since we do it below?

                    // enemy territories are considered empty tiles, available to be conquered
                    if(t.Territory.Owner != current.Territory.Owner)
                    {
                        CalculateHeuristic(t, start, finish);

                        t.Parent = current;
                    }
                    
                    // goal territory is reached
                    else if(t.Territory.Name == finish.Name)
                    {
                        t.Parent = current;

                        IsGoalFound = true;

                        Path = ConstructPath(t);
                    }

                    // self owned territory, seen as obstacle because it is already
                    else if(t.Territory.Owner == current.Territory.Owner)
                    {
                        // do not need to calculate anything, just skip
                    }
                }
            }
        }
示例#2
0
 public BfsTile(string id, Territory territory)
 {
     Id = id;
     Territory = territory;
     Parent = null;
     Distance = 0;
 }
示例#3
0
 public StarTile(string id, Territory territory)
 {
     Id = id;
     Territory = territory;
     Parent = null;
     HValue = 0;
     GValue = 0;
     FValue = 0;
 }
示例#4
0
 /// <summary>
 /// Adds a new node to the graph.
 /// </summary>
 /// <param name="key">The key value of the node to add.</param>
 /// <param name="data">The data of the node to add.</param>
 /// <returns>A reference to the Territory that was created and added to the graph.</returns>
 /// <remarks>If there already exists a node in the graph with the same <b>key</b> value then an
 /// <b>ArgumentException</b> exception will be thrown.</remarks>
 public virtual Territory AddNode(Territory t)
 {
     // Make sure the key is unique
     if (!territories.ContainsKey(t.Name))
     {
         territories.Add(t);
         return t;
     }
     else
         throw new ArgumentException("There already exists a node in the graph with name " + t.Name);
 }
示例#5
0
 private void CalculateHeuristic(StarTile tile, Territory start, Territory finish, Dictionary<string,int> sldMap)
 {
     if (tile.Parent != null)
     {
         tile.GValue = tile.Parent.GValue + 1;
         tile.HValue = sldMap[tile.Id];
         tile.FValue = tile.GValue + tile.HValue;
     }
 }
示例#6
0
		/// <summary>
		/// Removes a Territory from the NodeList.
		/// </summary>
		public virtual Territory Remove(Territory t)
		{
            Territory removed = (Territory) data[t.Name];
			data.Remove(t.Name);
            return removed;
		}
示例#7
0
		/// <summary>
		/// Adds a new Territory to the NodeList.
		/// </summary>
		public virtual void Add(Territory t)
		{
			data.Add(t.Name, t);
		}
示例#8
0
 /// <summary>
 /// Determines if a node exists within the graph.
 /// </summary>
 /// <param name="t">The node to check for in the graph.</param>
 /// <returns><b>True</b> if the node <b>n</b> exists in the graph, <b>False</b> otherwise.</returns>
 public virtual bool Contains(Territory t)
 {
     return ContainsTerritory(t.Name);
 }