Esempio n. 1
0
        private PointField findClosed(LinkedList <AStarSolver <GameField> .PathNode> nodeList)
        {
            PointField pointField = new PointField(this.currentlyChecking.value);
            int        num        = 2147483647;
            int        num2       = -2147483648;
            int        num3       = 2147483647;
            int        num4       = -2147483648;

            foreach (AStarSolver <GameField> .PathNode current in nodeList)
            {
                if (current.X < num)
                {
                    num = current.X;
                }
                if (current.X > num2)
                {
                    num2 = current.X;
                }
                if (current.Y < num3)
                {
                    num3 = current.Y;
                }
                if (current.Y > num4)
                {
                    num4 = current.Y;
                }
            }
            checked
            {
                int          x     = (int)Math.Ceiling((double)((float)(num2 - num) / 2f)) + num;
                int          y     = (int)Math.Ceiling((double)((float)(num4 - num3) / 2f)) + num3;
                List <Point> list  = new List <Point>();
                List <Point> list2 = new List <Point>();
                list2.Add(new Point(this.currentlyChecking.x, this.currentlyChecking.y));
                list.Add(new Point(x, y));
                while (list.Count > 0)
                {
                    Point point = list[0];
                    int   x2    = point.X;
                    int   y2    = point.Y;
                    if (x2 < num)
                    {
                        return(null);
                    }
                    if (x2 > num2)
                    {
                        return(null);
                    }
                    if (y2 < num3)
                    {
                        return(null);
                    }
                    if (y2 > num4)
                    {
                        return(null);
                    }
                    if (this[y2 - 1, x2] && this.currentField[y2 - 1, x2] == 0)
                    {
                        Point item = new Point(x2, y2 - 1);
                        if (!list.Contains(item) && !list2.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                    if (this[y2 + 1, x2] && this.currentField[y2 + 1, x2] == 0)
                    {
                        Point item = new Point(x2, y2 + 1);
                        if (!list.Contains(item) && !list2.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                    if (this[y2, x2 - 1] && this.currentField[y2, x2 - 1] == 0)
                    {
                        Point item = new Point(x2 - 1, y2);
                        if (!list.Contains(item) && !list2.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                    if (this[y2, x2 + 1] && this.currentField[y2, x2 + 1] == 0)
                    {
                        Point item = new Point(x2 + 1, y2);
                        if (!list.Contains(item) && !list2.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                    if (this.getValue(point) == 0)
                    {
                        pointField.add(point);
                    }
                    list2.Add(point);
                    list.RemoveAt(0);
                }
                return(pointField);
            }
        }
Esempio n. 2
0
        private PointField findClosed(LinkedList<AStarSolver<GameField>.PathNode> nodeList)
        {
            PointField returnList = new PointField(currentlyChecking.value);

            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach (AStarSolver<GameField>.PathNode node in nodeList)
            {
                if (node.X < minX)
                    minX = node.X;

                if(node.X > maxX)
                    maxX = node.X;

                if (node.Y < minY)
                    minY = node.Y;

                if (node.Y > maxY)
                    maxY = node.Y;

            }

            int middleX = (int)Math.Ceiling(((maxX - minX) / 2f)) + minX;
            int middleY = (int)Math.Ceiling(((maxY - minY) / 2f)) + minY;
            //Logging.WriteLine("Middle: x:[{0}]  y:[{1}]", middleX, middleY);

            Point current;
            List<Point> toFill = new List<Point>();
            List<Point> checkedItems = new List<Point>();
            checkedItems.Add(new Point(currentlyChecking.x, currentlyChecking.y));
            Point toAdd;
            toFill.Add(new Point(middleX,middleY));
            int x;
            int y;
            while(toFill.Count > 0)
            {
                current = toFill[0];
                x = current.X;
                y = current.Y;

                if (x < minX)
                    return null;//OOB
                if (x > maxX)
                    return null;//OOB
                if (y < minY)
                    return null;//OOB
                if (y > maxY)
                    return null; //OOB

                if (this[y - 1, x] && currentField[y - 1, x] == 0)
                {
                    toAdd = new Point(x, y - 1);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                        toFill.Add(toAdd);
                }
                if (this[y + 1, x] && currentField[y + 1, x] == 0 )
                {
                    toAdd = new Point(x, y + 1);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                        toFill.Add(toAdd);
                }
                if (this[y, x - 1] && currentField[y, x - 1] == 0)
                {
                    toAdd = new Point(x - 1, y);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                        toFill.Add(toAdd);
                }
                if (this[y, x + 1] && currentField[y, x + 1] == 0)
                {
                    toAdd = new Point(x + 1, y);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                        toFill.Add(toAdd);
                }
                if (getValue(current) == 0)
                    returnList.add(current);
                checkedItems.Add(current);
                toFill.RemoveAt(0);

            }

            return returnList;
        }
Esempio n. 3
0
        private PointField findClosed(LinkedList <AStarSolver <GameField> .PathNode> nodeList)
        {
            PointField returnList = new PointField(currentlyChecking.value);

            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach (AStarSolver <GameField> .PathNode node in nodeList)
            {
                if (node.X < minX)
                {
                    minX = node.X;
                }

                if (node.X > maxX)
                {
                    maxX = node.X;
                }

                if (node.Y < minY)
                {
                    minY = node.Y;
                }

                if (node.Y > maxY)
                {
                    maxY = node.Y;
                }
            }

            int middleX = (int)Math.Ceiling(((maxX - minX) / 2f)) + minX;
            int middleY = (int)Math.Ceiling(((maxY - minY) / 2f)) + minY;
            //Console.WriteLine("Middle: x:[{0}]  y:[{1}]", middleX, middleY);

            Point        current;
            List <Point> toFill       = new List <Point>();
            List <Point> checkedItems = new List <Point>();

            checkedItems.Add(new Point(currentlyChecking.x, currentlyChecking.y));
            Point toAdd;

            toFill.Add(new Point(middleX, middleY));
            int x;
            int y;

            while (toFill.Count > 0)
            {
                current = toFill[0];
                x       = current.X;
                y       = current.Y;

                if (x < minX)
                {
                    return(null);//OOB
                }
                if (x > maxX)
                {
                    return(null);//OOB
                }
                if (y < minY)
                {
                    return(null);//OOB
                }
                if (y > maxY)
                {
                    return(null); //OOB
                }
                if (this[y - 1, x] && currentField[y - 1, x] == 0)
                {
                    toAdd = new Point(x, y - 1);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                    {
                        toFill.Add(toAdd);
                    }
                }
                if (this[y + 1, x] && currentField[y + 1, x] == 0)
                {
                    toAdd = new Point(x, y + 1);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                    {
                        toFill.Add(toAdd);
                    }
                }
                if (this[y, x - 1] && currentField[y, x - 1] == 0)
                {
                    toAdd = new Point(x - 1, y);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                    {
                        toFill.Add(toAdd);
                    }
                }
                if (this[y, x + 1] && currentField[y, x + 1] == 0)
                {
                    toAdd = new Point(x + 1, y);
                    if (!toFill.Contains(toAdd) && !checkedItems.Contains(toAdd))
                    {
                        toFill.Add(toAdd);
                    }
                }
                if (getValue(current) == 0)
                {
                    returnList.add(current);
                }
                checkedItems.Add(current);
                toFill.RemoveAt(0);
            }

            return(returnList);
        }
Esempio n. 4
0
		private PointField findClosed(LinkedList<AStarSolver<GameField>.PathNode> nodeList)
		{
			PointField pointField = new PointField(this.currentlyChecking.value);
			int num = 2147483647;
			int num2 = -2147483648;
			int num3 = 2147483647;
			int num4 = -2147483648;
			foreach (AStarSolver<GameField>.PathNode current in nodeList)
			{
				if (current.X < num)
				{
					num = current.X;
				}
				if (current.X > num2)
				{
					num2 = current.X;
				}
				if (current.Y < num3)
				{
					num3 = current.Y;
				}
				if (current.Y > num4)
				{
                    num4 = current.Y;
				}
			}
			checked
			{
				int x = (int)Math.Ceiling((double)((float)(num2 - num) / 2f)) + num;
				int y = (int)Math.Ceiling((double)((float)(num4 - num3) / 2f)) + num3;
				List<Point> list = new List<Point>();
				List<Point> list2 = new List<Point>();
				list2.Add(new Point(this.currentlyChecking.x, this.currentlyChecking.y));
				list.Add(new Point(x, y));
				while (list.Count > 0)
				{
					Point point = list[0];
					int x2 = point.X;
					int y2 = point.Y;
					if (x2 < num)
					{
						return null;
					}
					if (x2 > num2)
					{
						return null;
					}
					if (y2 < num3)
					{
						return null;
					}
					if (y2 > num4)
					{
						return null;
					}
					if (this[y2 - 1, x2] && this.currentField[y2 - 1, x2] == 0)
					{
						Point item = new Point(x2, y2 - 1);
						if (!list.Contains(item) && !list2.Contains(item))
						{
							list.Add(item);
						}
					}
					if (this[y2 + 1, x2] && this.currentField[y2 + 1, x2] == 0)
					{
						Point item = new Point(x2, y2 + 1);
						if (!list.Contains(item) && !list2.Contains(item))
						{
							list.Add(item);
						}
					}
					if (this[y2, x2 - 1] && this.currentField[y2, x2 - 1] == 0)
					{
						Point item = new Point(x2 - 1, y2);
						if (!list.Contains(item) && !list2.Contains(item))
						{
							list.Add(item);
						}
					}
					if (this[y2, x2 + 1] && this.currentField[y2, x2 + 1] == 0)
					{
						Point item = new Point(x2 + 1, y2);
						if (!list.Contains(item) && !list2.Contains(item))
						{
							list.Add(item);
						}
					}
					if (this.getValue(point) == 0)
					{
						pointField.add(point);
					}
					list2.Add(point);
					list.RemoveAt(0);
				}
				return pointField;
			}
		}