Esempio n. 1
0
 public FindWay(int x, int y, bool _flag, Point[] _mAllowed, Point _Beg, FindWay _Father)
 {
     Begining = _Beg;
     flag     = _flag;
     Root     = new Point(x, y);
     mAllowed = _mAllowed;
     Father   = _Father;
 }
Esempio n. 2
0
        private Point[] GetCycle(int x, int y)
        {
            Point   Beg = new Point(x, y);
            FindWay fw  = new FindWay(x, y, true, Allowed, Beg, null);

            fw.BuildTree();
            Point[] Way = Array.FindAll <Point>(Allowed, delegate(Point p) { return((p.X != -1) && (p.Y != -1)); });
            return(Way);
        }
        /// <summary>
        /// Phân tích hình
        /// </summary>
        /// <param name="colors"></param>
        /// <param name="bounds"></param>
        public AnalystImageService(Color[,] colors, Bounds bounds)
        {
            Colors = colors;
            Bounds = bounds;
            SetValue();
            //SetColorWhenDuplicate();
            var temp = new FindWay(Image, Bounds);

            GeoJson = temp.FindGeoJson();
        }
        /// <summary>
        /// Phân tích hình
        /// </summary>
        /// <param name="colors"></param>
        /// <param name="box"></param>
        public AnalystImageService(Color[,] colors, string box, int zoom)
        {
            Colors = colors;
            Bounds = new Bounds(box, zoom);
            SetValue();
            //SetColorWhenDuplicate();
            var temp = new FindWay(Image, Bounds);

            GeoJson = temp.FindGeoJson();
        }
Esempio n. 5
0
        public int Attack(PictureBox pictureMap, TacticSeed seed, TacticState tacticState, Bitmap combatBitmap, System.Media.SoundPlayer player)
        {
            int ret = 0;

            if (seed.activeShip.actionsLeft >= seed.activeShip.equippedWeapon.energyСonsumption &&
                seed.activeShip.equippedWeapon.shotsleft > 0)    // если у корабля остались очки действий
            {
                double angle, targetx, targety;
                targetx = tacticState.cMap.boxes[seed.select].x;
                targety = tacticState.cMap.boxes[seed.select].y;
                angle   = FindWay.AttackAngleSearch(targetx, targety, seed, tacticState);
                doShipRotate(angle, 1, true, pictureMap, seed);
                // отрисовка атаки
                //Thread.Sleep(150);
                ret = seed.activeShip.attack(tacticState.cMap, tacticState.cMap.boxes[seed.select].id, ref combatBitmap,
                                             player, ref pictureMap, ref bmBackground, ref bmFull);
                // возвращаем корабль в исходное положение
                doShipRotate(angle, -1, false, pictureMap, seed);
            }
            return(ret);
        }
Esempio n. 6
0
        // Метод минимального элемента
        public float[,] MinEl( )
        {
            float[] Ahelp = this.dilers;
            float[] Bhelp = this.customers;
            int     i     = 0;
            int     j     = 0;
            float   min   = float.MaxValue;

            float[,] outArr = new float[this.dilersCount, this.customersCount];
            bool[,] pArr    = new bool[this.dilersCount, this.customersCount];
            for (i = 0; i < this.dilersCount; i++)
            {
                for (j = 0; j < this.customersCount; j++)
                {
                    pArr[i, j] = true;
                }
            }
            i = 0;
            j = 0;
            int k;
            int count = 0;

            while (!this.isEmpty(Ahelp) || !this.isEmpty(Bhelp))
            {
                min = this.findMin(this.transportationPrices, pArr, out i, out j);
                float Dif = Math.Min(Ahelp[i], Bhelp[j]);
                outArr[i, j] += Dif; count++;
                Ahelp[i]     -= Dif;
                Bhelp[j]     -= Dif;
                if (Ahelp[i] == 0f)
                {
                    k = 0;
                    while (k < this.customersCount)
                    {
                        pArr[i, k] = false;
                        k++;
                    }
                }
                if (Bhelp[j] == 0f)
                {
                    for (k = 0; k < this.dilersCount; k++)
                    {
                        pArr[k, j] = false;
                    }
                }
            }
            this.NanToEmpty(outArr);

            // Нуль-загрузка
            int difference = (dilersCount + customersCount - 1) - count;

            for (int l = 0; l < difference; l++)
            {
                //выбираем непустые
                Allowed = new Point[count + 1];
                k       = 0;
                for (i = 0; i < dilersCount; i++)
                {
                    for (j = 0; j < customersCount; j++)
                    {
                        if (outArr[i, j] == outArr[i, j])
                        {
                            Allowed[k] = new Point(i, j);
                            k++;
                        }
                    }
                }
                // ищем куда загрузить
                Boolean p  = true;
                Point   Nl = new Point(0, 0);
                for (i = 0; (i < dilersCount) && p; i++)
                {
                    for (j = 0; (j < customersCount) && p; j++)
                    {
                        Nl = Allowed[9] = new Point(i, j);
                        FindWay fw = new FindWay(i, j, true, Allowed, new Point(i, j), null);
                        p = fw.BuildTree();
                    }
                }
                if (!p)
                {
                    outArr[Nl.X, Nl.Y] = 0;
                }
            }

            return(outArr);
        }
Esempio n. 7
0
            public Boolean BuildTree( )
            {
                Point[] ps    = new Point[mAllowed.Length];
                int     Count = 0;

                for (int i = 0; i < mAllowed.Length; i++)
                {
                    if (flag)
                    {
                        if (Root.Y == mAllowed[i].Y)
                        {
                            Count++;
                            ps[Count - 1] = mAllowed[i];
                        }
                    }
                    else
                    if (Root.X == mAllowed[i].X)
                    {
                        Count++;
                        ps[Count - 1] = mAllowed[i];
                    }
                }

                FindWay fwu = this;

                Childrens = new FindWay[Count];
                int k = 0;

                for (int i = 0; i < Count; i++)
                {
                    if (ps[i] == Root)
                    {
                        continue;
                    }
                    if (ps[i] == Begining)
                    {
                        while (fwu != null)
                        {
                            mAllowed[k] = fwu.Root;
                            fwu         = fwu.Father;
                            k++;
                        }
                        ;
                        for ( ; k < mAllowed.Length; k++)
                        {
                            mAllowed[k] = new Point(-1, -1);
                        }
                        return(true);
                    }

                    if (!Array.TrueForAll <Point>(ps, p => ((p.X == 0) && (p.Y == 0))))
                    {
                        Childrens[i] = new FindWay(ps[i].X, ps[i].Y, !flag, mAllowed, Begining, this);
                        Boolean result = Childrens[i].BuildTree();
                        if (result)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
Esempio n. 8
0
        void imgCombatMap_MouseDown(Base sender, ClickedEventArgs e)
        {
            for (int i = 0; i < tacticState.cMap.boxes.Count; i++)
            {
                if ((e.X > tacticState.cMap.boxes[i].xpoint2) &&
                    (e.X < tacticState.cMap.boxes[i].xpoint3) &&
                    (e.Y > tacticState.cMap.boxes[i].ypoint2) &&
                    (e.Y < tacticState.cMap.boxes[i].ypoint6))
                {
                    seed.select = i;
                    if (seed.activeShip == null && tacticState.cMap.boxes[seed.select].spaceObject != null)
                    {
                        if (tacticState.cMap.boxes[seed.select].spaceObject != null)
                        {
                            if (seed.activePlayer == tacticState.cMap.boxes[seed.select].spaceObject.player)
                            {
                                // отрисовываем рамку вокруг активного корабля
                                labelDescription.Text = tacticState.cMap.boxes[seed.select].spaceObject.description();
                                seed.activeShip       = (Ship)tacticState.cMap.boxes[seed.select].spaceObject;
                                tacticDraw.DrawSavedImages(pictureMap, seed);
                                tacticDraw.DrawActiveShipFrames(pictureMap, seed, tacticState);
                            }
                            else
                            {
                                labelDescription.Text = tacticState.cMap.boxes[i].spaceObject.description();
                            }
                        }
                    }
                    // Если до этого ткнули по дружественному судну
                    else if (seed.activeShip != null)
                    {
                        // если выбранная клетка пуста - определяем возможность перемещения
                        if (seed.activeShip.actionsLeft > 0 && tacticState.cMap.boxes[seed.select].spaceObject == null)
                        {
                            int flag = 0;
                            int a = seed.activeShip.boxId;
                            int x1, x2, y1, y2;
                            x1 = tacticState.cMap.boxes[a].x;
                            x2 = tacticState.cMap.boxes[seed.select].x;
                            y1 = tacticState.cMap.boxes[a].y;
                            y2 = tacticState.cMap.boxes[seed.select].y;
                            int        lineRange      = (int)Math.Sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)) * 0.35);
                            List <Box> completeBoxWay = new List <Box>();
                            if (lineRange <= seed.activeShip.actionsLeft)
                            {
                                // запоминаю начальную клетку
                                Box baseBox = tacticState.cMap.boxes[a];
                                // определяю направление, в котором находится целевая клетка
                                int direction = FindWay.FindDirection(x1, x2, y1, y2);
                                // определяю приоритет
                                List <int> priority = new List <int>();
                                FindWay.FindPriority(direction, ref priority);
                                for (int k = 0; k < 6; k++)
                                {
                                    if (FindWay.GetBoxway(baseBox, baseBox, tacticState.cMap.boxes[seed.select], ref completeBoxWay, seed.activeShip.actionsLeft, k, tacticState) == 0)
                                    {
                                        break;
                                    }
                                }
                                if (completeBoxWay.Count > 0)
                                {
                                    flag = 1;
                                }
                            }
                            if (flag == 1)
                            {
                                tacticDraw.Move(pictureMap, seed, tacticState, completeBoxWay, x1, x2, y1, y2);
                                labelDescription.Text = seed.activeShip.description();
                                if (seed.activeShip.actionsLeft != 0)
                                {
                                    tacticDraw.DrawSavedImages(pictureMap, seed);
                                    tacticDraw.DrawActiveShipFrames(pictureMap, seed, tacticState);
                                }
                                else
                                {
                                    tacticDraw.DrawSavedImages(pictureMap, seed);
                                    seed.activeShip = null;
                                }
                            }
                        }
                        else if (tacticState.cMap.boxes[seed.select].spaceObject != null)
                        {
                            if (tacticState.cMap.boxes[seed.select].spaceObject.player == seed.activePlayer)
                            {
                                labelDescription.Text = tacticState.cMap.boxes[seed.select].spaceObject.description();
                                seed.activeShip       = (Ship)tacticState.cMap.boxes[seed.select].spaceObject;
                                tacticDraw.DrawSavedImages(pictureMap, seed);
                                tacticDraw.DrawActiveShipFrames(pictureMap, seed, tacticState);
                            }
                            // просчет возможности атаки
                            else if (tacticState.cMap.boxes[seed.select].spaceObject.player != seed.activePlayer)
                            {
                                int    flag = 0;
                                int    a    = seed.activeShip.boxId;
                                double x1   = tacticState.cMap.boxes[a].x;
                                double y1   = tacticState.cMap.boxes[a].y;
                                double x2   = tacticState.cMap.boxes[seed.select].x;
                                double y2   = tacticState.cMap.boxes[seed.select].y;
                                double range;
                                // определяем расстояние между объектами
                                range = Math.Sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)) * 0.35);
                                if (seed.activeShip.equippedWeapon.attackRange >= (int)range)
                                {
                                    flag = 1; // устанавливаем флаг, если расстояние не превышает дальности атаки
                                }
                                if (flag == 1)
                                {
                                    if (tacticDraw.Attack(pictureMap, seed, tacticState, combatBitmap, player) == 1)
                                    {
                                        ShipsCounter.ShipsCount(ref seed);
                                    }
                                    labelDescription.Text = seed.activeShip.description();

                                    // убираем подсветку с корабля, если у него не осталось очков передвижений
                                    if (seed.activeShip.actionsLeft == 0)
                                    {
                                        tacticDraw.DrawSavedImages(pictureMap, seed);
                                        seed.activeShip = null;
                                    }
                                    else
                                    {
                                        tacticDraw.DrawSavedImages(pictureMap, seed);
                                        tacticDraw.DrawActiveShipFrames(pictureMap, seed, tacticState);
                                    }
                                }
                            }
                        }
                    }
                    UpdateDrawing();
                    if (seed.redShipsCount == 0)
                    {
                        EndCombat(1);
                    }
                    if (seed.blueShipsCount == 0)
                    {
                        EndCombat(2);
                    }
                    break;
                }
            }
        }
Esempio n. 9
0
 private void Awake()
 {
     _instance = this;
 }
Esempio n. 10
0
        public void Move(PictureBox pictureMap, TacticSeed seed, TacticState tacticState, List <Box> completeBoxWay, int x1, int x2, int y1, int y2)
        {
            double   rotateAngle;
            int      range, dx;
            Graphics g = Graphics.FromImage(bmFull);
            int      actualDeltaX0, actualDeltaY0, actualDeltaX1, actualDeltaY1;

            actualDeltaX0 = actualDeltaY0 = 0;
            int savedAngle = 0;

            DrawSavedImages(pictureMap, /*bmFull,*/ seed);
            for (int cnt = 0; cnt < completeBoxWay.Count; cnt++)
            {
                if (seed.activeShip == null)
                {
                    break;
                }
                rotateAngle = FindWay.AttackAngleSearch(tacticState.cMap.boxes[completeBoxWay[cnt].id].x,
                                                        tacticState.cMap.boxes[completeBoxWay[cnt].id].y, seed, tacticState);
                x1 = tacticState.cMap.boxes[seed.activeShip.boxId].xcenter;
                y1 = tacticState.cMap.boxes[seed.activeShip.boxId].ycenter;
                x2 = tacticState.cMap.boxes[completeBoxWay[cnt].id].xcenter;
                y2 = tacticState.cMap.boxes[completeBoxWay[cnt].id].ycenter;
                int stepLineRange = (int)Math.Sqrt((x2 - x1) * (x2 - x1) + ((y2 - y1) * (y2 - y1)) * 0.35);
                range = (int)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
                dx    = range / 8;
                int deltax;
                int deltay;
                deltax = (x2 - x1) / 8;
                deltay = (y2 - y1) / 8;
                Image     bg;
                Rectangle rect;
                int       halfBoxWidth  = (tacticState.cMap.boxes[0].xpoint3 - tacticState.cMap.boxes[0].xpoint2) / 2;
                int       halfBoxHeight = (tacticState.cMap.boxes[0].ypoint6 - tacticState.cMap.boxes[0].ypoint2) / 2;
                //закрашиваем выделенный корабль
                rect = new Rectangle(
                    seed.activeShip.x - halfBoxWidth,
                    seed.activeShip.y - halfBoxHeight,
                    halfBoxWidth + halfBoxWidth,
                    halfBoxHeight + halfBoxHeight
                    );
                bg = bmBackground.Clone(rect, bmBackground.PixelFormat);
                g.DrawImage(bg, seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight);

                actualDeltaX1 = completeBoxWay[cnt].x - tacticState.cMap.boxes[seed.activeShip.boxId].x;
                actualDeltaY1 = completeBoxWay[cnt].y - tacticState.cMap.boxes[seed.activeShip.boxId].y;
                if (cnt > 0)
                {
                    if (actualDeltaX1 != actualDeltaX0 || actualDeltaY1 != actualDeltaY0)
                    {
                        if (savedAngle != 0)
                        {
                            doShipRotate(savedAngle, -1, false, pictureMap, seed);
                        }
                        doShipRotate(rotateAngle, 1, false, pictureMap, seed);
                        savedAngle = (int)rotateAngle;
                    }
                }
                else
                {
                    doShipRotate(rotateAngle, 1, false, pictureMap, seed);
                    savedAngle = (int)rotateAngle;
                }

                for (int count1 = 0; count1 < range - 10; count1 += dx)
                {
                    seed.activeShip.x += deltax;
                    seed.activeShip.y += deltay;
                    // запоминаем кусок картинки, на которой уже нет активного корабля
                    rect = new Rectangle(
                        seed.activeShip.x - halfBoxWidth,
                        seed.activeShip.y - halfBoxHeight,
                        halfBoxWidth + halfBoxWidth,
                        halfBoxHeight + halfBoxHeight
                        );
                    bg = bmFull.Clone(rect, bmFull.PixelFormat);
                    // рисуем корабль по новым координатам
                    g.DrawImage(seed.activeShip.objectImg,
                                new Rectangle(seed.activeShip.x - seed.activeShip.objectImg.Width / 2,
                                              seed.activeShip.y - seed.activeShip.objectImg.Height / 2,
                                              seed.activeShip.objectImg.Width,
                                              seed.activeShip.objectImg.Height)
                                );
                    pictureMap.Image = bmFull;
                    Screen_Combat.UpdateDrawing();
                    //Thread.Sleep(5);
                    g.DrawImage(bg, seed.activeShip.x - halfBoxWidth, seed.activeShip.y - halfBoxHeight);
                }
                seed.activeShip.moveShip(tacticState.cMap, seed.activeShip.boxId, completeBoxWay[cnt].id, 1);
                g.DrawImage(seed.activeShip.objectImg,
                            new Rectangle(seed.activeShip.x - seed.activeShip.objectImg.Width / 2,
                                          seed.activeShip.y - seed.activeShip.objectImg.Height / 2,
                                          seed.activeShip.objectImg.Width,
                                          seed.activeShip.objectImg.Height));
                if (cnt == completeBoxWay.Count - 1)
                {
                    doShipRotate(rotateAngle, -1, true, pictureMap, seed);
                }
                actualDeltaX0 = actualDeltaX1;
                actualDeltaY0 = actualDeltaY1;
            }
        }