Пример #1
0
        private void nbPoint(Point nb, Node current, Point end, int X, int Y) //функция обрабатывющая "соседнюю" клетку
        {
            //различные проверки клетки - границы массива,закрытый список итд.
            if (nb.X >= X || nb.X < 0)
            {
                return;
            }
            if (nb.Y >= Y || nb.Y < 0)
            {
                return;
            }
            if (existsArray[nb.X, nb.Y] == 2)
            {
                return;
            }
            if (!tissue.IsInMap(nb.X, nb.Y))
            {
                return;
            }
            if (tissue[nb.X, nb.Y].AreaType == VG.Map.AreaEnum.Bone)
            {
                return;
            }

            //если нет в открытом списке - добавляем
            if (existsArray[nb.X, nb.Y] != 1)
            {
                Node n = new Node(nb, 0, 0, 0);
                n.H = calcH(nb, end);
                n.G = calcG(n);

                n.F      = n.G + n.H;
                n.Parent = current.P;
                openList.Add(n);
                existsArray[n.P.X, n.P.Y] = 1;
            }
            else //если есть - страдаем некоторой фигней =)
            {
                Node n = openList[inList(nb, openList)];
                if (n.G > calcG(n))
                {
                    n.Parent = current.P;
                    n.G      = calcG(n);
                    n.F      = n.G + n.H;

                    int j = inList(nb, openList);
                    existsArray[openList[j].P.X, openList[j].P.Y] = 0;
                    openList.RemoveAt(j);
                    openList.Add(n);
                    existsArray[n.P.X, n.P.Y] = 1;
                }
            }
        }
Пример #2
0
        private void nbPoint(Point nb, Node current, Point end, int X, int Y)
        {
            if (nb.X >= X || nb.X < 0)
            {
                return;
            }
            if (nb.Y >= Y || nb.Y < 0)
            {
                return;
            }
            // if (ifExistsInList(nb, closeList))
            if (existsArray[nb.X, nb.Y] == 2)
            {
                return;
            }
            if (!tissue.IsInMap(nb.X, nb.Y))
            {
                return;
            }
            if (tissue[nb.X, nb.Y].AreaType == VG.Map.AreaEnum.Bone)
            {
                return;
            }

            //if (!ifExistsInList(nb, openList))
            if (existsArray[nb.X, nb.Y] != 1)
            {
                Node n = new Node(nb, 0, 0, 0);
                n.H = calcH(nb, end);
                n.G = calcG(n);

                n.F      = n.G + n.H;
                n.Parent = current.P;
                openList.Add(n);
                existsArray[n.P.X, n.P.Y] = 1;
            }
            else
            {
                Node n = openList[inList(nb, openList)];
                if (n.G < calcG(n))
                {
                    n.Parent = current.P;
                    n.G      = calcG(n);
                    n.F      = n.G + n.H;

                    int j = inList(nb, openList);
                    existsArray[openList[j].P.X, openList[j].P.Y] = 0;
                    openList.RemoveAt(j);
                    openList.Add(n);
                    existsArray[n.P.X, n.P.Y] = 1;
                }
            }
        }