Example #1
0
        void MyAI_ChooseInjectionPointEvent()
        {
            int HealConvoysWithContainers = 0;
            int BigHealConvoys = 0;
            int HealConvoysWithCollectors = 0;
            int count = 0;
            int tmp = 0;
            int tmp1 = 0;
            int FHPnum = -1;
            int FAPnum = -1;
            Point p = new Point();
            NavigationPointInfo FirstNavPoint = new NavigationPointInfo();
            ScoreInfo FirstScoreObj = new ScoreInfo();
            BattlePointInfo bp = new BattlePointInfo();
            AtackPointInfo ap = new AtackPointInfo();

            Pathfinder = new AStar(this.Tissue);
            ePathfinder = new eAStar(this.Tissue, new Point(PierreTeamInjectionPoint.X - 12, PierreTeamInjectionPoint.Y - 12), 24);

            //��������� ������
            ReadAllMissions();

            //������� HP � AP
            ReadHPsAndAPs();

            //���������� ����� ������ � ������� HP, �� ������� ������ �����
            AnalizeMap(ref FHPnum, ref FAPnum);

            //������� ����� ������ � ����� ������� ScoreMission`�
            if (ScoreObjectives != null)
            {
                count = 0;
                tmp = 10000;
                tmp1 = 0;
                for (int i = 0; i < ScoreObjectives.Length; i++)
                {
                    if (ScoreObjectives[i].Score > count)
                    {
                        count = ScoreObjectives[i].Score;
                    }
                    if (ScoreObjectives[i].Turn < tmp)
                    {
                        tmp = ScoreObjectives[i].Turn;
                        tmp1 = i;
                    }
                }

                FirstScoreObj = ScoreObjectives[tmp1];
                MinHPsToTake = (int)(count / 220) + 1;
            }
            else
            {
                FirstScoreObj.Score = 0;
                FirstScoreObj.Turn = 2000;
                MinHPsToTake = 0;
            }

            //������� ����� ������ NavigationMission
            if (NavigationPoints != null)
            {
                count = 10000;
                tmp = -1;
                for (int i = 0; i < NavigationPoints.Length; i++)
                {
                    if (NavigationPoints[i].EndTurn < count)
                    {
                        count = NavigationPoints[i].EndTurn;
                        tmp = i;
                    }
                }
                FirstNavPoint = NavigationPoints[tmp];
            }
            else
            {
                FirstNavPoint.Location = HoshimiPoints[FHPnum].Location;
            }

            //�������� � ����� ������ �� Pierre`�
            this.InjectionPointWanted = FinallyChooseInjectionPoint(HoshimiPoints[FHPnum].Location, AZNPoints[FAPnum].Location, FirstNavPoint.Location);

            if (KillPierre)
            {
                ap.Location = PierreTeamInjectionPoint;
                ap.Need = 5;
                ap.Exist = 0;
                ATargets.Add(ap);
            }

            //���� �������� HP � AP
            /*
            if (BattleExpected)
            {
                //��� ���������� ������������ ����� HP ���������� �����
                for (int i = 0; i < MinHPsToTake; i++)
                {
                    p = HoshimiPoints[(int)MyHPs[i]].Location;
                    bp.Location = p;
                    bp.Covered = 0;
                    BTargets.Add(bp);
                }

                //��� ������ AP ���������� �����
                p = AZNPoints[FAPnum].Location;
                bp.Location = p;
                bp.Covered = 0;
                BTargets.Add(bp);
            }
            */

            //���������, ������� � ����� ����� ��� ����
            NBPROTECTORTOBUILD = BTargets.Count;
            OBSERVERSTOBUILD = 1;
            NBBODYGUARSTOBUILD = 4;
            BodyGuards = new BodyGuard[NBBODYGUARSTOBUILD];
            for (int i = 0; i < BodyGuards.Length; i++)
            {
                BodyGuards[i] = null;
            }
            //if (KillPierre)
            //{
            //   NBNAVIGATORTOBUILD = NavigationPoints.Length * 2;
            //    NBATACKERTOBUILD = 4;
            //}
            //else
            //{
            NBATACKERTOBUILD = 0;

            if (NavigationPoints != null)
            {
                for (int i = 0; i < NavigationPoints.Length; i++)
                {
                    if ((NavigationPoints[i].BotType == NanoBotType.NanoExplorer)
                        || ((NavigationPoints[i].BotType == NanoBotType.Unknown) && (NavigationPoints[i].Stock <= 0)))
                    {
                        NBNAVIGATORTOBUILD++;
                    }
                    else if ((NavigationPoints[i].BotType == NanoBotType.NanoCollector)
                        && (NavigationPoints[i].Stock <= 0))
                    {
                        NBATACKERTOBUILD++;
                        AtackPointInfo api = new AtackPointInfo();
                        api.Location = NavigationPoints[i].Location;
                        api.Need = 1;
                        api.Exist = 0;
                        ATargets.Add(api);
                    }
                    else if (((NavigationPoints[i].BotType == NanoBotType.NanoCollector) || (NavigationPoints[i].BotType == NanoBotType.Unknown))
                        && (NavigationPoints[i].Stock > 0) && (NavigationPoints[i].Stock <= 10))
                    {
                        NBDOCTORSTOBUILD++;
                    }
                    else if (((NavigationPoints[i].BotType == NanoBotType.NanoContainer)
                        || ((NavigationPoints[i].BotType == NanoBotType.Unknown) && (NavigationPoints[i].Stock > 0)))
                        && (NavigationPoints[i].Stock <= 50))
                    {
                        HealConvoysWithContainers++;
                    }
                    else if ((NavigationPoints[i].BotType == NanoBotType.NanoContainer || (NavigationPoints[i].BotType == NanoBotType.Unknown))
                        && (NavigationPoints[i].Stock > 50))
                    {
                        BigHealConvoys++;
                    }
                    else if ((NavigationPoints[i].BotType == NanoBotType.NanoCollector)
                        && (NavigationPoints[i].Stock > 10))
                    {
                        HealConvoysWithCollectors++;
                    }
                }
            }
            else
            {
                NBNAVIGATORTOBUILD = 0;
            }
            //}

            if (HealConvoysWithCollectors > 0)
            {
                CollConvoys = new ConvoyWithCollector[HealConvoysWithCollectors];
                for (int i = 0; i < CollConvoys.Length; i++)
                {
                    CollConvoys[i] = new ConvoyWithCollector();
                }
            }

            if (BigHealConvoys > 0)
            {
                BigConvoys = new ConvoyWithBigContainer[BigHealConvoys];
                for (int i = 0; i < BigConvoys.Length; i++)
                {
                    BigConvoys[i] = new ConvoyWithBigContainer();
                }
            }

            //����� ������� - ������� �� ����, ������� �� � �������� ����� ��������� � ������� ��� �� ����
            int NotAllocatedBots = Utils.NbrMaxBots - 2 - NBBODYGUARSTOBUILD - NBATACKERTOBUILD - NBPROTECTORTOBUILD - MyHPs.Count;
            int ConvoysNumber = Math.Min((NotAllocatedBots - (NotAllocatedBots % 3)) / 3, MyHPs.Count + HealConvoysWithContainers);
            ConvoysNumber = Math.Max(ConvoysNumber, 3);
            Convoys = new Convoy[ConvoysNumber];
            for (int i = 0; i < Convoys.Length; i++)
            {
                Convoys[i] = new Convoy(false);
            }
            for (int i = 0; i < HealConvoysWithContainers; i++)
            {
                Convoys[i].IsNavigating = true;
            }
        }
Example #2
0
        private void AnalizeMap(ref int HPnum, ref int APnum)
        {
            eAStar PathFinder = new eAStar(this.Tissue);
            //used = new int[HoshimiPoints.Length];
            //path = new Stack<int>();
            //BestPath = new Stack<int>();
            //int Num = 0;
            //int Time = 0;
            HPtoHPdistances = new int[HoshimiPoints.Length, HoshimiPoints.Length];
            HPtoAPdistances = new int[HoshimiPoints.Length, AZNPoints.Length];
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                HPtoHPdistances[i, i] = 0;
                for (int j = 0; j < i; j++)
                {
                    PathFinder.FindPath(HoshimiPoints[i].Location, HoshimiPoints[j].Location, ref HPtoHPdistances[i, j]);
                    HPtoHPdistances[i, j] = (int)HPtoHPdistances[i, j] * (StepCost(HoshimiPoints[i].Location) + StepCost(HoshimiPoints[j].Location)) / 2;
                    HPtoHPdistances[j, i] = HPtoHPdistances[i, j];
                }
                for (int j = 0; j < AZNPoints.Length; j++)
                {
                    //PathFinder.FindPath(HoshimiPoints[i].Location, AZNPoints[j].Location, ref HPtoAPdistances[i, j]);
                    //HPtoAPdistances[i, j] = (int)HPtoAPdistances[i, j] * (StepCost(HoshimiPoints[i].Location) + StepCost(AZNPoints[j].Location)) / 2;
                    HPtoAPdistances[i, j] = EstimateMovementTime(HoshimiPoints[i].Location, AZNPoints[j].Location);
                }
            }
            //ScanList(-1, 0, ref Num, ref Time);

            List<int>[] Path = new List<int>[HoshimiPoints.Length];
            int[] HPN = new int[HoshimiPoints.Length];
            int[] fafa = new int[HoshimiPoints.Length];
            int[] value = new int[HoshimiPoints.Length];
            int sum = 0;
            int last = 0;
            int tmp = 0;
            int tmpNum1 = 0;
            int tmpNum2 = 0;
            int tmpDist3 = 0;
            int tmpDist4 = 0;
            double alpha = 1;

            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                value[i] = 0;
            }

            //������� �������� ������������ �����
            if (NavigationPoints != null)
            {
                for (int i = 0; i < HoshimiPoints.Length; i++)
                {
                    for (int j = 0; j < NavigationPoints.Length; j++)
                    {
                        ePathfinder.FindPath(HoshimiPoints[i].Location, NavigationPoints[j].Location, ref tmp);
                        if (tmp + 100 > NavigationPoints[j].EndTurn)
                        {
                            value[i] = -1;
                        }
                    }
                }
            }

            //��������� "��������" ����� ������
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                if (value[i] != -1)
                {
                    //��������� ����� ����������� �������
                    Path[i] = new List<int>();
                    Path[i].Clear();
                    for (int j = 0; j < fafa.Length; j++)
                    {
                        fafa[j] = 0;
                    }
                    Path[i].Add(i);
                    HPN[i] = 1;
                    fafa[i] = 1;
                    sum = 0;
                    last = i;
                    //���� ���� ���� (����� - ����-� �������� �������� � AZN
                    while (sum < 1500 * (1 + alpha))
                    {
                        //���� HP, ��������� � ������� HP
                        tmp = 10000;
                        tmpNum1 = -1;
                        for (int j = 0; j < HoshimiPoints.Length; j++)
                        {
                            if ((HPtoHPdistances[last, j] < tmp) && (fafa[j] == 0))
                            {
                                tmp = HPtoHPdistances[last, j];
                                tmpNum1 = j;
                            }
                        }
                        tmpDist3 = tmp;

                        //���� AP, ��������� � ������� HP
                        tmp = 10000;
                        tmpNum2 = -1;
                        for (int j = 0; j < AZNPoints.Length; j++)
                        {
                            if (HPtoAPdistances[last, j] < tmp)
                            {
                                tmp = HPtoAPdistances[last, j];
                                tmpNum2 = j;
                            }
                        }
                        tmpDist4 = tmp;

                        //���� ���-�� �����������, �� ����
                        if ((tmpNum1 == -1) || (tmpNum2 == -1))
                            break;

                        //��������� ����� � ������
                        sum = sum + tmpDist3 + (int)(tmpDist4 * alpha);
                        if (sum < 1500 * (1 + alpha))
                        {
                            fafa[tmpNum1] = 1;
                            HPN[i]++;
                            Path[i].Add(tmpNum1);
                            last = tmpNum1;
                        }
                    }

                    //���� AZN, ��������� � ������
                    tmpDist3 = 10000;
                    for (int j = 0; j < AZNPoints.Length; j++)
                    {
                        if (HPtoAPdistances[i, j] < tmpDist3)
                        {
                            tmpDist3 = HPtoAPdistances[i, j];
                        }
                    }
                    //��������� "��������"
                    value[i] = HPN[i] * 1000 - tmpDist3 * 10 + (int)(1500 * (1 + alpha) - sum);
                }
            }
            /*
            MyHPs.Add(0);
            MyHPs.Add(1);
            MyHPs.Add(2);
            HPnum = 0;
            APnum = 0;
            */

            //������� ������ ����� ������
            tmp = -1;
            tmpNum1 = -1;
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                if (value[i] > tmp)
                {
                    tmp = value[i];
                    tmpNum1 = i;
                }
            }
            HPnum = tmpNum1;

            //������� ��������� ����� � AZN
            tmpDist3 = 10000;
            tmpNum1 = -1;
            for (int j = 0; j < AZNPoints.Length; j++)
            {
                if (HPtoAPdistances[HPnum, j] < tmpDist3)
                {
                    tmpDist3 = HPtoAPdistances[HPnum, j];
                    tmpNum1 = j;
                }
            }
            APnum = tmpNum1;
            /*
            for (int i = 0; i < Path[HPnum].Count; i++)
            {
                MyHPs.Add(Path[HPnum][i]);
            }
            */
            //��������� ����� ����������� �������
            for (int j = 0; j < fafa.Length; j++)
            {
                fafa[j] = 0;
            }
            MyHPs.Add(HPnum);
            fafa[HPnum] = 1;
            sum = 0;
            last = HPnum;
            //���� ���� ����
            while (sum < 1500)
            {
                //���� HP, ��������� � ������� HP
                tmp = 10000;
                tmpNum1 = -1;
                for (int j = 0; j < HoshimiPoints.Length; j++)
                {
                    if ((HPtoHPdistances[last, j] < tmp) && (fafa[j] == 0))
                    {
                        tmp = HPtoHPdistances[last, j];
                        tmpNum1 = j;
                    }
                }
                tmpDist3 = tmp;

                //���� ���-�� �����������, �� ����
                if (tmpNum1 == -1)
                    break;

                //��������� ����� � ������
                sum = sum + tmpDist3;
                if (sum < 1500)
                {
                    fafa[tmpNum1] = 1;
                    MyHPs.Add(tmpNum1);
                    last = OptimizePath();
                }
            }
        }
Example #3
0
        private void AnalizeMap(ref int HPnum, ref int APnum)
        {
            eAStar PathFinder = new eAStar(this.Tissue);
            //used = new int[HoshimiPoints.Length];
            //path = new Stack<int>();
            //BestPath = new Stack<int>();
            //int Num = 0;
            //int Time = 0;
            HPtoHPdistances = new int[HoshimiPoints.Length, HoshimiPoints.Length];
            HPtoAPdistances = new int[HoshimiPoints.Length, AZNPoints.Length];
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                HPtoHPdistances[i, i] = 0;
                for (int j = 0; j < i; j++)
                {
                    PathFinder.FindPath(HoshimiPoints[i].Location, HoshimiPoints[j].Location, ref HPtoHPdistances[i, j]);
                    HPtoHPdistances[i, j] = (int)HPtoHPdistances[i, j] * (StepCost(HoshimiPoints[i].Location) + StepCost(HoshimiPoints[j].Location)) / 2;
                    HPtoHPdistances[j, i] = HPtoHPdistances[i, j];
                }
                for (int j = 0; j < AZNPoints.Length; j++)
                {
                    //PathFinder.FindPath(HoshimiPoints[i].Location, AZNPoints[j].Location, ref HPtoAPdistances[i, j]);
                    //HPtoAPdistances[i, j] = (int)HPtoAPdistances[i, j] * (StepCost(HoshimiPoints[i].Location) + StepCost(AZNPoints[j].Location)) / 2;
                    HPtoAPdistances[i, j] = EstimateMovementTime(HoshimiPoints[i].Location, AZNPoints[j].Location);
                }
            }
            //ScanList(-1, 0, ref Num, ref Time);

            List<int>[] Path = new List<int>[HoshimiPoints.Length];
            int[] HPN = new int[HoshimiPoints.Length];
            int[] sumDist = new int[HoshimiPoints.Length];
            int[] fafa = new int[HoshimiPoints.Length];
            int[] value = new int[HoshimiPoints.Length];
            int sum = 0;
            int last = 0;
            int tmp = 0;
            int tmpNum1 = 0;
            int tmpNum2 = 0;
            int tmpDist3 = 0;
            int tmpDist4 = 0;
            double alpha = 1;
            int zzz = 10000;

            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                value[i] = 0;
            }

            //������� �������� ������������ �����
            if (NavigationPoints != null)
            {
                for (int i = 0; i < HoshimiPoints.Length; i++)
                {
                    for (int j = 0; j < NavigationPoints.Length; j++)
                    {
                        if ((NavigationPoints[j].BotType == NanoBotType.NanoExplorer)
                        || ((NavigationPoints[j].BotType == NanoBotType.Unknown) && (NavigationPoints[j].Stock <= 0)))
                        {
                            ePathfinder.FindPath(HoshimiPoints[i].Location, NavigationPoints[j].Location, ref tmp);
                        }
                        else
                        {
                            for (int k = 0; k < AZNPoints.Length; k++)
                            {
                                if (HPtoAPdistances[i, k] < zzz)
                                {
                                    zzz = HPtoAPdistances[i, k];
                                    last = k;
                                }
                            }
                            Pathfinder.FindPath(AZNPoints[last].Location, NavigationPoints[j].Location, ref tmp);
                            tmp += zzz;
                        }
                        if (tmp + 100 > NavigationPoints[j].EndTurn)
                        {
                            value[i] = -1;
                        }
                    }
                    if (GeomDist(HoshimiPoints[i].Location, PierreTeamInjectionPoint) < 40)
                    {
                        value[i] = -1;
                    }
                    if (UniqueNavPoints != null)
                    {
                        if (!UNOpossible(i))
                        {
                            value[i] = -1;
                        }
                    }
                }

            }

            //��������, ���� �� ���� ���� ���������� �����
            bool MI = true;

            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                if (value[i] >= 0)
                    MI = false;
            }

            if (MI)
            {
                for (int i = 0; i < HoshimiPoints.Length; i++)
                {
                    value[i] = 0;
                }
            }

            //��������� "��������" ����� ������
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                if (value[i] != -1)
                {
                    //��������� ����� ����������� �������
                    Path[i] = new List<int>();
                    Path[i].Clear();
                    for (int j = 0; j < fafa.Length; j++)
                    {
                        fafa[j] = 0;
                    }
                    Path[i].Add(i);
                    HPN[i] = 1;
                    fafa[i] = 1;
                    sum = 0;
                    last = i;
                    //���� ���� ���� (����� - ����-� �������� �������� � AZN
                    while (sum < 1500 * (1 + alpha))
                    {
                        //���� HP, ��������� � ������� HP
                        tmp = 10000;
                        tmpNum1 = -1;
                        sumDist[i] = 0;
                        for (int j = 0; j < HoshimiPoints.Length; j++)
                        {
                            sumDist[i] += HPtoHPdistances[i, j];
                            if ((HPtoHPdistances[last, j] < tmp) && (fafa[j] == 0))
                            {
                                tmp = HPtoHPdistances[last, j];
                                tmpNum1 = j;
                            }
                        }
                        tmpDist3 = tmp;

                        //���� AP, ��������� � ������� HP
                        tmp = 10000;
                        tmpNum2 = -1;
                        for (int j = 0; j < AZNPoints.Length; j++)
                        {
                            if (HPtoAPdistances[last, j] < tmp)
                            {
                                tmp = HPtoAPdistances[last, j];
                                tmpNum2 = j;
                            }
                        }
                        tmpDist4 = tmp;

                        //���� ���-�� �����������, �� ����
                        if ((tmpNum1 == -1) || (tmpNum2 == -1))
                            break;

                        //��������� ����� � ������
                        sum = sum + tmpDist3 + (int)(tmpDist4 * alpha);
                        if (sum < 1500 * (1 + alpha))
                        {
                            fafa[tmpNum1] = 1;
                            HPN[i]++;
                            Path[i].Add(tmpNum1);
                            last = tmpNum1;
                        }
                    }

                    //���� AZN, ��������� � ������
                    tmpDist3 = 10000;
                    int fafaA = -1;
                    for (int j = 0; j < AZNPoints.Length; j++)
                    {
                        if (HPtoAPdistances[i, j] < tmpDist3)
                        {
                            tmpDist3 = HPtoAPdistances[i, j];
                            fafaA = j;
                        }
                    }
                    Pathfinder.FindPath(HoshimiPoints[i].Location, AZNPoints[fafaA].Location, ref tmpDist3);
                    //��������� "��������"
                    value[i] = HPN[i] * 1000 - tmpDist3 * 10 + (int)(1500 * (1 + alpha) - sum) + (int)(GROUP_VALUE*((double)HoshimiPoints.Length)/((double)sumDist[i]))/* - 10*(int)(((double)sumDist[i])/((double)HoshimiPoints.Length))*/;
                }
            }
            /*
            MyHPs.Add(0);
            MyHPs.Add(1);
            MyHPs.Add(2);
            HPnum = 0;
            APnum = 0;
            */

            //������� ������ ����� ������
            tmp = -1;
            tmpNum1 = -1;
            for (int i = 0; i < HoshimiPoints.Length; i++)
            {
                if (value[i] > tmp)
                {
                    tmp = value[i];
                    tmpNum1 = i;
                }
            }
            HPnum = tmpNum1;

            //������� ��������� ����� � AZN
            tmpDist3 = 10000;
            tmpNum1 = -1;
            for (int j = 0; j < AZNPoints.Length; j++)
            {
                if (HPtoAPdistances[HPnum, j] < tmpDist3)
                {
                    tmpDist3 = HPtoAPdistances[HPnum, j];
                    tmpNum1 = j;
                }
            }
            APnum = tmpNum1;

            if (UniqueNavPoints != null)
            {
                BuildUNOPath(HPnum);
            }
            /*
            for (int i = 0; i < Path[HPnum].Count; i++)
            {
                MyHPs.Add(Path[HPnum][i]);
            }
            */
            BuildPath(HPnum);
        }