Ejemplo n.º 1
0
        public BrigadeFormationWithFamiliars(BrigadeFormationWithFamiliars other)
        {
            this.PhlebotomistRepository = other.PhlebotomistRepository;

            this.IncludeReserve       = other.IncludeReserve;
            this.FamiliarsInPositions = new Dictionary <BrigadeFormationVerticalPositionType, List <FamiliarWinPercent> >();
            foreach (var key in other.FamiliarsInPositions.Keys)
            {
                this.FamiliarsInPositions[key] = new List <FamiliarWinPercent>(other.FamiliarsInPositions[key]);
            }

            this.Formation = other.Formation;
        }
Ejemplo n.º 2
0
        static IEnumerable <BrigadeFormationWithFamiliars> GetBrigadeFormationPermutations(
            PhlebotomistRepository phlebotomistRepository, List <FamiliarWinPercent> familiarWinPercents,
            BrigadeFormation formation, bool includeReserve)
        {
            if (formation == null)
            {
                throw new ArgumentNullException("formation", "The BrigadeFormation argument can not be null!");
            }

            var currentBrigadeInstace = new BrigadeFormationWithFamiliars(phlebotomistRepository,
                                                                          includeReserve);

            currentBrigadeInstace.Formation = formation;
            foreach (var brigadeFormation in GetBrigadeFormationPermutations(phlebotomistRepository,
                                                                             familiarWinPercents, currentBrigadeInstace, includeReserve))
            {
                yield return(brigadeFormation);
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <BrigadeFormationWithFamiliars> GetBrigadeFormationPermutations(
            PhlebotomistRepository phlebotomistRepository, List <FamiliarWinPercent> familiarWinPercents,
            BrigadeFormationWithFamiliars currentFormation, bool includeReserve)
        {
            // Either no more familiars left to place or we've placed everyone already.
            if (familiarWinPercents.Count == 0 ||
                currentFormation.NumFamiliarsInPosition == (currentFormation.Formation.NumPositions *
                                                            (currentFormation.IncludeReserve ? 2 : 1)))
            {
                yield return(currentFormation);
            }
            // First place all familiars in the non-reserve positions (that is, make sure at least
            // currentFormation.Formation.NumPositions familiars have been placed).
            else if (currentFormation.NumFamiliarsInPosition < currentFormation.Formation.NumPositions)
            {
                bool forReserve             = false;
                var  positionsWithOpenSlots = new List <BrigadeFormationVerticalPositionType>();
                foreach (var verticalPosition in phlebotomistRepository.Context.BrigadeFormationVerticalPositionTypes)
                {
                    if (currentFormation.HasOpenSlotsInPosition(verticalPosition, forReserve))
                    {
                        positionsWithOpenSlots.Add(verticalPosition);
                    }
                }

                var nextFamiliar = familiarWinPercents[0];
                foreach (var verticalPosition in positionsWithOpenSlots)
                {
                    BrigadeFormationWithFamiliars nextFormation = new BrigadeFormationWithFamiliars(currentFormation);
                    var remainingFamiliars = new List <FamiliarWinPercent>(familiarWinPercents);
                    remainingFamiliars.RemoveAt(0);

                    nextFormation.FamiliarsInPositions[verticalPosition].Add(nextFamiliar);
                    foreach (var permutation in GetBrigadeFormationPermutations(phlebotomistRepository, remainingFamiliars,
                                                                                nextFormation, includeReserve))
                    {
                        yield return(permutation);
                    }
                }
            }
            // Then place a reserve familiar if we are including reserves.
            else if (includeReserve)
            {
                bool placingReserveFamiliar = true;
                var  positionsWithOpenSlots = new List <BrigadeFormationVerticalPositionType>();
                foreach (var verticalPosition in phlebotomistRepository.Context.BrigadeFormationVerticalPositionTypes)
                {
                    if (currentFormation.HasOpenSlotsInPosition(verticalPosition, placingReserveFamiliar))
                    {
                        positionsWithOpenSlots.Add(verticalPosition);
                    }
                }

                var nextFamiliar = familiarWinPercents[0];
                foreach (var verticalPosition in positionsWithOpenSlots)
                {
                    BrigadeFormationWithFamiliars nextFormation = new BrigadeFormationWithFamiliars(currentFormation);
                    var remainingFamiliars = new List <FamiliarWinPercent>(familiarWinPercents);
                    remainingFamiliars.RemoveAt(0);

                    nextFormation.FamiliarsInPositions[verticalPosition].Add(nextFamiliar);
                    foreach (var permutation in GetBrigadeFormationPermutations(phlebotomistRepository, remainingFamiliars,
                                                                                nextFormation, includeReserve))
                    {
                        yield return(permutation);
                    }
                }
            }
        }