Ejemplo n.º 1
0
        public void TestClosePosition()
        {
            const string message =
                "P 14 14 0 35 5#0\n" +
                "P 7.2951994 8.103587 1 100 5#1\n" +
                "P 5.5505366 11.114068 2 100 5#2\n" +
                "P 4.8750625 8.711828 0 86 4#3\n" +
                "P 7.181268 10.048343 0 68 3#4\n" +
                "P 8.658058 13.022591 0 15 3#5\n" +
                "P 10.4961 9.850982 0 15 3#6\n" +
                "P 17.795769 17.857422 0 79 5#7\n" +
                "P 19.234045 15.375622 0 79 5#8\n" +
                "P 17.824682 18.873695 0 84 3#9\n" +
                "P 20.130194 14.89545 0 84 3#10\n" +
                "P 20.19213 8.496058 0 20 2#11\n" +
                "P 12.30302 22.109013 0 20 2#12\n" +
                "P 5.0697794 15.698908 0 31 2#13\n" +
                "P 11.034236 5.4070163 0 31 2#14\n" +
                "P 9.207518 9.434581 0 35 3#15\n" +
                "P 7.6561236 12.111569 0 35 3#16\n" +
                "P 5.7288275 13.711043 0 27 5#17\n" +
                "P 9.6371155 6.967146 0 27 5#18\n" +
                "go\n";

            PlanetWars pw = new PlanetWars(message);
            FirstMoveAdviser adviser = new FirstMoveAdviser(pw);
            List<MovesSet> movesSet = adviser.RunAll();

            Assert.IsTrue(movesSet.Count == 1);
            //go to 27 planet with 20 ships, to protect from RageBot and take bigger planet than 15
            Assert.AreEqual(20 + 8, movesSet[0].SummaryNumShips);
        }
Ejemplo n.º 2
0
        public void TestInvadeCorrectNumber2()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 10.946215 11.757139 0 15 4#0\n" +
                "P 18.033072 20.11299 1 6 5#1\n" +
                "P 3.859357 3.4012883 2 130 5#2\n" +
                "P 19.282667 9.50695 0 61 2#3\n" +
                "P 2.609762 14.007327 0 61 2#4\n" +
                "P 4.9880333 6.555844 0 15 2#5\n" +
                "P 16.904396 16.958433 1 5 2#6\n" +
                "P 17.819895 5.624568 0 79 3#7\n" +
                "P 4.0725336 17.88971 0 79 3#8\n" +
                "P 12.936233 0.2987193 0 36 1#9\n" +
                "P 8.956196 23.215559 0 36 1#10\n" +
                "P 0 23.514278 0 43 1#11\n" +
                "P 21.89243 0 0 43 1#12\n" +
                "P 13.72995 13.885786 0 59 2#13\n" +
                "P 8.162479 9.628491 0 59 2#14\n" +
                "P 7.9460754 4.9982805 0 87 2#15\n" +
                "P 13.946353 18.515997 0 87 2#16\n" +
                "P 5.118788 4.420579 0 26 1#17\n" +
                "P 16.773642 19.093699 1 6 1#18\n" +
                "P 17.77824 11.674772 0 62 1#19\n" +
                "P 4.1141887 11.839505 0 62 1#20\n" +
                "P 20.811337 21.04995 1 5 5#21\n" +
                "P 1.0810924 2.4643273 0 38 5#22\n" +
                "F 1 5 21 1 3 1\n" +
                "F 1 15 18 0 10 8\n" +
                "F 1 5 1 18 2 1\n" +
                "F 1 5 21 1 3 2\n" +
                "F 1 22 18 6 3 2\n" +
                "go\n"
                );

            IAdviser adviser = new InvadeAdviser(planetWars);
            List<MovesSet> movesList = adviser.RunAll();

            bool sended = false;
            foreach (MovesSet movesSet in movesList)
            {
                Moves moves = movesSet.GetMoves();
                foreach (Move move in moves)
                {
                    if (move.DestinationID != 0) continue;
                    sended = true;
                    Assert.AreEqual(1, move.NumShips);
                    Assert.AreEqual(0, move.TurnsBefore);
                }
            }
            Assert.IsTrue(sended);
        }
Ejemplo n.º 3
0
        public void TestDontStealWhenWeCant()
        {
            const string message =
                "P 0 0 1 1 1#0\n" +
                "P 0 11 0 44 5#1\n" +
                "P 12 9 2 10 5#2\n" +
                "F 2 45 2 1 12 12\n" +
                "go\n";
            PlanetWars pw = new PlanetWars(message);
            StealAdviser adviser = new StealAdviser(pw);

            List<MovesSet> moves = adviser.RunAll();

            Assert.AreEqual(0, moves.Count);
        }
Ejemplo n.º 4
0
        public void TestDoNothingWhenNoNeutralPlanets()
        {
            PlanetWars planetWars = new PlanetWars(
                "P 11.6135908004 11.6587374197 1 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 21 4#3\n" +
                "P 17.5788239251 5.05148236609 2 21 4#4\n" +
                "go\n");

            IAdviser adviser = new InvadeAdviser(planetWars);
            List<MovesSet> moves = adviser.RunAll();

            Assert.AreEqual(0, moves.Count);
        }
Ejemplo n.º 5
0
        public MovesSet(IEnumerable<Move> movesSet, double score, string adviserName, PlanetWars context)
        {
            this.context = context;
            MaxDistance = Int32.MinValue;
            MinDistance = Int32.MaxValue;
            AverageDistance = 0;
            SummaryNumShips = 0;
            NumShipsByTurns = 0;

            moves = new Moves();
            foreach (Move move in movesSet)
            {
                AddMove(move);
            }

            Score = score;
            AdviserName = adviserName;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void TestStealShipsNumber()
        {
            const string message =
                "P 0 0 1 10 1#0\n" +
                "P 0 11 0 44 5#1\n" +
                "P 12 9 2 0 0#2\n" +
                "F 2 45 2 1 12 12\n" +
                "go\n";
            PlanetWars pw = new PlanetWars(message);
            StealAdviser adviser = new StealAdviser(pw);

            List<MovesSet> moves = adviser.RunAll();

            Assert.AreEqual(1, moves.Count);
            Assert.AreEqual(1, moves[0].GetMoves().Count);
            Assert.AreEqual(1, moves[0].GetMove(0).DestinationID);
            Assert.AreEqual(7, moves[0].GetMove(0).NumShips);
            Assert.AreEqual(2, moves[0].GetMove(0).TurnsBefore);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void TestCorrectInvalidMove()
        {
            const string message =
                "P 15 15 0 8 5\n" +
                "P 23.1375337817 4.42693803291 1 5 5\n" +
                "P 26.6740203772 21.4595931483 2 68 5\n" +
                "P 1.98779865997 17.7017206246 0 68 1\n" +
                "P 13.7667813797 15.2560529225 0 66 3\n" +
                "P 20.8388714403 2.08783005806 0 67 3\n" +
                "P 25.4965514955 24.5204495171 0 67 3\n" +
                "P 5.37536683718 17.5350297684 0 98 2\n" +
                "P 5.16172014315 16.5060507641 0 98 2\n" +
                "P 3.70827139799 13.7270439881 0 17 1\n" +
                "P 5.14837144015 20.6629468078 0 17 1\n" +
                "P 12.9651908012 1.81647321654 0 99 3\n" +
                "P 18.3817114514 27.9038697523 0 99 3\n" +
                "P 18.28336772 17.717202368 0 92 3\n" +
                "P 16.9302631088 11.2002925607 0 92 3\n" +
                "P 11.3863458078 6.71683074497 0 92 5\n" +
                "P 14.9825486162 24.0370949413 0 92 5\n" +
                "F 2 9 2 0 14 8\n" +
                "F 2 18 2 9 25 19\n" +
                "F 2 18 2 10 22 16\n" +
                "F 1 74 1 0 14 9\n" +
                "F 1 36 1 0 14 10\n" +
                "F 1 5 1 0 14 11\n" +
                "F 1 2 1 0 14 12\n" +
                "F 1 3 1 9 22 20\n" +
                "F 1 5 1 0 14 13\n" +
                "F 2 17 2 9 25 24\n";
            PlanetWars pw = new PlanetWars(message);
            MyBot bot = new MyBot(pw);

            try
            {
                bot.DoTurn();
            }
            catch
            {
                Assert.IsTrue(false);
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void TestSteal()
        {
            const string message =
                "P 0 0 1 1 0#0\n" +
                "P 2 2 1 10 5#1\n" +
                "P 3 3 0 10 3#2\n" +
                "P 4 4 0 10 5#3\n" +
                "P 5 5 0 10 4#4\n" +
                "P 6 6 2 10 4#5\n" +
                "F 2 12 5 2 4 2\n" +
                "F 2 12 5 3 4 2\n" +
                "F 2 12 5 4 4 2\n";
            PlanetWars pw = new PlanetWars(message);
            StealAdviser adviser = new StealAdviser(pw);

            List<MovesSet> moves = adviser.RunAll();

            Assert.AreEqual(2, moves.Count);
            Assert.AreEqual(1, moves[1].GetMoves().Count);
            Assert.AreEqual(3, moves[1].GetMove(0).DestinationID);
        }
Ejemplo n.º 12
0
        public void TestDontGoToPlanetsCloserToEnemy()
        {
            const string message =
                "P 0 0 1 57 2#0\n" +
                "P 6 6 2 100 5#1\n" +
                "P 2 2 0 1 5#2\n" +
                "P 4 4 0 1 100#3\n" +
                "go\n";

            PlanetWars pw = new PlanetWars(message);
            FirstMoveAdviser adviser = new FirstMoveAdviser(pw);
            List<MovesSet> movesSet = adviser.RunAll();

            foreach (MovesSet set in movesSet)
            {
                Moves moves = set.GetMoves();
                foreach (Move move in moves)
                {
                    Assert.IsFalse(move.DestinationID == 3);
                }
            }
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
		public MyBot(PlanetWars planetWars)
		{
			Context = planetWars;
			DoCheckTime = true;
			InitLastMove();
		}
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void TestNoDoubleDefence()
        {
            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" +
                "F 1 35 0 2 5 2\n" +
                "go\n");

            IAdviser adviser = new DefendAdviser(planetWars);
            List<MovesSet> moves = adviser.RunAll();

            Assert.AreEqual(0, moves.Count);
        }
Ejemplo n.º 17
0
        public void TestParseManyFleets()
        {
            #region
            PlanetWars pw = new PlanetWars(
                "P 0 0 2 15 4#0\n" +
                "F 2 29 12 17 14 1\n" +
                "F 1 5 9 15 13 1\n" +
                "F 2 4 8 17 13 1\n" +
                "F 1 5 9 15 13 2\n" +
                "F 1 5 9 15 13 3\n" +
                "F 1 5 9 15 13 4\n" +
                "F 1 5 9 15 13 5\n" +
                "F 1 9 1 15 8 1\n" +
                "F 1 5 9 15 13 6\n" +
                "F 2 2 3 12 8 1\n" +
                "F 2 2 3 12 8 2\n" +
                "F 1 9 1 15 8 2\n" +
                "F 1 5 9 15 13 7\n" +
                "F 1 4 6 1 6 1\n" +
                "F 1 9 1 15 8 3\n" +
                "F 1 5 9 15 13 8\n" +
                "F 2 9 16 12 6 1\n" +
                "F 2 4 5 16 6 1\n" +
                "F 2 5 2 8 6 1\n" +
                "F 2 2 3 12 8 3\n" +
                "F 1 4 6 1 6 2\n" +
                "F 1 9 1 15 8 4\n" +
                "F 1 5 9 15 13 9\n" +
                "F 2 5 10 8 6 2\n" +
                "F 2 9 16 12 6 2\n" +
                "F 2 4 5 16 6 2\n" +
                "F 2 5 2 8 6 2\n" +
                "F 2 2 3 12 8 4\n" +
                "F 2 5 10 8 6 3\n" +
                "F 2 48 12 19 4 1\n" +
                "F 2 9 16 19 4 1\n" +
                "F 2 92 8 19 7 4\n" +
                "F 2 5 2 8 6 3\n" +
                "F 2 2 3 19 6 3\n" +
                "F 2 4 5 16 6 3\n" +
                "F 1 4 6 1 6 3\n" +
                "F 1 5 9 1 7 4\n" +
                "F 1 9 1 15 8 5\n" +
                "F 1 25 4 13 6 4\n" +
                "F 1 4 6 15 6 4\n" +
                "F 1 6 1 6 6 4\n" +
                "F 1 5 9 1 7 5\n" +
                "F 2 12 12 19 4 2\n" +
                "F 2 5 10 8 6 4\n" +
                "F 2 6 19 13 9 7\n" +
                "F 2 9 16 19 4 2\n" +
                "F 2 2 3 19 6 4\n" +
                "F 2 5 2 8 6 4\n" +
                "F 2 11 8 13 6 4\n" +
                "F 2 4 5 16 6 4\n" +
                "F 2 3 12 19 4 3\n" +
                "F 2 5 10 8 6 5\n" +
                "F 2 5 19 13 9 8\n" +
                "F 2 9 16 19 4 3\n" +
                "F 2 2 3 19 6 5\n" +
                "F 2 5 2 8 6 5\n" +
                "F 2 11 8 13 6 5\n" +
                "F 2 4 5 16 6 5\n" +
                "F 1 4 6 15 6 5\n" +
                "F 1 5 1 6 6 5\n" +
                "F 1 5 9 1 7 6\n" +
                "go\n");
            #endregion

            //actually 61, but 42 grouped
            Assert.AreEqual(42, pw.Fleets().Count);

            int num = 0;
            foreach (Fleet fleet in pw.Fleets())
            {
                num += fleet.NumShips();
            }
            Assert.AreEqual(506, num);
        }
Ejemplo n.º 18
0
        public void TestNoOverShips()
        {
            const string message =
                "P 9.790385 11.939511 0 3 4#0\n" +
                "P 13.135618 2.07503 1 100 5#1\n" +
                "P 6.4451513 21.803991 2 100 5#2\n" +
                "P 0 3.3089578 0 58 1#3\n" +
                "P 19.58077 20.570065 0 58 1#4\n" +
                "P 11.975901 0.2549936 0 69 1#5\n" +
                "P 7.604869 23.624027 0 69 1#6\n" +
                "P 4.7522573 6.9940777 0 48 1#7\n" +
                "P 14.828512 16.884945 0 48 1#8\n" +
                "P 14.284102 12.164202 0 82 2#9\n" +
                "P 5.296667 11.71482 0 82 2#10\n" +
                "P 18.723335 9.709133 0 6 4#11\n" +
                "P 0.8574339 14.1698885 0 6 4#12\n" +
                "P 18.553186 5.650815 0 17 4#13\n" +
                "P 1.0275841 18.228207 0 17 4#14\n" +
                "P 3.260637 6.3643866 0 47 2#15\n" +
                "P 16.320133 17.514635 0 47 2#16\n" +
                "P 6.901025 0 0 49 2#17\n" +
                "P 12.679745 23.879023 0 49 2#18\n" +
                "P 18.747196 2.6167994 0 28 3#19\n" +
                "P 0.8335743 21.262222 0 28 3#20\n" +
                "P 5.718854 1.5311116 0 11 3#21\n" +
                "P 13.861916 22.34791 0 11 3#22\n" +
                "go\n";

            PlanetWars pw = new PlanetWars(message);
            FirstMoveAdviser adviser = new FirstMoveAdviser(pw);
            List<MovesSet> movesSet = adviser.RunAll();

            Assert.AreEqual(1, movesSet.Count);
            int ships = 0;
            foreach (Move move in movesSet[0].GetMoves())
            {
                ships += move.NumShips;
            }
            Console.WriteLine(ships);
            Assert.IsTrue(100 >= ships);
        }
Ejemplo n.º 19
0
 public FirstMoveAdviser(PlanetWars context)
     : base(context)
 {
 }
Ejemplo n.º 20
0
		public AttackAdviser(PlanetWars context)
			: base(context)
		{
		}
Ejemplo n.º 21
0
        public void TestSerializationForLOG()
        {
            PlanetWars pw = new PlanetWars(
                "P 0 0 2 10 5#0\n" +
                "F 1 7 3 1 8 3\n" +
                "go\n");

            const string result =
                "\"P 0 0 2 10 5#0\\n\" +\n" +
                "\"F 1 7 3 1 8 3\\n\" +\n" +
                "\"go\\n\"\n";

            Assert.AreEqual(result, PlanetWars.SerializeGameState(pw, true));
        }
Ejemplo n.º 22
0
 public PlanetWars CreateTestContextForSort()
 {
     Context = new PlanetWars(CreateTestMessageForSort());
     return Context;
 }
Ejemplo n.º 23
0
		public static void Main()
		{
			CultureInfo myCulture = new CultureInfo("en-US");
			Thread.CurrentThread.CurrentCulture = myCulture;

			turn = 0;
			string line = "";
			string message = "";
			try
			{
				int c;
				while ((c = Console.Read()) >= 0)
				{
					switch (c)
					{
						case '\n':
							line = line.Trim();
							if (line.Equals("go"))
							{
								turn++;
								Config.CurrentTurn = turn;
								PlanetWars pw = new PlanetWars(message);
#if LOG
								Logger.Log("");
								Logger.Log(
									"Turn " + Convert.ToString(turn) +
									" (" +
									"ships " +
									Convert.ToString(pw.MyTotalShipCount) + "/" + Convert.ToString(pw.EnemyTotalShipCount) + " " +
									"planets " +
									Convert.ToString(pw.MyPlanets().Count) + "/" + Convert.ToString(pw.EnemyPlanets().Count) + " " +
									"prod " +
									Convert.ToString(pw.MyProduction) + "/" + Convert.ToString(pw.EnemyProduction) + " " +
									")");
#endif
								if (bot == null)
									bot = new MyBot(pw);
								else
									bot.Context = pw;
								bot.DoTurn();
#if LOG
								//Logger.Log("  Turn time: " + (DateTime.Now - startTime).TotalMilliseconds);
#endif
								message = "";
							}
							else
							{
								message += line + "\n";
							}
							line = "";
							break;
						default:
							if (line == "")
							{
								//start reading data
								startTime = DateTime.Now;
							}
							line += (char) c;
							break;
					}
				}
			}
// ReSharper disable EmptyGeneralCatchClause
			catch
// ReSharper restore EmptyGeneralCatchClause
			{
				// Owned.
			}
		}
Ejemplo n.º 24
0
        public void TestReturners()
        {
            const string message =
                "P 0 0 1 100 5#0\n" +
                "P 9 0 2 100 5#1\n" +
                "P 2 0 0 59 5#2\n" +
                "go\n";

            PlanetWars pw = new PlanetWars(message);
            FirstMoveAdviser adviser = new FirstMoveAdviser(pw);
            List<MovesSet> movesSet = adviser.RunAll();

            Assert.AreEqual(1, movesSet.Count);
            Assert.AreEqual(1, movesSet[0].GetMoves().Count);
            Assert.AreEqual(60, movesSet[0].GetMoves()[0].NumShips);
        }
Ejemplo n.º 25
0
 public Comparer(PlanetWars context)
 {
     Context = context;
 }
Ejemplo n.º 26
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)));
        }
Ejemplo n.º 27
0
 public SupplyAdviser(PlanetWars context)
     : base(context)
 {
 }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
 public DefendAdviser(PlanetWars context)
     : base(context)
 {
 }
Ejemplo n.º 30
0
        public void TestDoSomething()
        {
            const string message =
                "P 10.621908 8.30391 0 129 0#0\n" +
                "P 10.514905 1.7481457 1 100 5#1\n" +
                "P 10.728911 14.859674 2 100 5#2\n" +
                "P 13.951591 15.502133 0 88 2#3\n" +
                "P 7.292225 1.1056871 0 88 2#4\n" +
                "P 2.2078469 13.372326 0 87 4#5\n" +
                "P 19.035969 3.235495 0 87 4#6\n" +
                "P 5.829895 0 0 90 1#7\n" +
                "P 15.41392 16.60782 0 90 1#8\n" +
                "P 13.174852 11.510555 0 1 4#9\n" +
                "P 8.068963 5.0972652 0 1 4#10\n" +
                "P 21.243816 1.3553712 0 8 2#11\n" +
                "P 0 15.252449 0 8 2#12\n" +
                "P 16.312483 1.6560206 0 8 1#13\n" +
                "P 4.9313326 14.9518 0 8 1#14\n" +
                "P 7.9964867 7.850896 0 24 3#15\n" +
                "P 13.247329 8.756925 0 24 3#16\n" +
                "P 19.656878 1.6819931 0 3 2#17\n" +
                "P 1.5869379 14.925827 0 3 2#18\n" +
                "P 9.85971 10.874075 0 76 2#19\n" +
                "P 11.384106 5.7337456 0 76 2#20\n" +
                "P 2.0674944 1.7542361 0 80 5#21\n" +
                "P 19.176321 14.853584 0 80 5#22\n" +
                "go\n";

            PlanetWars pw = new PlanetWars(message);
            FirstMoveAdviser adviser = new FirstMoveAdviser(pw);
            List<MovesSet> movesSet = adviser.RunAll();

            Assert.IsTrue(movesSet.Count > 0);
        }