Ejemplo n.º 1
0
Archivo: Unit.cs Proyecto: vbnet3d/AAA
        public static BattleResult RPSFullBattle(Unit[] attacker, Unit[] defender)
        {
            var b = new BattleResult();

            while (attacker.Length > 0 && defender.Length > 0 && UnitsThatCanFight(attacker, defender) && b.Rounds < 20)
            {
                // Battleships and Destroyers only give supporting bombardment on the first round.
                if (b.Rounds >= 1)
                {
                    if (attacker.Any(x => x.Name == "Battleship" || x.Name == "Destroyer") && attacker.Any(x => x.Name == "Infantry" || x.Name == "Tank"))
                    {
                        RemoveUnitType(attacker, "Battleship");
                        RemoveUnitType(attacker, "Destroyer");
                    }
                }

                BattleResult r = RPSBattleRound(attacker, defender);

                defender = RemoveUnits(defender, r.AttackHits, false, false, false, false);
                attacker = RemoveUnits(attacker, r.DefendHits, false, false, false, false);

                b.AttackHits += r.AttackHits;
                b.DefendHits += r.DefendHits;
                b.Rounds++;
            }

            return(b);
        }
Ejemplo n.º 2
0
Archivo: Unit.cs Proyecto: vbnet3d/AAA
        public static BattleResult RPSBattleRound(Unit[] Attacker, Unit[] Defender)
        {
            if (rand == null)
            {
                rand = new Random();
            }

            BattleResult r = new BattleResult();

            Attacker = Attacker.Select(x => x).OrderBy(x => rand.Next()).ToArray();
            Defender = Defender.Select(x => x).OrderBy(x => rand.Next()).ToArray();

            for (int i = 0; i < Attacker.Length; i++)
            {
                if (Defender.Length > i)
                {
                    if (RPSAttack(Attacker[i], Defender[i]))
                    {
                        r.AttackHits++;
                    }
                    else
                    {
                        r.DefendHits++;
                    }
                }
                else
                {
                    break;
                }
            }
            return(r);
        }
Ejemplo n.º 3
0
Archivo: Unit.cs Proyecto: vbnet3d/AAA
        public static BattleResult FullBattle(Unit[] attacker, Unit[] defender, Func <Unit[], bool, int> calculation, bool border)
        {
            var b = new BattleResult();

            while (attacker.Length > 0 && defender.Length > 0 && UnitsThatCanFight(attacker, defender) && b.Rounds < 20)
            {
                // Battleships and Destroyers only give supporting bombardment on the first round.
                if (b.Rounds >= 1)
                {
                    if (attacker.Any(x => x.Name == "Battleship" || x.Name == "Destroyer") && attacker.Any(x => x.Name == "Infantry" || x.Name == "Tank"))
                    {
                        RemoveUnitType(attacker, "Battleship");
                        RemoveUnitType(attacker, "Destroyer");
                    }
                }

                int sub_attack;
                int air_attack;
                int naval_attack;
                int land_attack;

                int sub_defend;
                int air_defend;
                int naval_defend;
                int land_defend;

                sub_attack = calculation(attacker.Where(x => x.Name == "Submarine").ToArray(), true);
                sub_defend = calculation(defender.Where(x => x.Name == "Submarine").ToArray(), border);

                b.AttackHits += sub_attack;
                b.DefendHits += sub_defend;

                if (!defender.Any(x => x.Name == "Destroyer"))
                {
                    defender   = RemoveUnits(defender, sub_attack, true, false, true, false);
                    sub_attack = 0;
                }

                if (!attacker.Any(x => x.Name == "Destroyer"))
                {
                    attacker   = RemoveUnits(attacker, sub_defend, true, false, true, false);
                    sub_attack = 0;
                }

                air_attack   = calculation(attacker.Where(x => x.Name == "Bomber" || x.Name == "Fighter").ToArray(), true);
                naval_attack = calculation(attacker.Where(x => x.Name == "Destroyer" || x.Name == "Battleship" || x.Name == "Carrier").ToArray(), true);
                land_attack  = calculation(attacker.Where(x => x.Name == "Infantry" || x.Name == "Tank").ToArray(), true);

                b.AttackHits += air_attack;
                b.AttackHits += naval_attack;
                b.AttackHits += land_attack;

                air_defend   = calculation(defender.Where(x => Type.Air(x.Name)).ToArray(), border);
                naval_defend = calculation(defender.Where(x => Type.Naval(x.Name)).ToArray(), border);
                land_defend  = calculation(defender.Where(x => Type.Land(x.Name)).ToArray(), border);

                b.DefendHits += air_defend;
                b.DefendHits += naval_defend;
                b.DefendHits += land_defend;

                defender = RemoveUnits(defender, sub_attack, true, false, false, false);
                defender = RemoveUnits(defender, air_attack, false, true, false, false);
                defender = RemoveUnits(defender, naval_attack, false, false, false, false);
                defender = RemoveUnits(defender, land_attack, false, false, false, true);

                attacker = RemoveUnits(attacker, sub_defend, true, false, false, false);
                attacker = RemoveUnits(attacker, air_defend, false, true, false, false);
                attacker = RemoveUnits(attacker, naval_defend, false, false, false, false);
                attacker = RemoveUnits(attacker, land_defend, false, false, false, true);

                b.Rounds++;
            }

            return(b);
        }