Exemplo n.º 1
0
        //----------------------------------------------------------------------------
        //              Constructor
        //----------------------------------------------------------------------------

        public PathValue(int score_g, int heuristic, Vector3 centre, IHexagon hex, PathValue previous)
        {
            Score_g   = score_g;
            Heuristic = heuristic;
            Centre    = centre;
            Hex       = hex;
            Previous  = previous;
        }
Exemplo n.º 2
0
        //----------------------------------------------------------------------------
        //              Get Path Value
        //----------------------------------------------------------------------------

        /// <summary>
        /// GetPathValue checks if a hex has been visited before. <para/>
        /// If it has, return the original PathValue <para/>
        /// Otherwise, construct a new PathValue
        ///
        /// </summary>
        public IPathValue GetPathValue(IHexagon hex)
        {
            if (PathValueDict.ContainsKey(hex))
            {
                return(PathValueDict[hex]);
            }
            else
            {
                Vector3    centre = (Destination.HexTransform.position + Start.HexTransform.position) / 2;
                IPathValue myPath = new PathValue(400000, HexMath.FindDistance(hex, Destination), centre, hex, null);
                PathValueDict.Add(hex, myPath);
                return(myPath);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The path values have the path stored as a reverse linked list <para />
        /// This reverses it, and constructs a MapPath <para />
        /// MapPath is currently unimportant, but will hopefully allow ai to make good decisions with movement
        /// </summary>
        public MapPath ReconstructPath()
        {
            MapPath myMapPath = new MapPath();

            myMapPath.cost = Score_g;

            PathValue currentPath = this;

            while (currentPath != null)
            {
                myMapPath.PathStack.Push(currentPath.Hex);
                currentPath = currentPath.Previous;
            }

            return(myMapPath);
        }
Exemplo n.º 4
0
        //----------------------------------------------------------------------------
        //              IComparable
        //----------------------------------------------------------------------------

        #region IComparable
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            PathValue otherPathValue = (PathValue)obj;

            if (otherPathValue != null)
            {
                return(PathCompare(this, otherPathValue));
            }
            else
            {
                throw new ArgumentException("Object is not a PathValue");
            }
        }
Exemplo n.º 5
0
 private int PathCompare(PathValue a, PathValue b)
 {
     if (a.Score_f < b.Score_f)
     {
         return(-1);
     }
     else if (a.Score_f > b.Score_f)
     {
         return(1);
     }
     //here's where the euclidean distance comparison kicks in
     else if (Vector3.Distance(a.Hex.HexTransform.position, Centre) < Vector3.Distance(b.Hex.HexTransform.position, Centre))
     {
         return(-1);
     }
     else if (Vector3.Distance(a.Hex.HexTransform.position, Centre) > Vector3.Distance(b.Hex.HexTransform.position, Centre))
     {
         return(1);
     }
     else
     {
         return(Vec3IntExt.Vec3IntCompare(a.Hex.MyHexMap.CoOrds, b.Hex.MyHexMap.CoOrds));
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// If a shorter path to a hex is found <para/>
 /// You should update the path to it (previous), and the new cost to this node (score_g)
 /// </summary>
 /// <param name="score_g"></param>
 /// <param name="previous"></param>
 public void UpdateValues(int score_g, IPathValue previous)
 {
     Score_g  = score_g;
     Previous = (PathValue)previous;
 }