예제 #1
0
        private GameSquare AddToCloseList()
        {
            GameSquare square = this.RemoveFromOpenList();

            closeList.Add(square);
            closeDictionary.Add(square.Position, square);
            return(square);
        }
예제 #2
0
 private void AddToCloseList(GameSquare square)
 {
     if (!this.closeDictionary.ContainsKey(square.Position))
     {
         this.closeList.Add(square);
         this.closeDictionary.Add(square.Position, square);
     }
 }
예제 #3
0
        private void SwapSquare(int x, int y, List <GameSquare> list)
        {
            GameSquare square = list[x];

            list[x]       = list[y];
            list[y]       = square;
            list[x].Index = x;
            list[y].Index = y;
        }
예제 #4
0
        public GameArea GetDayArea(Troop troop, int Days)
        {
            GameArea area = new GameArea();

            this.openDictionary.Clear();
            this.closeDictionary.Clear();
            this.openList.Clear();
            this.closeList.Clear();
            GameSquare square = new GameSquare();

            square.Position = troop.Position;
            this.AddToCloseList(square);
            int num            = troop.Movability * Days;
            int movabilityLeft = troop.MovabilityLeft;
            int num3           = troop.RealMovability * Days;

            troop.MovabilityLeft = num;
            int num4 = 0;

            do
            {
                try
                {
                    this.CheckAdjacentSquares(square, troop.Position);
                    if (this.openList.Count == 0)
                    {
                        break;
                    }
                    square = this.AddToCloseList();
                    if (square == null)
                    {
                        break;
                    }
                    if (num >= square.G)
                    {
                        if (!troop.Scenario.PositionIsTroop(square.Position))
                        {
                            area.AddPoint(square.Position);
                        }
                        num4 = 0;
                    }
                    else
                    {
                        num4++;
                    }
                }
                catch (OutOfMemoryException)
                {
                    openList.Clear();
                    closeList.Clear();
                    return(area);
                }
            }while (num4 < (num3 * 2));
            troop.MovabilityLeft = movabilityLeft;
            return(area);
        }
예제 #5
0
 private void AddToOpenList(GameSquare square, bool useAStar)
 {
     int key = 0;
     if (useAStar) // A* search
         key = square.F * 160000 + (square.Position.X * 400 + square.Position.Y); // to break tie because Dictionary doesn't allow duplicate keys (only need square.F)
     else          // least cost first search
         key = square.G * 160000 + (square.Position.X * 400 + square.Position.Y);
     openList.Add(key, square);
     openDictionary.Add(square.Position, square);
 }
예제 #6
0
        public GameArea GetDayArea(Troop troop, int Days)
        {
            GameArea area = new GameArea();

            openDictionary.Clear();
            openList.Clear();
            closeDictionary.Clear();
            closeList.Clear();
            GameSquare square = new GameSquare();

            square.Position = troop.Position;
            this.AddToCloseList(square);
            int num            = troop.Movability * Days;
            int movabilityLeft = troop.MovabilityLeft;

            //int num3 = troop.RealMovability * Days;
            troop.MovabilityLeft = num;
            MilitaryKind kind = troop.Army.Kind;

            do
            {
                CheckAdjacentSquares(square, troop.Position, false, kind);
                if (this.openList.Count == 0)
                {
                    break;
                }
                square = this.AddToCloseList();
                if (square == null)
                {
                    break;
                }
                if (num >= square.G)
                {
                    if (!troop.Scenario.PositionIsTroop(square.Position))
                    {
                        area.AddPoint(square.Position);
                    }
                }
                else
                {
                    break;
                }
                if (closeList.Count > 2500 || closeDictionary.Count > 2500)
                {
                    break;
                }
            } while (true);
            troop.MovabilityLeft = movabilityLeft;
            saveLastPath();
            openDictionary.Clear();
            openList.Clear();
            closeDictionary.Clear();
            closeList.Clear();
            return(area);
        }
예제 #7
0
 private void CheckAdjacentSquares(GameSquare currentSquare, Point end, bool useAStar, MilitaryKind kind)
 {
     int leftSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1, useAStar, kind);
     int topSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1, useAStar, kind);
     int rightSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1, useAStar, kind);
     int bottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1, useAStar, kind);
     this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (topSquareCost > leftSquareCost) ? topSquareCost : leftSquareCost, useAStar, kind);
     this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (bottomSquareCost > leftSquareCost) ? bottomSquareCost : leftSquareCost, useAStar, kind);
     this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (topSquareCost > rightSquareCost) ? topSquareCost : rightSquareCost, useAStar, kind);
     this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (bottomSquareCost > rightSquareCost) ? bottomSquareCost : rightSquareCost, useAStar, kind);
 }
예제 #8
0
        private GameSquare AddToCloseList()
        {
            GameSquare item = this.RemoveFromOpenList();

            if ((item != null) && !this.IsInCloseList(item.Position))
            {
                this.closeList.Add(item);
                this.closeDictionary.Add(item.Position, item);
            }
            return(item);
        }
예제 #9
0
        private int MakeSquare(GameSquare currentSquare, bool oblique, Point position, Point end, int DirectionCost, bool useAStar, MilitaryKind kind)
        {
            int num = this.GetCostByPosition(position, oblique, DirectionCost, kind);

            if (!this.IsInCloseList(position) && (num < 0xdac))
            {
                GameSquare square = new GameSquare();
                int        num2;
                if (oblique)
                {
                    num2 = currentSquare.RealG + (7 * num);
                }
                else
                {
                    num2 = currentSquare.RealG + (5 * num);
                }
                GameSquare squareFromOpenList = this.GetSquareFromOpenList(position);
                if (squareFromOpenList == null)
                {
                    square.Parent        = currentSquare;
                    square.Position      = position;
                    square.PenalizedCost = this.GetPenalizedCostByPosition(position, kind);
                    if (useAStar)
                    {
                        square.H = distance(position, end);
                    }
                    square.RealG = num2;
                    this.AddToOpenList(square, useAStar);
                }
                else if (num2 < squareFromOpenList.RealG)
                {
                    openDictionary.Remove(position);
                    if (useAStar)
                    {
                        openList.Remove(squareFromOpenList.F * 160000 + (squareFromOpenList.Position.X * 400 + squareFromOpenList.Position.Y));
                    }
                    else
                    {
                        openList.Remove(squareFromOpenList.G * 160000 + (squareFromOpenList.Position.X * 400 + squareFromOpenList.Position.Y));
                    }
                    square.Parent        = currentSquare;
                    square.Position      = position;
                    square.PenalizedCost = this.GetPenalizedCostByPosition(position, kind);
                    if (useAStar)
                    {
                        square.H = distance(position, end);
                    }
                    square.RealG = num2;
                    this.AddToOpenList(square, useAStar);
                }
            }
            return(num);
        }
예제 #10
0
        private GameSquare RemoveFromOpenList()
        {
            if (openDictionary.Count <= 0)
            {
                return(null);
            }
            GameSquare square = openList.Values[0];

            openList.RemoveAt(0);
            openDictionary.Remove(square.Position);
            return(square);
        }
예제 #11
0
        private void CheckAdjacentSquares(GameSquare currentSquare, Point end, bool useAStar, MilitaryKind kind)
        {
            int leftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1, useAStar, kind);
            int topSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1, useAStar, kind);
            int rightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1, useAStar, kind);
            int bottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1, useAStar, kind);

            this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (topSquareCost > leftSquareCost) ? topSquareCost : leftSquareCost, useAStar, kind);
            this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (bottomSquareCost > leftSquareCost) ? bottomSquareCost : leftSquareCost, useAStar, kind);
            this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (topSquareCost > rightSquareCost) ? topSquareCost : rightSquareCost, useAStar, kind);
            this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (bottomSquareCost > rightSquareCost) ? bottomSquareCost : rightSquareCost, useAStar, kind);
        }
예제 #12
0
        private void AddToOpenList(GameSquare square, bool useAStar)
        {
            int key = 0;

            if (useAStar)                                                                // A* search
            {
                key = square.F * 160000 + (square.Position.X * 400 + square.Position.Y); // to break tie because Dictionary doesn't allow duplicate keys (only need square.F)
            }
            else                                                                         // least cost first search
            {
                key = square.G * 160000 + (square.Position.X * 400 + square.Position.Y);
            }
            openList.Add(key, square);
            openDictionary.Add(square.Position, square);
        }
 public GameArea GetDayArea(Troop troop, int Days)
 {
     GameArea area = new GameArea();
     openDictionary.Clear();
     openList.Clear();
     closeDictionary.Clear();
     closeList.Clear();
     GameSquare square = new GameSquare();
     square.Position = troop.Position;
     this.AddToCloseList(square);
     int num = troop.Movability * Days;
     int movabilityLeft = troop.MovabilityLeft;
     //int num3 = troop.RealMovability * Days;
     troop.MovabilityLeft = num;
     MilitaryKind kind = troop.Army.Kind;
     do
     {
         CheckAdjacentSquares(square, troop.Position, false, kind);
         if (this.openList.Count == 0)
         {
             break;
         }
         square = this.AddToCloseList();
         if (square == null)
         {
             break;
         }
         if (num >= square.G)
         {
             if (!troop.Scenario.PositionIsTroop(square.Position))
             {
                 area.AddPoint(square.Position);
             }
         }
         else
         {
             break;
         }
         if (closeList.Count > 2500 || closeDictionary.Count > 2500) break;
     } while (true);
     troop.MovabilityLeft = movabilityLeft;
     saveLastPath();
     openDictionary.Clear();
     openList.Clear();
     closeDictionary.Clear();
     closeList.Clear();
     return area;
 }
예제 #14
0
        private void saveLastPath()
        {
            lastPath.Clear();
            List <Point> list   = new List <Point>();
            GameSquare   parent = this.closeList[this.closeList.Count - 1];

            do
            {
                list.Add(parent.Position);
                parent = parent.Parent;
            }while (parent != null);
            for (int i = 1; i <= list.Count; i++)
            {
                lastPath.Add(list[list.Count - i]);
            }
        }
예제 #15
0
        public void SetPath(List <Point> path)
        {
            path.Clear();
            List <Point> list   = new List <Point>();
            GameSquare   parent = this.closeList[this.closeList.Count - 1];

            do
            {
                list.Add(parent.Position);
                parent = parent.Parent;
            }while (parent != null);
            for (int i = 1; i <= list.Count; i++)
            {
                path.Add(list[list.Count - i]);
            }
        }
예제 #16
0
 private void AddToOpenList(GameSquare square)
 {
     if (!this.IsInOpenList(square.Position))
     {
         this.openList.Add(square);
         int x = this.openList.Count - 1;
         square.Index = x;
         for (int i = (x - 1) / 2; this.openList[x].F < this.openList[i].F; i = (x - 1) / 2)
         {
             this.SwapSquare(x, i, this.openList);
             if (i == 0)
             {
                 break;
             }
             x = i;
         }
         this.openDictionary.Add(square.Position, square);
     }
 }
예제 #17
0
        public bool GetPath(Point start, Point end, MilitaryKind kind)
        {
            bool flag = false;

            openDictionary.Clear();
            openList.Clear();
            closeDictionary.Clear();
            closeList.Clear();
            GameSquare square = new GameSquare();

            square.Position = start;
            this.AddToCloseList(square);
            if (start == end)
            {
                lastPath = new List <Point>();
                lastPath.Add(start);
                return(true);
            }
            do
            {
                CheckAdjacentSquares(square, end, true, kind);
                if (this.openList.Count == 0)
                {
                    break;
                }
                square = this.AddToCloseList();
                if (square == null)
                {
                    break;
                }
                flag = square.Position == end;
                if (closeList.Count > 2500 || closeDictionary.Count > 2500)
                {
                    break;
                }
            }while (!flag && (square.RealG < 0xdac));
            saveLastPath();
            openDictionary.Clear();
            openList.Clear();
            closeDictionary.Clear();
            closeList.Clear();
            return(flag);
        }
예제 #18
0
        public bool GetPath(Point start, Point end)
        {
            bool flag = false;

            this.openDictionary.Clear();
            this.closeDictionary.Clear();
            this.openList.Clear();
            this.closeList.Clear();
            GameSquare square = new GameSquare();

            square.Position = start;
            this.AddToCloseList(square);
            if (start == end)
            {
                return(true);
            }
            do
            {
                try
                {
                    this.CheckAdjacentSquares(square, end);
                    if (this.openList.Count == 0)
                    {
                        break;
                    }
                    square = this.AddToCloseList();
                    if (square == null)
                    {
                        break;
                    }
                    flag = square.Position == end;
                }
                catch (OutOfMemoryException)
                {
                    openList.Clear();
                    closeList.Clear();
                    return(false);
                }
            }while (!flag && (square.RealG < 0xdac));
            return(flag);
        }
예제 #19
0
        private GameSquare RemoveFromOpenList()
        {
            if (this.openList.Count <= 0)
            {
                return(null);
            }
            this.SwapSquare(0, this.openList.Count - 1, this.openList);
            GameSquare square = this.openList[this.openList.Count - 1];

            square.Index = -1;
            this.openList.RemoveAt(this.openList.Count - 1);
            this.openDictionary.Remove(square.Position);
            int x = 0;
            int y = x;

            while (true)
            {
                if (((x * 2) + 2) < this.openList.Count)
                {
                    if (this.openList[x].F > this.openList[(x * 2) + 1].F)
                    {
                        y = (x * 2) + 1;
                    }
                    if (this.openList[y].F > this.openList[y + 1].F)
                    {
                        y++;
                    }
                }
                else if ((((x * 2) + 1) < this.openList.Count) && (this.openList[x].F > this.openList[(x * 2) + 1].F))
                {
                    y = (x * 2) + 1;
                }
                if (y == x)
                {
                    return(square);
                }
                this.SwapSquare(x, y, this.openList);
                x = y;
            }
        }
예제 #20
0
 private void UpResortOpenList(GameSquare square, int index)
 {
     if (index != 0)
     {
         int x = index;
         int y = (x - 1) / 2;
         while (true)
         {
             if (this.openList[x].F >= this.openList[y].F)
             {
                 return;
             }
             this.SwapSquare(x, y, this.openList);
             if (y == 0)
             {
                 return;
             }
             x = y;
             y = (x - 1) / 2;
         }
     }
 }
예제 #21
0
        private int MakeSquare(GameSquare currentSquare, bool oblique, Point position, Point end, int DirectionCost)
        {
            int num = this.GetCostByPosition(position, oblique, DirectionCost);

            if (!this.IsInCloseList(position))
            {
                int num2;
                if (num >= 0xdac)
                {
                    return(num);
                }
                GameSquare square = new GameSquare();
                if (oblique)
                {
                    num2 = currentSquare.RealG + (7 * num);
                }
                else
                {
                    num2 = currentSquare.RealG + (5 * num);
                }
                GameSquare squareFromOpenList = this.GetSquareFromOpenList(position);
                if (squareFromOpenList == null)
                {
                    square.Parent        = currentSquare;
                    square.Position      = position;
                    square.PenalizedCost = this.GetPenalizedCostByPosition(position);
                    square.H             = (Math.Abs((int)(end.X - position.X)) + Math.Abs((int)(end.Y - position.Y))) * 5;
                    square.RealG         = num2;
                    this.AddToOpenList(square);
                }
                else if (num2 < squareFromOpenList.RealG)
                {
                    squareFromOpenList.Parent = currentSquare;
                    squareFromOpenList.RealG  = num2;
                    this.UpResortOpenList(squareFromOpenList, squareFromOpenList.Index);
                }
            }
            return(num);
        }
 public bool GetPath(Point start, Point end, MilitaryKind kind)
 {
     bool flag = false;
     openDictionary.Clear();
     openList.Clear();
     closeDictionary.Clear();
     closeList.Clear();
     GameSquare square = new GameSquare();
     square.Position = start;
     this.AddToCloseList(square);
     if (start == end)
     {
         return true;
     }
     do
     {
         CheckAdjacentSquares(square, end, true, kind);
         if (this.openList.Count == 0)
         {
             break;
         }
         square = this.AddToCloseList();
         if (square == null)
         {
             break;
         }
         flag = square.Position == end;
         if (closeList.Count > 2500 || closeDictionary.Count > 2500) break;
     }
     while (!flag && (square.RealG < 0xdac));
     saveLastPath();
     openDictionary.Clear();
     openList.Clear();
     closeDictionary.Clear();
     closeList.Clear();
     return flag;
 }
예제 #23
0
 private void AddToCloseList(GameSquare square)
 {
     closeList.Add(square);
     closeDictionary.Add(square.Position, square);
 }
 private int MakeSquare(GameSquare currentSquare, bool oblique, Point position, Point end, int DirectionCost, bool useAStar, MilitaryKind kind)
 {
     int num = this.GetCostByPosition(position, oblique, DirectionCost, kind);
     if (!this.IsInCloseList(position) && (num < 0xdac))
     {
         GameSquare square = new GameSquare();
         int num2;
         if (oblique)
         {
             num2 = currentSquare.RealG + (7 * num);
         }
         else
         {
             num2 = currentSquare.RealG + (5 * num);
         }
         GameSquare squareFromOpenList = this.GetSquareFromOpenList(position);
         if (squareFromOpenList == null)
         {
             square.Parent = currentSquare;
             square.Position = position;
             square.PenalizedCost = this.GetPenalizedCostByPosition(position, kind);
             if (useAStar)
                 square.H = distance(position, end);
             square.RealG = num2;
             this.AddToOpenList(square, useAStar);
         }
         else if (num2 < squareFromOpenList.RealG)
         {
             openDictionary.Remove(position);
             if (useAStar)
                 openList.Remove(squareFromOpenList.F * 160000 + (squareFromOpenList.Position.X * 400 + squareFromOpenList.Position.Y));
             else
                 openList.Remove(squareFromOpenList.G * 160000 + (squareFromOpenList.Position.X * 400 + squareFromOpenList.Position.Y));
             square.Parent = currentSquare;
             square.Position = position;
             square.PenalizedCost = this.GetPenalizedCostByPosition(position, kind);
             if (useAStar)
                 square.H = distance(position, end);
             square.RealG = num2;
             this.AddToOpenList(square, useAStar);
         }
     }
     return num;
 }
 private void AddToCloseList(GameSquare square)
 {
     closeList.Add(square);
     closeDictionary.Add(square.Position, square);
 }
예제 #26
0
        private void CheckAdjacentSquares(GameSquare currentSquare, Point end)
        {
            int num  = end.X - currentSquare.Position.X;
            int num2 = end.Y - currentSquare.Position.Y;
            int num3 = (num > 0) ? 1 : -1;
            int num4 = (num2 > 0) ? 1 : -1;

            if (num2 == 0)
            {
                num4 = 0;
            }
            else if (Math.Abs((decimal)(num / num2)) > 2M)
            {
                num4 = 0;
            }
            if (num == 0)
            {
                num3 = 0;
            }
            else if (Math.Abs((decimal)(num2 / num)) > 2M)
            {
                num3 = 0;
            }
            switch (num3)
            {
            case -1:
                switch (num4)
                {
                case -1:
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    break;

                case 0:
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    break;

                case 1:
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    break;
                }
                break;

            case 0:
                switch (num4)
                {
                case -1:
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    break;

                case 0:
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    break;

                case 1:
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    break;
                }
                break;

            case 1:
                switch (num4)
                {
                case -1:
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    break;

                case 0:
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    break;

                case 1:
                    this.RightSquareCost  = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y), end, -1);
                    this.BottomSquareCost = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y + 1), end, -1);
                    this.LeftSquareCost   = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y), end, -1);
                    this.TopSquareCost    = this.MakeSquare(currentSquare, false, new Point(currentSquare.Position.X, currentSquare.Position.Y - 1), end, -1);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.RightSquareCost) ? this.BottomSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y + 1), end, (this.BottomSquareCost > this.LeftSquareCost) ? this.BottomSquareCost : this.LeftSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X + 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.RightSquareCost) ? this.TopSquareCost : this.RightSquareCost);
                    this.MakeSquare(currentSquare, true, new Point(currentSquare.Position.X - 1, currentSquare.Position.Y - 1), end, (this.TopSquareCost > this.LeftSquareCost) ? this.TopSquareCost : this.LeftSquareCost);
                    break;
                }
                break;
            }
        }