Ejemplo n.º 1
0
        /// <summary>
        /// Deep copies this instance of a BlockDescription
        /// </summary>
        /// <returns>
        /// The copy.
        /// </returns>
        public BlockDescription DeepCopy()
        {
            BlockDescription copy = new BlockDescription();

            copy._blockMap = new SortedList <CreatureCard, AttackerToBlockersTuple>(_blockMap.Count, comp);
            foreach (var cc in _blockMap.Keys)
            {
                copy._blockMap.Add(cc, new AttackerToBlockersTuple(cc, _blockMap[cc].Blockers));
            }
            return(copy);
        }
Ejemplo n.º 2
0
        public static IEnumerable <BlockDescription> GetPossibleBlocks(IList <CreatureCard> attackers, IList <CreatureCard> possibleBlockers)
        {
            var allBlocksList = new List <BlockDescription>();
            var blockersToUse = possibleBlockers.PowerSet();


            allBlocksList.Add(new BlockDescription(attackers));
            //GetPossibleBlocksAux(attackers,possibleBlockers,possibleBlockers.Count - 1, emptyBlocks, allBlocksList);
            foreach (var blkSet in blockersToUse)
            {
                if (blkSet.Count == 0)
                {
                    continue;
                }

                BlockDescription emptyBlocks = new BlockDescription(attackers);
                GetPossibleBlocksAux(attackers, blkSet, blkSet.Count - 1, emptyBlocks, allBlocksList);
            }

            return(allBlocksList);
        }
Ejemplo n.º 3
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);
            }
        }