Exemplo n.º 1
0
        public void testSpeed()
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var input = new StreamReader("../../../example-input-start.txt");

            Console.SetIn(input);

            var gameState = Bot.InitGameState();

            var input1 = new StreamReader("../../../example-input-turn1.txt");

            Console.SetIn(input1);

            var planets = Bot.ReadPlanets();
            var ships   = Bot.ReadShips();
            var turn    = 1;

            Bot.AdjustGamestateForTurn(turn, gameState, planets, ships);

            var moves = TheMoleStrategy.PlayTurn(gameState, turn, new Stopwatch());

            var input2 = new StreamReader("../../../example-input-turn2.txt");

            Console.SetIn(input2);

            planets = Bot.ReadPlanets();
            ships   = Bot.ReadShips();
            turn++;
            Bot.AdjustGamestateForTurn(turn, gameState, planets, ships);

            moves = TheMoleStrategy.PlayTurn(gameState, turn, new Stopwatch());



            var input3 = new StreamReader("../../../example-input-speed2.txt");

            Console.SetIn(input3);
            var watch = System.Diagnostics.Stopwatch.StartNew();

            planets = Bot.ReadPlanets();
            ships   = Bot.ReadShips();
            var x1 = watch.ElapsedTicks;

            turn++;
            Bot.AdjustGamestateForTurn(turn, gameState, planets, ships);
            var x2 = watch.ElapsedTicks;

            moves = TheMoleStrategy.PlayTurn(gameState, turn, new Stopwatch());
            watch.Stop();
            var x3 = watch.ElapsedTicks;
            var x4 = watch.ElapsedTicks;
        }
Exemplo n.º 2
0
        public void Take_into_account_incoming_enemy_reinforcements_when_trying_to_take_over_planet()
        {
            var enemyHealth        = 1F;
            var enemyDistanceTurns = 3;
            var enemyPlanet        = CreateEnemyPlanet(health: enemyHealth, x: 0, y: enemyDistanceTurns * CH.ShipSpeed);
            var planets            = new List <Planet> {
                CreatePlanet(), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets, new Ship[] { CreateEnemyShip(enemyPlanet, enemyDistanceTurns, 3) });

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.LessOrEqual(enemyPlanet.GetHealthAtTurnKnown(enemyDistanceTurns).health, moves.Single().Power);
        }
Exemplo n.º 3
0
        public void Take_into_account_planet_growth_when_trying_to_take_over_planet()
        {
            var enemyHealth        = 1F;
            var enemyDistanceTurns = 3;
            var enemyPlanet        = CreateEnemyPlanet(health: enemyHealth, x: 0, y: enemyDistanceTurns * CH.ShipSpeed);
            var planets            = new List <Planet> {
                CreatePlanet(), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets);

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.LessOrEqual(enemyHealth + enemyPlanet.GrowthSpeed * enemyDistanceTurns, moves.Single().Power);
        }
Exemplo n.º 4
0
        public void Dont_send_more_power_then_needed_to_turn_neutral_planet()
        {
            var enemyDistanceTurns = 3;
            var enemyPlanet        = CreatePlanet(health: 3F, x: 0, y: enemyDistanceTurns * CH.ShipSpeed, owner: null);
            var planets            = new List <Planet> {
                CreatePlanet(), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets);

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.LessOrEqual(3F, moves.Single().Power);
            Assert.GreaterOrEqual(3F + 2, moves.Single().Power);
        }
Exemplo n.º 5
0
        public void Dont_send_more_ships_when_already_enough_power_inbound_to_take_over_enemy_planet()
        {
            var enemyHealth        = 1F;
            var enemyDistanceTurns = 3;
            var enemyPlanet        = CreateEnemyPlanet(health: enemyHealth, x: 0, y: enemyDistanceTurns * CH.ShipSpeed);
            var planets            = new List <Planet> {
                CreatePlanet(), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets, new [] { CreateShip(enemyPlanet, enemyDistanceTurns, 10) });

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.AreEqual(0, moves.Length);
        }
Exemplo n.º 6
0
        public void Obliterate_Single_Weak_Enemy()
        {
            var enemyHealth = 1F;
            var myPlanet    = CreatePlanet();
            var enemyPlanet = CreateEnemyPlanet(health: enemyHealth, x: 0, y: 1F);
            var planets     = new List <Planet> {
                myPlanet, enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets);

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.AreEqual(1, moves.Length);
            Assert.AreEqual(myPlanet.Id, moves.Single().Source);
            Assert.AreEqual(enemyPlanet.Id, moves.Single().Target);
            Assert.LessOrEqual(enemyHealth, moves.Single().Power);
        }
Exemplo n.º 7
0
        public void Dont_send_more_power_then_needed_to_turn_planet()
        {
            var enemyDistanceTurns = 3;
            var health             = 1F;
            var enemyPlanet        = CreateEnemyPlanet(health: health, x: 0, y: enemyDistanceTurns * CH.ShipSpeed);
            var planets            = new List <Planet> {
                CreatePlanet(), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            var gameState = CreateGameState(planets);

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            var enemyHealth = health + enemyDistanceTurns * enemyPlanet.GrowthSpeed;
            var power       = moves.Single().Power;

            Assert.LessOrEqual(enemyHealth, power);
            Assert.GreaterOrEqual(enemyHealth + 2, power);
        }
Exemplo n.º 8
0
        // biggest first because it generates health more quickly
        public void Obliterate_Biggest_Of_Two_Enemy_Planets()
        {
            var enemyHealth = 6F;
            var myPlanet    = CreatePlanet();
            var enemyPlanet = CreateEnemyPlanet(health: enemyHealth, x: 1F, y: 0, radius: 10);
            var planets     = new List <Planet> {
                myPlanet, CreateEnemyPlanet(health: enemyHealth, x: 0, y: 1F, radius: 1), enemyPlanet
            };

            Connect(planets[0], planets[1]);
            Connect(planets[0], planets[2]);
            var gameState = CreateGameState(planets);

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.AreEqual(1, moves.Length);
            Assert.AreEqual(myPlanet.Id, moves.Single().Source);
            Assert.AreEqual(enemyPlanet.Id, moves.Single().Target);
            Assert.LessOrEqual(enemyHealth, moves.Single().Power);
        }
Exemplo n.º 9
0
        public void AttackNeutralWithTwoPlanets()
        {
            var planet1       = CreatePlanet(29.9F, 26.693428F, 0, 200.47342F, 150.36024F);
            var planet2       = CreatePlanet(19.9F, 30.496107F, 0, 93.75485F, 61.48056F);
            var enemyHealth   = 47F;
            var planetNeutral = CreatePlanet(enemyHealth, 28.83773F, owner: null, 83.12419F, 237.5396F);

            Connect(planet1, planet2);
            Connect(planet1, planetNeutral);
            Connect(planet2, planetNeutral);
            var gameState = CreateGameState(new List <Planet> {
                planet1, planet2, planetNeutral
            });

            var moves = TheMoleStrategy.PlayTurn(gameState, 1, new Stopwatch());

            Assert.AreEqual(2, moves.Length);
            Assert.AreEqual(1, moves.Count(m => m.Source == planet1.Id));
            Assert.AreEqual(1, moves.Count(m => m.Source == planet2.Id));
            Assert.AreEqual(2, moves.Count(m => m.Target == planetNeutral.Id));
            Assert.LessOrEqual(enemyHealth, moves.Sum(m => m.Power));
        }
Exemplo n.º 10
0
        public void testTurnInit()
        {
            var output = new StringWriter();

            Console.SetOut(output);

            var input = new StreamReader("../../../example-input-start.txt");

            Console.SetIn(input);

            var gameState = Bot.InitGameState();

            var input1 = new StreamReader("../../../example-input-turn1.txt");

            Console.SetIn(input1);

            var planets = Bot.ReadPlanets();
            var ships   = Bot.ReadShips();
            var turn    = 1;

            Bot.AdjustGamestateForTurn(turn, gameState, planets, ships);

            var moves = TheMoleStrategy.PlayTurn(gameState, turn, new Stopwatch());

            var input2 = new StreamReader("../../../example-input-turn2.txt");

            Console.SetIn(input2);

            planets = Bot.ReadPlanets();
            ships   = Bot.ReadShips();
            turn++;
            Bot.AdjustGamestateForTurn(turn, gameState, planets, ships);

            moves = TheMoleStrategy.PlayTurn(gameState, turn, new Stopwatch());

            Assert.AreEqual(1, gameState.Ships.Count);// is al niet meer 1 omdat PlayTurn er ook 1 toevoegd...
            Assert.AreEqual(1, gameState.PlanetsById[4].InboundShips.Count);
        }