예제 #1
0
        public ReinforceAnimation Reinforce(Board b, Player p, int reinforcements)
        {
            ReinforceAnimation anim = new ReinforceAnimation(b);

            b.TryReinforce(p.Zones, reinforcements, anim);
            return(anim);
        }
예제 #2
0
        /// <summary>
        /// Try to reinforce zones in this list until full.  Returns number of remaining reinforcements that could not be placed.
        /// </summary>
        /// <returns>Number of remaining reinforcements that could not be placed</returns>
        /// <param name="zones">Zones.</param>
        /// <param name="numReinforcements">Number to try to place.</param>
        /// <param name="anim">Animation to update</param>
        public int TryReinforce(List <Zone> zones, int numReinforcements, ReinforceAnimation anim)
        {
            List <Zone> remaining = new List <Zone>(zones);

            while (numReinforcements > 0 && remaining.Count > 0)
            {
                var toReinforce = Random.Next(remaining.Count);
                var z           = remaining[toReinforce];
                if (z.Strength < z.MaxStrength)
                {
                    if (anim == null)
                    {
                        z.Strength++;
                    }
                    else
                    {
                        anim.AddUnit(z);
                    }
                    numReinforcements--;
                }
                else
                {
                    remaining.Remove(z);
                }
            }

            // The number that could not be placed
            return(numReinforcements);
        }
        public ReinforceAnimation Reinforce(Board b, Player p, int reinforcements)
        {
            ReinforceAnimation anim = new ReinforceAnimation(b);
            var area = b.GetLargestArea(p);

            b.TryReinforce(area, reinforcements, anim);
            return(anim);
        }
예제 #4
0
        public ReinforceAnimation Reinforce(Board b, Player p, int reinforcements)
        {
            ReinforceAnimation anim = new ReinforceAnimation(b);

            // First try reinforcing borders
            var area      = b.GetLargestArea(p);
            var borders   = (from z in area where z.BordersAnEnemy() select z).ToList();
            int remaining = b.TryReinforce(borders, reinforcements, anim);

            // If there's more, try largest area
            if (remaining > 0)
            {
                b.TryReinforce(area, remaining, anim);
            }
            return(anim);
        }