示例#1
0
        public void TestRetreat()
        {
            using (var consoleOutput = new ConsoleOutput())
            {
                var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1);
                var bot   = new MyBot();

                state.StartNewTurn();
                state.AddAnt(16, 15, 0);
                state.AddAnt(12, 16, 1);
                state.AddAnt(12, 15, 1);
                state.AddAnt(12, 17, 1);

                var initDist = state.EnemyAnts.Select(x => state.GetDistance(state.MyAnts[0], x)).ToList();

                bot.DoTurn(state);

                ApplyTurn(state, consoleOutput.GetOuput());
                consoleOutput.Clear();


                var finalDist = state.EnemyAnts.Select(x => state.GetDistance(state.MyAnts[0], x)).ToList();


                for (int i = 0; i < initDist.Count; i++)
                {
                    Assert.Greater(finalDist[i], initDist[i]);
                }
            }
        }
示例#2
0
        public void PerformanceIssue()
        {
            Assert.Fail();

            GameState state = new GameState(10, 10, 1, 1, 1, 5, 1);

            state.Set(new Tile[, ]
            {
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, a, a, a, a, a, a, _, _ },
                { _, _, a, a, w, a, a, a, _, _ },
                { _, _, a, a, w, a, a, a, _, _ },
                { _, _, a, a, f, a, a, a, _, _ },
                { _, _, a, a, a, A, a, a, _, _ },
                { _, _, a, a, a, a, a, a, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
            });

            Bot dut = new MyBot();

            dut.Initialize(state);

            dut.DoTurn(state);
        }
示例#3
0
        public void TestNoCollision1()
        {
            GameState state = new GameState(10, 10, 1, 1, 1, 5, 1);

            state.Set(new Tile[, ]
            {
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, a, a, a, a, a, a, _, _ },
                { _, _, a, a, w, a, a, a, _, _ },
                { _, _, a, a, w, a, a, a, _, _ },
                { _, _, a, a, f, a, a, a, _, _ },
                { _, _, a, a, a, a, a, a, _, _ },
                { _, _, a, a, a, a, a, a, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
                { _, _, _, _, _, _, _, _, _, _ },
            });

            MyBot dut = new MyBot();

            dut.Initialize(state);

            for (int i = 0; i < 10; i++)
            {
                dut.Cook(state);
            }


            dut.DoTurn(state);

            bool takeFood = false;

            foreach (Ant a in state.MyAnts)
            {
                Assert.IsTrue(a.hasMoved);
                Vector2i dst = a.position + Vector2i.AllDirections[(int)a.direction];
                if (state.map[dst.x, dst.y].isFood)
                {
                    takeFood = true;
                }
            }
            Assert.IsTrue(takeFood);


            for (int i = 0; i < state.MyAnts.Count; i++)
            {
                Ant      a    = state.MyAnts[i];
                Vector2i aPos = a.position + Vector2i.AllDirections[(int)a.direction];
                for (int j = 0; j < i; j++)
                {
                    Ant      b    = state.MyAnts[j];
                    Vector2i bPos = b.position + Vector2i.AllDirections[(int)b.direction];

                    Assert.AreNotEqual(aPos, bPos);
                }
            }
        }
示例#4
0
        public void GetFood()
        {
            using (var consoleOutput = new ConsoleOutput())
            {
                var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1);
                var bot   = new MyBot();


                state.StartNewTurn();
                state.AddAnt(16, 16, 0);
                state.AddFood(17, 16);

                Func <Location, Ant> test = x => state.MyAnts.Select(ant => (x.Row == ant.Row && x.Col == ant.Col) ? ant : null).Where(y => y != null).FirstOrDefault();

                Assert.NotNull(test(state.MyAnts[0]));
                Assert.NotNull(test(new Ant(16, 16, 0)));
                Assert.NotNull(test(new Location(16, 16)));

                var result = MyBot.FindClosest(state, state.FoodTiles[0], test);
                Assert.NotNull(result);


                bot.DoTurn(state);

                Assert.AreEqual("o 16 16 s\r\n", consoleOutput.GetOuput());

                consoleOutput.Clear();


                state.StartNewTurn();
                state.AddAnt(16, 16, 0);
                state.AddFood(15, 16);

                bot.DoTurn(state);

                Assert.AreEqual("o 16 16 n\r\n", consoleOutput.GetOuput());
            }
        }
示例#5
0
        public void TestRegroup()
        {
            using (var consoleOutput = new ConsoleOutput())
            {
                var state = new GameState(32, 32, int.MaxValue, 100, 25, 5, 1);
                var bot   = new MyBot();

                state.StartNewTurn();
                state.AddAnt(18, 15, 0);
                state.AddAnt(16, 16, 0);
                state.AddAnt(18, 17, 0);

                state.AddAnt(12, 15, 1);
                state.AddAnt(12, 17, 1);

                {//Extra test for platoon + BuildFrontLine
                    List <Ant> Platoon = new List <Ant>();
                    Battle.BuildPlatoon(state, Platoon, new Ant(16, 16, 0));
                    Assert.AreEqual(3, Platoon.Count);

                    List <Ant> EPlatoon = new List <Ant>();
                    Battle.BuildPlatoon(state, EPlatoon, new Ant(12, 15, 1));
                    Assert.AreEqual(2, EPlatoon.Count);

                    var AllyDist = Battle.BuildFrontline(state, Platoon, EPlatoon, out int qty, out int distance);
                    Assert.AreEqual(1, qty);
                    Assert.AreEqual(6, AllyDist[Platoon.IndexOf(new Ant(18, 15, 0))]);
                    Assert.AreEqual(5, AllyDist[Platoon.IndexOf(new Ant(16, 16, 0))]);
                    Assert.AreEqual(5, distance);

                    var EnemyDist = Battle.BuildFrontline(state, EPlatoon, Platoon, out int Eqty, out int Edistance);
                    Assert.AreEqual(2, Eqty);
                }

                bot.DoTurn(state);
                consoleOutput.originalOutput.Write(consoleOutput.GetOuput());
                ApplyTurn(state, consoleOutput.GetOuput());
                consoleOutput.Clear();

                Assert.Contains(new Ant(17, 15, 0), state.MyAnts);
                Assert.Contains(new Ant(16, 16, 0), state.MyAnts);
                Assert.Contains(new Ant(17, 17, 0), state.MyAnts);
            }
        }