示例#1
0
        public void TestCanSend()
        {
            int canSend = Context.CanSend(Context.GetPlanet(3));
            Assert.AreEqual(Context.GetPlanet(3).NumShips(), canSend);

            canSend = Context.CanSend(Context.GetPlanet(1));
            Assert.AreEqual(0, canSend);

            PlanetWars planetWars = new PlanetWars(
                "P 1 1 1 30 5#0\n" +
                "P 9 9 1 30 5#1 we need second planet to have Router.MaxDistance > 0\n" +
                "F 2 20 1 0 5 1\n" +
                "F 2 18 1 0 5 2\n" +
                "F 2 3 1 0 5 3\n" +
                "go\n");
            canSend = planetWars.CanSend(planetWars.GetPlanet(0));

            Assert.AreEqual(2, canSend);
        }
示例#2
0
        public void TestSupplyFrontPlanet()
        {
            const string message =
                "P 2 2 1 10 0#0\n" +
                "P 4 1 1 10 5#1\n" +
                "P 5 6 1 10 5#2\n" +
                "P 0 0 1 10 4#3\n" +
                "P 2 5 2 10 4#4\n" +
                "P 3 3 2 10 4#5\n";
            PlanetWars pw = new PlanetWars(message);

            IAdviser adviser = new SupplyAdviser(pw);
            Moves moves = adviser.Run(pw.GetPlanet(3));

            Assert.AreEqual(1, moves.Count);
            Assert.AreEqual(3, moves[0].SourceID);
            Assert.AreEqual(0, moves[0].DestinationID);
            Assert.AreEqual(10, moves[0].NumShips);
        }
示例#3
0
        public void TestDefendPlanetUnderAttack()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 11.6135908004 11.6587374197 0 119 0#0\n" +
                "P 1.2902863101 9.04078582767 1 40 5#1\n" +
                "P 21.9368952907 14.2766890117 2 100 5#2\n" +
                "P 2.64835767563 10.2659924733 1 31 4#3\n" +
                "P 17.5788239251 5.05148236609 0 21 4#4\n" +
                "F 1 25 1 4 5 3\n" +
                "F 1 50 1 2 10 1\n" +
                "F 2 70 2 1 5 3\n" +
                "go\n");

            DefendAdviser adviser = new DefendAdviser(planetWars);
            Moves moves = adviser.Run(planetWars.GetPlanet(1));

            Assert.AreEqual(1, moves.Count);
            Assert.AreEqual(3, moves[0].SourceID);
            Assert.AreEqual(1, moves[0].DestinationID);
            Assert.AreEqual(15 + Config.MinShipsOnPlanetsAfterDefend, moves[0].NumShips);
        }
示例#4
0
        public void TestDontSupplyFromEndangeredPlanets()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 10.9462142783 11.7571388049 1 24 4\n"+
                "P 18.033071482 20.1129893546 1 5 5\n"+
                "P 3.85935707472 3.40128825511 2 5 5\n"+
                "P 19.2826666634 9.50695040005 0 61 2\n"+
                "P 2.6097618933 14.0073272097 0 61 2\n"+
                "P 4.98803321494 6.55584398927 2 7 2\n"+
                "P 16.9043953417 16.9584336205 1 9 2\n"+
                "P 17.8198951395 5.6245678102 0 79 3\n"+
                "P 4.07253341715 17.8897097996 0 79 3\n"+
                "P 12.9362327012 0.298719287095 0 36 1\n"+
                "P 8.95619585546 23.2155583227 1 1 1\n"+
                "P 0.0 23.5142776098 0 43 1\n"+
                "P 21.8924285567 0.0 0 43 1\n"+
                "P 13.7299496073 13.8857860803 0 59 2\n"+
                "P 8.16247894941 9.62849152945 2 14 2\n"+
                "P 7.9460755228 4.99828064251 0 87 2\n"+
                "P 13.9463530339 18.5159969673 0 87 2\n"+
                "P 5.11878762985 4.42057885479 2 2 1\n"+
                "P 16.7736409268 19.093698755 1 7 1\n"+
                "P 17.7782398876 11.674772355 0 62 1\n"+
                "P 4.11418866912 11.8395052548 0 62 1\n"+
                "P 20.8113361481 21.049950329 0 19 5\n"+
                "P 1.08109240856 2.46432728074 2 5 5\n"+
                "F 2 16 14 10 14 13\n"+
                "F 1 2 0 10 12 12\n" +
                "go\n");

            /*Planets planets = planetWars.MyEndangeredPlanets(14, 0);
            Assert.IsTrue(planets.IndexOf(planetWars.GetPlanet(10)) >= 0);*/

            SupplyAdviser adviser = new SupplyAdviser(planetWars);

            Moves moves = adviser.Run(planetWars.GetPlanet(10));
            Assert.AreEqual(0, moves.Count);
        }
示例#5
0
        public void TestNoExtraDefence()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 10.619331099 20.0028830106 1 122 5#0\n" +
                "P 10.6897926 1.87550420275 2 18 5#1\n" +
                "P 6.42926362386 21.4118201349 1 5 4#2\n" +
                "F 2 50 1 2 20 14\n" +
                "F 2 27 1 2 20 15\n" +
                "F 2 16 1 2 20 16\n" +
                "F 2 11 1 2 20 17\n" +
                "F 2 8 1 2 20 18\n" +
                "go\n");

            DefendAdviser adviser = new DefendAdviser(planetWars);
            Moves moves = adviser.Run(planetWars.GetPlanet(2));

            int totalCount = 0;
            foreach (Move move in moves)
            {
                Assert.AreEqual(2, moves[0].DestinationID);
                totalCount = totalCount + move.NumShips;
            }

            Assert.AreEqual(12 + Config.MinShipsOnPlanetsAfterDefend, totalCount);
        }
示例#6
0
        public void TestCanSendInFuture()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 1 1 1 30 5#0\n" +
                "P 9 9 1 30 5#1 we need second planet to have Router.MaxDistance > 0\n" +
                "F 2 20 1 0 5 1\n" +
                "F 2 18 1 0 5 2\n" +
                "F 2 3 1 0 5 3\n" +
                "go\n");
            int canSend = planetWars.CanSend(planetWars.GetPlanet(0), 3);

            Assert.AreEqual(4, canSend);
        }
示例#7
0
        public void TestGetSector2()
        {
            PlanetWars pw = new PlanetWars(
                "P 0 2 1 5 0#0\n" +
                "P 1 0 1 5 0#1\n" +
                "go\n");

            Assert.AreEqual(Sectors.SouthEast, pw.GetSector(pw.GetPlanet(0), pw.GetPlanet(1)));
        }
示例#8
0
        public void TestGetSector()
        {
            PlanetWars pw = new PlanetWars(
                "P 10.946215 11.757139 0 15 4#0\n" +
                "P 18.033072 20.11299 1 5 5#1\n" +
                "go\n");

            Assert.AreEqual(Sectors.NordEast, pw.GetSector(pw.GetPlanet(0), pw.GetPlanet(1)));
            Assert.AreEqual(Sectors.SouthWest, pw.GetSector(pw.GetPlanet(1), pw.GetPlanet(0)));
        }
示例#9
0
        public void TestGetClosestPlanetsToTargetBySectors3()
        {
            PlanetWars pw = new PlanetWars(
                "P 0 2 1 5 0#0\n" +
                "P 0 4 1 5 0#1\n" +
                "P 1 0 1 5 0#2\n" +
                "P 5 1 1 5 0#3\n" +
                "P 5 5 1 5 0#4\n" +
                "P 10 0 1 5 0#5\n" +
                "P 9 5 1 5 0#6\n" +
                "P 11 3 1 5 0#7\n" +
                "P 11 2 2 5 0#8\n" +
                "go\n");

            Planets closestPlanets = pw.GetClosestPlanetsToTargetBySectors(pw.GetPlanet(0), pw.MyPlanets());

            Assert.AreEqual(2, closestPlanets.Count);
        }
示例#10
0
        public void TestGetClosestPlanetsToTargetBySectors()
        {
            PlanetWars pw = new PlanetWars(
                "P 10.946215 11.757139 0 15 4#0\n" +
                "P 18.033072 20.11299 1 5 5#1\n" +
                "P 28.033072 30.11299 1 5 5#1\n" +
                "go\n");

            Planets closestPlanets = pw.GetClosestPlanetsToTargetBySectors(pw.GetPlanet(0), pw.MyPlanets());

            Assert.AreEqual(1, closestPlanets.Count);
            Assert.AreEqual(1, closestPlanets[0].PlanetID());
        }
示例#11
0
        public void TestEnemyAid()
        {
            PlanetWars pw = new PlanetWars(
                "P 0 0 1 10 5#0\n" +
                "P 1 1 2 10 5#1\n" +
                "P 3 3 2 10 5#2\n" +
                "P 5 5 2 10 5#3\n" +
                "go\n");

            Assert.AreEqual(10 + 5*4 + 10 + 5*1, pw.GetEnemyAid(pw.GetPlanet(0), 6));
        }
示例#12
0
        public void TestCanSendShipNumber()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 11.613591 11.658737 0 119 0#0\n" +
                "P 1.2902863 9.040786 1 20 5#1\n" +
                "P 21.936895 14.276689 1 72 5#2\n" +
                "P 5.648358 18.265993 1 150 4#3\n" +
                "P 17.578823 5.051482 0 21 4#4\n" +
                "P 0 17.566463 1 2 2#5\n" +
                "P 23.227182 5.751012 0 32 2#6\n" +
                "P 15.9964075 22.492537 0 60 5#7\n" +
                "P 7.2307744 0.8249375 1 5 5#8\n" +
                "P 12.096861 23.317474 0 74 5#9\n" +
                "P 11.130321 0 1 6 5#10\n" +
                "P 5.9057293 2.4822736 0 85 1#11\n" +
                "P 17.321453 20.835201 0 85 1#12\n" +
                "P 18.286013 0.76577765 0 72 3#13\n" +
                "P 4.9411683 22.551697 0 72 3#14\n" +
                "P 20.10671 18.059385 2 5 5#15\n" +
                "P 3.120471 5.2580895 1 10 5#16\n" +
                "P 4.5948386 13.786 0 69 2#17\n" +
                "P 18.632343 9.531475 0 69 2#18\n" +
                "P 8.801192 20.015703 0 41 1#19\n" +
                "P 14.425989 3.3017714 0 41 1#20\n" +
                "P 19.466787 20.056168 1 39 5#21\n" +
                "P 3.7603943 3.2613065 1 5 5#22\n" +
                "F 1 10 8 3 18 1\n" +
                "F 1 10 8 3 18 2\n" +
                "F 1 5 8 3 18 3\n" +
                "F 1 9 3 15 15 1\n" +
                "F 1 5 8 3 18 4\n" +
                "F 1 10 3 15 15 2\n" +
                "F 1 20 8 3 18 5\n" +
                "F 1 11 3 15 15 3\n" +
                "F 1 20 8 3 18 6\n" +
                "F 1 11 3 15 15 4\n" +
                "F 1 11 3 15 15 5\n" +
                "F 1 57 8 4 12 3\n" +
                "F 1 5 1 3 11 4\n" +
                "F 1 5 1 3 11 5\n" +
                "F 1 5 1 3 11 6\n" +
                "F 1 2 5 3 6 1\n" +
                "F 1 15 16 1 5 1\n" +
                "F 1 5 1 3 11 7\n" +
                "F 1 2 5 3 6 2\n" +
                "F 1 2 5 3 6 3\n" +
                "F 1 15 16 1 5 2\n" +
                "F 1 5 1 3 11 8\n" +
                "F 1 20 1 3 11 9\n" +
                "F 1 2 5 3 6 4\n" +
                "F 1 10 16 1 5 3\n" +
                "F 1 5 22 16 3 1\n" +
                "F 2 54 15 2 5 4\n" +
                "F 1 5 22 16 3 2\n" +
                "F 1 10 16 1 5 4\n" +
                "F 1 2 5 3 6 5\n" +
                "F 1 20 1 3 11 10\n" +
                "F 1 88 8 10 4 3\n" +
                "go\n");
            int canSend = planetWars.CanSend(planetWars.GetPlanet(2));

            Assert.AreEqual(92-54, canSend);
        }
示例#13
0
        public void TestSupplyFrontPlanet2()
        {
            const string message =
                "P 13.3422077014 0.781586578168 1 100 5\n" +
                "P 9.83220591213 22.0204604189 2 100 5\n" +
                "P 19.6930466168 9.76544103518 2 2 4\n" +
                "P 20.2820697829 3.88811462784 1 7 1\n";
            PlanetWars pw = new PlanetWars(message);

            IAdviser adviser = new SupplyAdviser(pw);
            Moves moves = adviser.Run(pw.GetPlanet(0));

            Assert.AreEqual(1, moves.Count);
            /*Assert.AreEqual(3, moves[0].SourceID);
            Assert.AreEqual(0, moves[0].DestinationID);
            Assert.AreEqual(10, moves[0].NumSheeps);*/
        }
示例#14
0
        public void TestSupplyMoreThenOnce()
        {
            const string message =
                "P 1 1 1 10 5\n" +
                "P 2 2 1 10 5\n" +
                "P 3 3 1 10 5\n" +
                "P 4 4 2 10 5\n";
            PlanetWars pw = new PlanetWars(message);

            SupplyAdviser adviser = new SupplyAdviser(pw);

            Moves moves = adviser.Run(pw.GetPlanet(0));
            Assert.IsTrue(moves.Count > 0);
            Assert.AreEqual(1, moves[0].DestinationID);

            moves = adviser.Run(pw.GetPlanet(1));
            Assert.IsTrue(moves.Count > 0);
            Assert.AreEqual(2, moves[0].DestinationID);
        }
示例#15
0
        public void TestInvadeNeutralPlanet()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 1 1 0 119 2#0\n" +
                "P 2 2 1 150 5#1\n" +
                "P 3 3 2 100 5#2\n" +
                "P 6 6 1 21 2#3\n" +
                "P 5 5 0 21 5#4\n" +
                "go\n");

            Config.InvadeSendMoreThanEnemyCanDefend = true;

            IAdviser adviser = new InvadeAdviser(planetWars);
            Moves moves = adviser.Run(planetWars.GetPlanet(4));

            //int extraTurns = (int)Math.Ceiling(planetWars.GetPlanet(4).NumShips() / (double)planetWars.GetPlanet(4).GrowthRate());

            Assert.AreEqual(2, moves.Count);
            Assert.AreEqual(21 + 100 + 5 * 2 + 1, moves[0].NumShips + moves[1].NumShips);
        }