示例#1
0
        public override void ChooseBlockers(IDictionary <CreatureCard, IList <CreatureCard> > attackersToBlockersDictionary, IList <CreatureCard> possibleBlockers)
        {
            // for each attacker, randomly determine if blocking using pBlock, then determine how many blockers
            foreach (var attacker in attackersToBlockersDictionary.Keys)
            {
                double blockSample = rng.NextDouble();
                if (blockSample <= pBlock)
                {
                    // +1 because upper bound is exclusive
                    int numBlockers = rng.Next(possibleBlockers.Count + 1);
                    for (int i = 0; i < numBlockers; i++)
                    {
                        int          nextIndex = rng.Next(possibleBlockers.Count);
                        CreatureCard blocker   = possibleBlockers[nextIndex];
                        bool         result    = possibleBlockers.Remove(blocker);

                        if (!result)
                        {
                            throw new Exception("WTF MAN");
                        }

                        attackersToBlockersDictionary[attacker].Add(blocker);
                    }
                }
            }
        }
 public AttackerToBlockersTuple this[CreatureCard key] {
     get {
         return(_blockMap[key]);
     }
     set {
         _blockMap[key] = value;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="mlaSharp.GameEngine.AttackerToBlockersTuple"/> class.
 /// </summary>
 /// <param name='attacker'>
 /// Attacker.
 /// </param>
 /// <param name='blockersList'>
 /// Blockers list to clone.
 /// </param>
 public AttackerToBlockersTuple(CreatureCard attacker, IList <CreatureCard> blockersList)
 {
     Attacker = attacker;
     if (blockersList == null)
     {
         Blockers = new List <CreatureCard>();
     }
     else
     {
         Blockers = new List <CreatureCard>(blockersList);
     }
 }
示例#4
0
        /// <summary>
        /// Recursive helper function to get the possible blocks and add them to blockDescriptions.
        /// </summary>
        /// <param name='atkSet'>
        /// List of attackers to consider.
        /// </param>
        /// <param name='blkSet'>
        /// List of blockers to consider.
        /// </param>
        /// <param name='blkSetEndIndex'>
        /// The index of the last item in blkSet not yet assigned.
        /// </param>
        /// <param name='parent'>
        /// The parent <see cref="BlockDescription"/> for the current recursive call to consider.
        /// </param>
        /// <param name='blockDescriptions'>
        /// A list that will be filled with the <see cref="BlockDescription"/>s built
        /// </param>
        private static void GetPossibleBlocksAux(IList <CreatureCard> atkSet, IList <CreatureCard> blkSet, int blkSetEndIndex, BlockDescription parent, IList <BlockDescription> blockDescriptions)
        {
            // base case - no more blockers to assign, so add this block description to the list
            if (blkSetEndIndex < 0)
            {
                blockDescriptions.Add(parent);
                return;
            }

            // contraction - remove last blocker and assign it to all possible attackers
            CreatureCard lastBlocker = blkSet[blkSetEndIndex--];

            foreach (var attacker in atkSet)
            {
                var newBlockingChoice = parent.DeepCopy();
                newBlockingChoice[attacker].Blockers.Add(lastBlocker);
                GetPossibleBlocksAux(atkSet, blkSet, blkSetEndIndex, newBlockingChoice, blockDescriptions);
            }
        }
 public bool Remove(CreatureCard attacker)
 {
     return(_blockMap.Remove(attacker));
 }
 public bool Contains(CreatureCard attacker)
 {
     return(_blockMap.ContainsKey(attacker));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="mlaSharp.GameEngine.AttackerToBlockersTuple"/> class.
 /// </summary>
 /// <param name='attacker'>
 /// Attacker.
 /// </param>
 public AttackerToBlockersTuple(CreatureCard attacker)
     : this(attacker, null)
 {
 }