Example #1
0
 public void AddPos(HexaPos pos)
 {
     if (false == HasPos(pos) && false == _allowDuplicate)
     {
         _set.Add(pos);
     }
 }
Example #2
0
        public bool Equals(HexaPos pos)
        {
            if (this._x == pos._x && this._y == pos._y)
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        public List <HexaPos> GetHexes(int x, int y, int radius, bool includeCenter = false)
        {
            List <HexaPos> hexes        = new List <HexaPos>();
            List <HexaPos> delta        = new List <HexaPos>();
            HexaPos        centerHexPos = new HexaPos(x, y);

            hexes.Add(centerHexPos);

            if (radius < 1)
            {
                return(hexes);
            }

            for (int i = 0; i < radius; i++)
            {
                List <HexaPos> .Enumerator e = hexes.GetEnumerator();

                delta.Clear();

                while (e.MoveNext())
                {
                    int refX = e.Current.X;
                    int refY = e.Current.Y;

                    for (int j = 0; j < directionList.Length; j++)
                    {
                        HexaPos next = GetNext(refX, refY, directionList[j]);

                        //Console.WriteLine(refX + " + " + refY + " -- " + directionList[j].ToString() + " = " + next.X + " + " + next.Y);

                        if (!hexes.Contains(next))
                        {
                            delta.Add(next);
                        }
                    }
                }

                e = delta.GetEnumerator();
                while (e.MoveNext())
                {
                    if (!hexes.Contains(e.Current))
                    {
                        hexes.Add(e.Current);
                    }
                }
            }

            if (!includeCenter)
            {
                hexes.Remove(centerHexPos);
            }

            return(hexes);
        }
Example #4
0
 public bool HasPos(HexaPos pos)
 {
     List <HexaPos> .Enumerator e = _set.GetEnumerator();
     while (e.MoveNext())
     {
         if (e.Current.X == pos.X && e.Current.Y == pos.Y)
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        public bool IsAccessible(HexaPos from, HexaPos to)
        {
            int directionLen = directionList.Length;

            for (int l = 0; l < directionLen; l++)
            {
                HexaPos nextPos = GetNext(from.X, from.Y, directionList[l]);
                if (to.X == nextPos.X && to.Y == nextPos.Y)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #6
0
        public int GetPosCnt(HexaPos pos)
        {
            int cnt = 0;

            List <HexaPos> .Enumerator e = _set.GetEnumerator();
            while (e.MoveNext())
            {
                if (e.Current.X == pos.X && e.Current.Y == pos.Y)
                {
                    cnt++;
                }
            }
            return(cnt);
        }
Example #7
0
 public void RemovePos(HexaPos pos)
 {
     List <HexaPos> .Enumerator e = _set.GetEnumerator();
     while (e.MoveNext())
     {
         if (e.Current.X == pos.X && e.Current.Y == pos.Y)
         {
             _set.Remove(e.Current);
             if (false == _allowDuplicate)
             {
                 return;
             }
         }
     }
 }
Example #8
0
        public HexaPos GetMaxPos(List <HexaPos> hexes)
        {
            double  maxValue = 0;
            HexaPos maxPos   = null;

            List <HexaPos> .Enumerator e = hexes.GetEnumerator();
            while (e.MoveNext())
            {
                if (_entropy[e.Current.X, e.Current.Y] >= maxValue)
                {
                    maxPos = e.Current;
                }
            }

            return(maxPos);
        }
Example #9
0
        public void Update(Agent agent, HexaPos currentPos)
        {
            int radius = agent.GetObservationRange();

            SetProbability(currentPos.X, currentPos.Y, 0);

            List <HexaPos> hexes = _map.GetHexes(currentPos.X, currentPos.Y, radius, false);

            List <HexaPos> .Enumerator e = hexes.GetEnumerator();

            while (e.MoveNext())
            {
                double prob = _probability[currentPos.X, currentPos.Y];
                prob = prob * agent.confidenceFactor;
                SetProbability(currentPos.X, currentPos.Y, prob);
            }
        }
Example #10
0
 public void InsertFront(HexaPos pos)
 {
     _path.Insert(0, pos);
 }
Example #11
0
 public void AddPos(HexaPos pos)
 {
     _path.Add(pos);
 }
Example #12
0
 public HexaPos GetNext(HexaPos current, Direction direction)
 {
     return(GetNext(current.X, current.Y, direction));
 }