Example #1
0
 //constructor initialises the grid array
 public Level()
 {
     path_count = new int();
     dijkstra = new Dijkstra();
     astar = new AStar();
     scentmap = new Scentmap();
     tiles = new int[gridSize, gridSize];
     for (int i = 0; i < gridSize; i++)
         for (int j = 0; j < gridSize; j++)
             tiles[i,j] = 0;
 }
Example #2
0
        public Game1()
        {
            //constructor
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = BackBufferHeight;
            graphics.PreferredBackBufferWidth = BackBufferWidth;
            Window.Title = "Pathfinder";
            Content.RootDirectory = "Content";
            this.IsMouseVisible = true;
            this.IsFixedTimeStep = false;
            elapsedTime = 0;
            frameCounter = 0;
            FPS = 60;
            mouseState = Mouse.GetState();
            lastMouseState = mouseState;
            mouseClickPos = new Coord2(-1, -1);
            scrollOffset = Vector2.Zero;
            textColour = Color.BlueViolet;
            //set frame rate
            TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate);
            //load level map
            level = new Level();
            string mapName = mapNumber.ToString();
            //mapName = "eighty";
            level.Loadmap("Content/" + mapName + ".txt");
            //instantiate bot and player objects

            BackBufferWidth = level.gridSquareSize * level.GridSizeX;
            BackBufferHeight = level.GridSizeY * level.GridSquareSize;
            graphics.PreferredBackBufferHeight = BackBufferHeight;
            graphics.PreferredBackBufferWidth = BackBufferWidth;
            graphics.ApplyChanges();
            graphics.GraphicsDevice.Reset();

            SetCharacters();
            //bots = new List<AiBotBase>();

            #if ASTARTEST
            string heuristic = "Euclidean";
            StreamWriter r = new StreamWriter("astarTest-" + mapName + "-" + heuristic + ".txt");
            r.WriteLine("A Star Test values with " + heuristic);
            r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY);
            r.WriteLine("Times per build, in ms");

            AStar aStar = new AStar(level);
            aStar = new AStar(level);

            Stopwatch timer = new Stopwatch();

            Coord2 start = new Coord2(1, 1);
            Coord2 end = new Coord2(level.GridSizeX-1, level.GridSizeY-1);
            for (int i = 0; i < 1000; i++)
            {

                timer.Restart();
                aStar.Build(level, start, end, false, heuristic);
                timer.Stop();
                r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds);
            }
            r.Close();

            #endif

            #if DIJKSTRASTEST
            StreamWriter r = new StreamWriter("dijkstrasTest-" + mapName + ".txt");

            string mapDescription = "";
            r.WriteLine("Dijkstra's Test values");
            r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY);
            r.WriteLine(mapDescription);
            r.WriteLine("Times per build, in ms");

            Dijkstra dijkstras = new Dijkstra(level);
            dijkstras = new Dijkstra(level);

            Stopwatch timer = new Stopwatch();
            AiBotAlgorithm bot = new AiBotAlgorithm(1, 1);
            Player player = new Player(level.GridSizeX - 1, level.GridSizeY - 1);
            for (int i = 0; i < 1000; i++)
            {

                timer.Restart();
                dijkstras.Build(level, bot, player);
                timer.Stop();
                r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds);
            }
            r.Close();
            #endif

            #if PRECOMPUTETEST
            StreamWriter r = new StreamWriter("precomputeTest-" + mapName + ".txt");

            string mapDescription = "";
            r.WriteLine("Precompute's Test values");
            r.WriteLine("Map size: {0}x{1}", level.GridSizeX, level.GridSizeY);
            r.WriteLine(mapDescription);
            r.WriteLine("Times per build, in ms");

            Precompute precompute = new Precompute(mapName);
            precompute = new Precompute(mapName);

            Stopwatch timer = new Stopwatch();
            AiBotAlgorithm bot = new AiBotAlgorithm(1, 1);
            Player player = new Player(level.GridSizeX - 1, level.GridSizeY - 1);
            for (int i = 0; i < 1; i++)
            {

                timer.Restart();
                precompute.Calculate(level);
                timer.Stop();
                r.WriteLine("{0:N3}", timer.Elapsed.TotalMilliseconds);
            }
            r.Close();
            #endif
        }
Example #3
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;
            }
        }