Exemple #1
0
        void func(Army A, Army B)
        {
            int min;

            if (A.Count() == B.Count())
            {
                for (int j = 0; j < B.Count(); j++)
                {
                    if (B.SmbAttackedOneSoldier(A.OneSoldierMakeAttack(j), j))
                    {
                        A.SmbAttackedOneSoldier(B.OneSoldierMakeAttack(j), j);
                    }
                }
            }

            else
            {
                if (A.Count() < B.Count())
                {
                    min = A.Count();
                }
                else
                {
                    min = B.Count();
                }
                int i;
                for (i = 0; i < min; i++)
                {
                    if (B.SmbAttackedOneSoldier(A.OneSoldierMakeAttack(i), i))
                    {
                        A.SmbAttackedOneSoldier(B.OneSoldierMakeAttack(i), i);
                    }
                }
                if (A.Count() > min)
                {
                    if (B.IsHeAlive(i - 1))
                    {
                        if (B.SmbAttackedOneSoldier(A.OneSoldierMakeAttack(i), i - 1))
                        {
                            A.SmbAttackedOneSoldier(B.OneSoldierMakeAttack(i - 1), i);
                        }
                    }
                }
            }
            B.CheckDead();
            A.CheckDead();


            for (int i = 0; i < A.Count(); i++)
            {
                if (A.SADistance(i) > 0)
                {
                    List <IUnit> enemies = new List <IUnit>();
                    List <IUnit> friends = A.NewList(i - A.SADistance(i), i + A.SADistance(i));
                    int          k       = i - A.SADistance(i) + 1;
                    int          j       = i + A.SADistance(i) - 1;
                    enemies = B.NewList(k, j);
                    if (A.DoSA(i, friends, enemies))
                    {
                        i++;
                    }
                }
            }
            B.CheckDead();
            for (int i = 0; i < B.Count(); i++)
            {
                if (B.SADistance(i) > 0)
                {
                    List <IUnit> enemies = new List <IUnit>();
                    List <IUnit> friends = B.NewList(i - B.SADistance(i), i + B.SADistance(i));
                    int          k       = i - B.SADistance(i) + 1;
                    int          j       = i + B.SADistance(i) - 1;
                    enemies = A.NewList(k, j);
                    if (B.DoSA(i, friends, enemies))
                    {
                        i++;
                    }
                }
            }
            A.CheckDead();
        }