Beispiel #1
0
        public void ProcessSkill_AttackTest()
        {
            //Initialize necessary instances.
            BattleSimulator battleSim = this.BattleSimulator;

            //A custom attack skill used for the tests.
            Skill attackSkill = new Attack("attack", 1, 25, 999, Target.Opponent);

            //Initialize entities.
            Player player = this.Player;
            Enemy  enemy  = this.Enemy;

            //Give the player enough gauge to use the attack skill.
            player.Gauge = attackSkill.Gauge;
            //Trigger the skill.
            battleSim.ProcessSkill(attackSkill, player, enemy);

            //Verify to see if the player's gauge was consumed, which
            //indicates a successful execution.
            Assert.AreEqual <byte>(0, player.Gauge);

            //Follow up by making sure the enemy took
            //damage from the attack.
            Assert.AreNotEqual <short>(enemy.MaxHp, enemy.Hp);
        }
Beispiel #2
0
 public static bool IsNuke(JSON.Army army)
 {
     return
         (BattleSimulator.TotalAttackPower(army) > 4e5 &&
          ArmyStats.CalculateTotalPopulation(army.OfType(JSON.UnitBuild.Offensive)) > 10000 &&
          ArmyStats.CalculateTotalPopulation(army) > FullArmyPopulation);
 }
Beispiel #3
0
 public override void PostCombatEffect(BattleSimulator simulator)
 {
     if (Power != 0 && simulator.Chance(50))
     {
         Power += 1;
     }
 }
Beispiel #4
0
 public override void OnLeaveBattle(BattleSimulator simulator)
 {
     if ((Power <= 0) && (simulator.DarkSide.GetWarrior(simulator).Power > 0))
     {
         simulator.DarkSide.GetWarrior(simulator).DecreasePower(simulator, 1);
     }
 }
Beispiel #5
0
        public List <BattleTestResult> Test()
        {
            var result = new List <BattleTestResult>();

            var simulator = new BattleSimulator();

            foreach (var sample in testSamples)
            {
                var simulationResult = simulator.SimulateAttack(new Army(sample.Start.Attacker), new Army(sample.Start.Defender), sample.Start.Wall, sample.ArchersEnabled);

                var attackerError = sample.Expect.Attacker.Sum(kvp => Math.Abs(kvp.Value - simulationResult.AttackingArmy[kvp.Key]) / (float)(1 + (sample.Start.Attacker[kvp.Key] - kvp.Value)));
                var defenderError = sample.Expect.Defender.Sum(kvp => Math.Abs(kvp.Value - simulationResult.DefendingArmy[kvp.Key]) / (float)(1 + (sample.Start.Defender[kvp.Key] - kvp.Value)));

                var lossesError = attackerError + defenderError;
                var wallError   = Math.Abs(sample.Expect.Wall - simulationResult.NewWallLevel) / (1 + sample.Expect.Wall);

                var finalError = lossesError * 0.75f + wallError * 0.25f;

                result.Add(new BattleTestResult
                {
                    Passed       = finalError < MaxErrorPercent,
                    ErrorPercent = finalError,
                    Sample       = sample,
                    Index        = result.Count,
                    ActualResult = new BattleTestState
                    {
                        Wall     = simulationResult.NewWallLevel,
                        Attacker = simulationResult.AttackingArmy,
                        Defender = simulationResult.DefendingArmy
                    }
                });
            }

            return(result);
        }
Beispiel #6
0
 public override void OnJoinBattle(BattleSimulator simulator)
 {
     if (simulator.LightSide.Morale < simulator.DarkSide.Morale)
     {
         this.Power += 2;
     }
 }
Beispiel #7
0
        public void PerformSkillTest_EnemyHasNoGauge_SkillNotExecuted()
        {
            //Initialize required instances.
            GameBase        gb        = new GameBase(new RichTextBoxScroll());
            BattleSimulator battleSim = gb.BattleSimulator;

            //Initialize the enemy and player.
            Enemy  enemy  = this.Enemy;
            Player player = this.Player;

            //Create the AI for the enemy.
            EnemyAI ai = new EnemyAI(enemy);

            //Set the skill delay to 0 in order to
            //trigger skills right away.
            ai.MinSkillDelay = TimeSpan.FromMilliseconds(0);
            ai.MaxSkillDelay = TimeSpan.FromMilliseconds(0);

            //Trigger a skill against the player.
            Action <Skill, Entity, Entity> processSkill =
                new Action <Skill, Entity, Entity>(battleSim.ProcessSkill);

            ai.PerformSkill(processSkill, player);

            //We expect the skill to not trigger due to the enemy having
            //no gauge value.
            //Check to see if the player took any damage.
            //This should be false, since the enemy shouldn't be able
            //to execute any skills, and thus the player takes no
            //damage and has equal HP and MaxHP.
            bool condition = player.Hp != player.MaxHp;

            Assert.IsFalse(condition);
        }
Beispiel #8
0
        public override void PreCombatEffect(BattleSimulator simulator)
        {
            foreach (var opponent in simulator.DarkSide.Warriors)
            {
                if (!(opponent is Sith))
                {
                    return;
                }
            }
            Power += 2;

            //string w [] =

            //foreach (var w in )
            //{
            //    if (simulator.DarkSide.GetWarrior(simulator) is Sith)
            //{
            //        return;
            //}
            //    else
            //    {

            //    }
            //}
        }
Beispiel #9
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            BattleSimulator sim = new BattleSimulator();

            this.Hide();
            await sim.RandomBattle();
        }
Beispiel #10
0
 public override void OnJoinBattle(BattleSimulator simulator)
 {
     if (simulator.LightSide.Morale < simulator.DarkSide.Morale)
     {
         simulator.DarkSide.Morale += 2;
         Console.WriteLine($"A csapata új morálja: {simulator.DarkSide.Morale}");
     }
 }
Beispiel #11
0
        public void BattleTest()
        {
            BattleSimulator sim = new BattleSimulator(monkeyArmy, wizardArmy);

            sim.Battle();
            Assert.AreEqual(wizardArmy.Name, sim.Result.Winner.Name);
            Console.WriteLine(sim.Result);
        }
Beispiel #12
0
 public override void DecreasePower(BattleSimulator simulator, int power)
 {
     if (simulator.Chance(10))
     {
         Power -= power / 2;
     }
     Power -= power;
 }
Beispiel #13
0
 public override bool IsStrongerThan(BattleSimulator simulator, Warrior other)
 {
     if (other is ForceUser)
     {
         return(base.IsStrongerThan(simulator, other));
     }
     return(Power + 2 > other.Power);
 }
Beispiel #14
0
 private void CreateNonMonobehaviours()
 {
     units      = new Units();
     simulator  = new BattleSimulator();
     rule       = new BattleRuleLastTeam();
     statistics = new BattleStatistics();
     saveLoad   = new BattleSaveLoad();
 }
        public FightStat countFitness(Strategy tankStrategy)
        {
            var map             = new Map(Map);
            var enemyStrategy   = new Strategy(EnemyStrategy);
            var battleSimulator = new BattleSimulator(map, tankStrategy, enemyStrategy);

            return(battleSimulator.Execute());
        }
Beispiel #16
0
        public bool MeetsRequirement(decimal worldSpeed, decimal travelSpeed, Coordinate source, Coordinate target, Army army)
        {
            if (AllowedTypes != null)
            {
                army = army.Only(AllowedTypes);
            }

            return(BattleSimulator.AttackPower(army).Total >= MinimumOffense);
        }
        public static void Main(string[] args)
        {
            //var battleship = Battleship.CreateBattleShip("Raven");

            var factory = new ShipFactory <Battleship>();

            var raven    = factory.CreateShip(Battleships.Raven);
            var dominix  = factory.CreateShip(Battleships.Dominix);
            var rokh     = factory.CreateShip(Battleships.Rokh);
            var scorpion = factory.CreateShip(Battleships.Scorpion);

            var canon      = new Weapon(Weapons.Cannon, WeaponGrades.Large);
            var projectile = new Weapon(Weapons.Projectile, WeaponGrades.Large);
            var laser      = new Weapon(Weapons.Laser, WeaponGrades.Large);
            var missile    = new Weapon(Weapons.Missile, WeaponGrades.Large);

            raven.InstallWeapon(canon, 1);
            dominix.InstallWeapon(projectile, 1);
            rokh.InstallWeapon(laser, 1);
            scorpion.InstallWeapon(missile, 1);

            var attackingPlanetOffensiveFormation = new BattleFormation("ap of");
            var attackingPlanetDefensiveFormation = new BattleFormation("ap df");
            var defensivePlanetOffensiveFormation = new BattleFormation("dp of");
            var defensivePlanetDefensiveFormation = new BattleFormation("dp df");

            attackingPlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            attackingPlanetDefensiveFormation.SetFormationRow(dominix, 100, 1);
            defensivePlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            defensivePlanetDefensiveFormation.SetFormationRow(raven, 100, 1);


            var attackingPlanetOffensiveFormationGeneral = new General();
            var attackingPlanetDefensiveFormationGeneral = new General();
            var defensivePlanetOffensiveFormationGeneral = new General();
            var defensivePlanetDefensiveFormationGeneral = new General();

            attackingPlanetOffensiveFormation.SetGeneral(attackingPlanetOffensiveFormationGeneral);
            attackingPlanetDefensiveFormation.SetGeneral(attackingPlanetDefensiveFormationGeneral);
            defensivePlanetDefensiveFormation.SetGeneral(defensivePlanetDefensiveFormationGeneral);
            defensivePlanetOffensiveFormation.SetGeneral(defensivePlanetOffensiveFormationGeneral);

            var attackingPlanet = new Planet(Planets.Pandora);
            var defensivePlanet = new Planet(Planets.Desert);

            attackingPlanet.AddFormation(attackingPlanetOffensiveFormation);
            attackingPlanet.AddFormation(attackingPlanetDefensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetOffensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetDefensiveFormation);

            attackingPlanet.ActivateFormation(attackingPlanetOffensiveFormation, BattleFormationType.Offensive);
            attackingPlanet.ActivateFormation(attackingPlanetDefensiveFormation, BattleFormationType.Defensive);
            defensivePlanet.ActivateFormation(defensivePlanetOffensiveFormation, BattleFormationType.Offensive);
            defensivePlanet.ActivateFormation(defensivePlanetDefensiveFormation, BattleFormationType.Defensive);

            BattleSimulator.CalculateBattleResult(attackingPlanet, defensivePlanet);
        }
Beispiel #18
0
 public override void PreCombatEffect(BattleSimulator simulator)
 {
     foreach (var w in simulator.LightSide.Warriors)
     {
         if (w.IsForceUser)
         {
             simulator.LightSide.Morale -= 1;
         }
     }
     Console.WriteLine($"Az ellenfél új morálja: {simulator.LightSide.Morale}");
 }
 public override void OnJoinBattle(BattleSimulator simulator)
 {
     foreach (var w in simulator.DarkSide.Warriors)
     {
         if (w is Sith)
         {
             return;
         }
     }
     simulator.LightSide.Morale += 3;
 }
Beispiel #20
0
        private static void Main(string[] args)
        {
            var gameSettingsJson = File.ReadAllText(GameSettingsFileName);
            var gameSettings = JsonConvert.DeserializeObject<GameSettings>(gameSettingsJson);

            var gameDatabase = GameDatabase.CreateFromFiles(
                gameSettings.TypesFileName,
                gameSettings.MovesFileName,
                gameSettings.NeuromonFileName
            );

            var playerOneControllerFactory = PlayerControllerFactoryFactory.Create(
                gameSettings.PlayerOneType,
                gameSettings.NumberOfNeuromon,
                gameSettings.InputNeuronCount,
                gameSettings.OutputNeuronCount,
                gameSettings.PlayerOneBrain
            );

            var playerTwoControllerFactory = PlayerControllerFactoryFactory.Create(
                gameSettings.PlayerTwoType,
                gameSettings.NumberOfNeuromon,
                gameSettings.InputNeuronCount,
                gameSettings.OutputNeuronCount,
                gameSettings.PlayerTwoBrain
            );

            var randomNeuromonGenerator = new NeuromonCollectionGenerator(gameDatabase.Neuromon, gameSettings.NumberOfNeuromon);

            var playerOneState = new PlayerState(gameSettings.PlayerOneName, randomNeuromonGenerator.GenerateNeuromonCollection());
            var playerOneController = playerOneControllerFactory.CreatePlayer(playerOneState);
            var playerOne = new Player.Player(playerOneState, playerOneController);

            var playerTwoState = new PlayerState(gameSettings.PlayerTwoName, randomNeuromonGenerator.GenerateNeuromonCollection());
            var playerTwoController = playerTwoControllerFactory.CreatePlayer(playerTwoState);
            var playerTwo = new Player.Player(playerTwoState, playerTwoController);

            var damageCalculatorFactory = new DamageCalculatorFactory(
                gameSettings.EffectiveMultiplier, gameSettings.WeakMultiplier,
                gameSettings.MinimumRandomMultiplier, gameSettings.MaximumRandomMultiplier,
                gameSettings.NonDeterministic
            );

            var battleSimulator = new BattleSimulator(playerOne, playerTwo, damageCalculatorFactory.Create());

            Renderer renderer = null;

            if (gameSettings.ShouldRender)
            {
                renderer = new Renderer(battleSimulator, gameSettings.SimulateThinking);
            }

            battleSimulator.Run();
        }
Beispiel #21
0
    private void Awake()
    {
        if ((_instance != null) && (_instance != this))
        {
            Destroy(this.gameObject);
            return;
        }

        _instance = this;
        DontDestroyOnLoad(this.gameObject);
    }
    void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(instance);
        }
        instance = this;

#if UNITY_EDITOR
        loadFile();
#endif
    }
Beispiel #23
0
 public override void PreCombatEffect(BattleSimulator simulator)
 {
     foreach (var w in simulator.LightSide.Warriors)
     {
         if (w is Jedi)
         {
             {
                 simulator.LightSide.Morale -= 1;
                 Console.WriteLine("Az ellenfél morálját minden ellenséges Jedi után 1 ponttal csökkenti.");
             }
         }
     }
 }
Beispiel #24
0
        public Renderer(BattleSimulator battleSimulator, bool simulateThinking)
        {
            _battleSimulator = battleSimulator;
            _simulateThinking = simulateThinking;

            _moveRenderLength = CalculateMoveRenderLength();

            _battleSimulator.OnAttackMade += RenderAttack;
            _battleSimulator.OnNeuromonChanged += RenderNeuromonChanged;
            _battleSimulator.OnGameOver += RenderGameOver;
            _battleSimulator.OnGameStateChanged += OnGameStateChanged;
            _battleSimulator.OnNeuromonDefeated += OnNeuromonDefeated;
        }
Beispiel #25
0
        static void TestBattleSimulation()
        {
            var attackingArmy = new Army
            {
                { TroopType.Axe, 7000 },
                { TroopType.Light, 3000 },
                { TroopType.Ram, 220 },
                { TroopType.Catapult, 75 }
            };

            var defendingArmy = new Army
            {
                { TroopType.Spear, 10000 },
                { TroopType.Sword, 10000 }
            };

            int testWallLevel = 15;

            var simulator     = new BattleSimulator();
            var battleResults = simulator.SimulateAttackWithoutArchers(attackingArmy, defendingArmy, testWallLevel);

            Console.WriteLine("Attacker results:");
            PrintArmy(attackingArmy, battleResults.AttackingArmy);

            Console.WriteLine("\nDefender results:");
            PrintArmy(defendingArmy, battleResults.DefendingArmy);

            Console.WriteLine("\nWall level: {0} - {1} = {2}", testWallLevel, testWallLevel - battleResults.NewWallLevel, battleResults.NewWallLevel);

            DateTime start     = DateTime.UtcNow;
            int      numNukes  = 0;
            int      wallLevel = testWallLevel;

            while (true)
            {
                var partialResults = simulator.SimulateAttackWithoutArchers(attackingArmy, defendingArmy, wallLevel);
                wallLevel     = partialResults.NewWallLevel;
                defendingArmy = partialResults.DefendingArmy;
                ++numNukes;

                if (defendingArmy.Count == 0)
                {
                    break;
                }
            }
            DateTime end = DateTime.UtcNow;

            Console.WriteLine("It would take {0} total attacks like this to defeat all defending troops.", numNukes);
            Console.WriteLine("Took {0}ms to simulate", (end - start).TotalMilliseconds);
        }
        public override void OnJoinBattle(BattleSimulator simulator)
        {
            bool isSith = false;

            foreach (var s in simulator.DarkSide.Warriors)
            {
                if (s is Sith)
                {
                    isSith = true;
                }
            }
            if (isSith == false)
            {
                simulator.LightSide.Morale += 3;
            }
        }
Beispiel #27
0
 /// <summary>
 /// 5% eséllyel növeli csapata morálját 20 egységgel,
 /// ha ez nem sikerül akkor további 20% esélye van 5-el növelni azt.
 /// </summary>
 /// <param name="simulator">Simulator.</param>
 public override void OnJoinBattle(BattleSimulator simulator)
 {
     if (simulator.Chance(5))
     {
         simulator.LightSide.Morale += 20;
         Console.WriteLine($"Jar Jar nagyon szerencsés, csapata új morálja: {simulator.LightSide.Morale}");
     }
     else if (simulator.Chance(20))
     {
         simulator.LightSide.Morale += 5;
         Console.WriteLine($"Jar Jar szerencsés, csapata új morálja: {simulator.LightSide.Morale}");
     }
     else
     {
         Console.WriteLine($"Jar Jar semmit nem tett a csapatért...");
     }
 }
Beispiel #28
0
//        public static void Main()
//        {
//            Clear();
//            var configuration = Configuration.DeserializeFromFile(ConfigFilename);
//            var geneticAlgorithm = new GeneticAlgorithm(configuration);
//            geneticAlgorithm.Run();
//        }
//
//        private static void Clear()
//        {
//            for (int i = 0; i < 30; i++)
//            {
//                string folderName = $"Logs\\Generation{i}";
//                if (Directory.Exists(folderName))
//                    Directory.Delete(folderName, true);
//            }
//        }

        public static void Main()
        {
            var configuration = Configuration.DeserializeFromFile(ConfigFilename);

            var strategiesGenerator = new StrategiesGenerator(5000);
            var strategy            = strategiesGenerator.GenerateProgram();
            var enemyStrategy       = strategiesGenerator.GenerateEnemyProgram();

            System.IO.File.WriteAllLines("strategy.txt", strategy.commands);

            var mapGenerator = new MapGenerator(configuration);
            var map          = mapGenerator.GenerateMap();
            //   SerializeMap(map);

            var simulator = new BattleSimulator(map, strategy, enemyStrategy, true);

            var value = simulator.Execute();

            Console.WriteLine($"Fitness value: {value}");
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            TroopReader troopReader = new TroopReader();

            troopTypes = troopReader.Read();

            TroopFactory troopFactory = new TroopFactory(troopTypes);
            ArmyReader   armyReader   = new ArmyReader(troopFactory);

            armies = armyReader.Read();

            PrintArmy("Good Army");
            Console.WriteLine();
            PrintArmy("Bad Army");

            Army            a   = armies["Good Army"];
            Army            b   = armies["Bad Army"];
            BattleSimulator sim = new BattleSimulator(a, b);

            sim.Battle();
            Console.WriteLine(sim.Result);
            Console.ReadLine();
        }
Beispiel #30
0
    void ExecuteMove(Area origin, Area destination, List <Unit> _attackers)
    {
        //Make copy of attackers for looping when we might be altering the original (which derives from area lists)
        List <Unit> attackers = new List <Unit>(_attackers);

        Debug.Log(string.Format("Now attacking from {0} with {1} attackers into {2}", origin.name, attackers.Count, destination.name));
        if (destination.owner == origin.owner)
        {
            net.CmdRequestMoveUnits(attackers.Select(u => u.ID).ToArray(), origin.ID, destination.ID);
        }
        else
        {
            BattleInfo   info   = new BattleInfo(attackers, destination.units, destination);
            BattleResult result = BattleSimulator.SimulateBattle(info);
            foreach (Unit unit in result.units)
            {
                if (unit.dead)
                {
                    net.CmdRequestDespawnUnit(unit.ID);
                }
                else
                {
                    unit.Reset();
                }
            }
            if (result.victor != destination.owner)
            {
                net.CmdRequestChangeOwner(destination.ID, origin.owner.name);
                int[] unitIDs = attackers.Where(u => !u.dead).Select(u => u.ID).ToArray();
                net.CmdRequestMoveUnits(unitIDs, origin.ID, destination.ID);
            }
        }

        origin.selectable      = false;
        destination.selectable = false;
        InitSelectMoveFrom();
    }
Beispiel #31
0
        public void ProcessSkill_RecoveryTest()
        {
            //Initialize necessary instances.
            BattleSimulator battleSim = this.BattleSimulator;

            //A custom healing skill used for the tests.
            Skill attackSkill = new Heal("Heal", 1, 25, 999, Target.Self);

            //Initialize entities.
            Player player = this.Player;
            Enemy  enemy  = this.Enemy;

            //Give the player enough gauge to use the healing skill.
            player.Gauge = attackSkill.Gauge;

            //Damage the player to verify that Hp gets recovered.
            player.Hp = 1;

            //Damage the enemy to make sure the enemy is not
            //recovering from the skill as well.
            enemy.Hp = 1;

            //Trigger the skill.
            battleSim.ProcessSkill(attackSkill, player, enemy);

            //Verify to see if the player's gauge was consumed, which
            //indicates a successful execution.
            Assert.AreEqual <byte>(0, player.Gauge);

            //Follow up by making sure the player recovered Hp.
            Assert.IsTrue(player.Hp > 1);

            //Check to make sure the healing effects were not
            //also applied to the enemy's Hp.
            Assert.AreEqual <short>(1, enemy.Hp);
        }
Beispiel #32
0
        public void PerformSkillTest_EnemyHasMaxGauge_SkillIsExecuted()
        {
            //Initialize required instances.
            GameBase        gb        = new GameBase(new RichTextBoxScroll());
            BattleSimulator battleSim = gb.BattleSimulator;

            //Initialize the enemy and player.
            Enemy  enemy  = this.Enemy;
            Player player = this.Player;

            //Give the enemy maximum gauge to execute skills.
            enemy.Gauge = enemy.MaxGauge;

            //Create the AI for the enemy.
            EnemyAI ai = new EnemyAI(enemy);

            //Set the skill delay to 0 in order to
            //trigger skills right away.
            ai.MinSkillDelay = TimeSpan.FromMilliseconds(0);
            ai.MaxSkillDelay = TimeSpan.FromMilliseconds(0);

            //Trigger a skill against the player.
            Action <Skill, Entity, Entity> processSkill =
                new Action <Skill, Entity, Entity>(battleSim.ProcessSkill);

            ai.PerformSkill(processSkill, player);

            //We expect the skill to trigger and damage the player
            //due to having a sufficient amount of gauge.
            //Check to see if the player took any damage.
            //This should be true, since the enemy should be able
            //to execute skills which will damage the player's HP.
            bool condition = player.Hp != player.MaxHp;

            Assert.IsTrue(condition);
        }