private ActionProcessingResults ProcessPickupsIteration(SystemWideValues systemWideValues, IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > allActiveBids,
                                                            ActionProcessingResults existingResults, Instant processingTime, IReadOnlyDictionary <Guid, MasterGameYear> masterGameYearDictionary)
    {
        IEnumerable <PickupBid> flatAllBids = allActiveBids.SelectMany(x => x.Value);

        var publisherStateSet = existingResults.PublisherStateSet;
        var processedBids     = new ProcessedBidSet();

        foreach (var leagueYear in allActiveBids)
        {
            if (!leagueYear.Value.Any())
            {
                continue;
            }

            var processedBidsForLeagueYear = ProcessPickupsForLeagueYear(leagueYear.Key, leagueYear.Value, publisherStateSet, systemWideValues, processingTime);
            processedBids = processedBids.AppendSet(processedBidsForLeagueYear);
        }

        ActionProcessingResults bidResults = GetBidProcessingResults(processedBids.SuccessBids, processedBids.FailedBids, publisherStateSet, processingTime, masterGameYearDictionary);
        var newResults    = existingResults.Combine(bidResults);
        var remainingBids = flatAllBids.Except(processedBids.ProcessedBids);

        if (remainingBids.Any())
        {
            IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > remainingBidDictionary = remainingBids.GroupToDictionary(x => x.LeagueYear);
            var subProcessingResults = ProcessPickupsIteration(systemWideValues, remainingBidDictionary, newResults, processingTime, masterGameYearDictionary);
            ActionProcessingResults combinedResults = newResults.Combine(subProcessingResults);
            return(combinedResults);
        }

        return(newResults);
    }
        private ProcessedBidSet ProcessPickupsForLeagueYear(LeagueYear leagueYear, IEnumerable <PickupBid> activeBidsForLeague,
                                                            IEnumerable <Publisher> currentPublisherStates, SystemWideValues systemWideValues, IEnumerable <SupportedYear> supportedYears)
        {
            List <PickupBid> noSpaceLeftBids       = new List <PickupBid>();
            List <PickupBid> insufficientFundsBids = new List <PickupBid>();
            List <KeyValuePair <PickupBid, string> > invalidGameBids = new List <KeyValuePair <PickupBid, string> >();

            foreach (var activeBid in activeBidsForLeague)
            {
                Publisher publisher = currentPublisherStates.Single(x => x.PublisherID == activeBid.Publisher.PublisherID);

                var gameRequest = new ClaimGameDomainRequest(publisher, activeBid.MasterGame.GameName, false, false, false, activeBid.MasterGame, null, null);
                var publishersForLeagueAndYear = currentPublisherStates.Where(x => x.LeagueYear.League.LeagueID == leagueYear.League.LeagueID && x.LeagueYear.Year == leagueYear.Year);
                var claimResult = _gameAcquisitionService.CanClaimGame(gameRequest, supportedYears, leagueYear, publishersForLeagueAndYear);

                if (!publisher.HasRemainingGameSpot(leagueYear.Options.StandardGames))
                {
                    noSpaceLeftBids.Add(activeBid);
                    continue;
                }

                if (!claimResult.Success)
                {
                    invalidGameBids.Add(new KeyValuePair <PickupBid, string>(activeBid, string.Join(" AND ", claimResult.Errors.Select(x => x.Error))));
                    continue;
                }

                if (activeBid.BidAmount > publisher.Budget)
                {
                    insufficientFundsBids.Add(activeBid);
                }
            }

            var validBids    = activeBidsForLeague.Except(noSpaceLeftBids).Except(insufficientFundsBids).Except(invalidGameBids.Select(x => x.Key));
            var winnableBids = GetWinnableBids(validBids, leagueYear.Options, systemWideValues);
            var winningBids  = GetWinningBids(winnableBids);

            var takenGames = winningBids.Select(x => x.MasterGame);
            var losingBids = activeBidsForLeague
                             .Except(winningBids)
                             .Except(noSpaceLeftBids)
                             .Except(insufficientFundsBids)
                             .Except(invalidGameBids.Select(x => x.Key))
                             .Where(x => takenGames.Contains(x.MasterGame))
                             .Select(x => new FailedPickupBid(x, "Publisher was outbid."));

            var invalidGameBidFailures       = invalidGameBids.Select(x => new FailedPickupBid(x.Key, "Game is no longer eligible: " + x.Value));
            var insufficientFundsBidFailures = insufficientFundsBids.Select(x => new FailedPickupBid(x, "Not enough budget."));
            var noSpaceLeftBidFailures       = noSpaceLeftBids.Select(x => new FailedPickupBid(x, "No roster spots available."));
            var failedBids = losingBids.Concat(insufficientFundsBidFailures).Concat(noSpaceLeftBidFailures).Concat(invalidGameBidFailures);

            var processedSet = new ProcessedBidSet(winningBids, failedBids);

            return(processedSet);
        }
        public BidProcessingResults ProcessPickupsIteration(SystemWideValues systemWideValues, IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > allActiveBids,
                                                            IEnumerable <Publisher> currentPublisherStates, IClock clock, IEnumerable <SupportedYear> supportedYears)
        {
            if (!allActiveBids.Any())
            {
                return(new BidProcessingResults(new List <PickupBid>(), new List <PickupBid>(), new List <LeagueAction>(), currentPublisherStates, new List <PublisherGame>()));
            }

            IEnumerable <PickupBid> flatAllBids = allActiveBids.SelectMany(x => x.Value);

            var processedBids = new ProcessedBidSet();

            foreach (var leagueYear in allActiveBids)
            {
                if (!leagueYear.Value.Any())
                {
                    continue;
                }

                var processedBidsForLeagueYear = ProcessPickupsForLeagueYear(leagueYear.Key, leagueYear.Value, currentPublisherStates, systemWideValues, supportedYears);
                processedBids = processedBids.AppendSet(processedBidsForLeagueYear);
            }

            BidProcessingResults bidProcessingResults = GetProcessingResults(processedBids.SuccessBids, processedBids.FailedBids, currentPublisherStates, clock);

            var remainingBids = flatAllBids.Except(processedBids.ProcessedBids);

            if (remainingBids.Any())
            {
                Dictionary <LeagueYear, IReadOnlyList <PickupBid> > remainingBidDictionary = remainingBids.GroupBy(x => x.LeagueYear).ToDictionary(x => x.Key, y => (IReadOnlyList <PickupBid>)y.ToList());
                var subProcessingResults             = ProcessPickupsIteration(systemWideValues, remainingBidDictionary, bidProcessingResults.UpdatedPublishers, clock, supportedYears);
                BidProcessingResults combinedResults = bidProcessingResults.Combine(subProcessingResults);
                return(combinedResults);
            }

            return(bidProcessingResults);
        }
Пример #4
0
 public ProcessedBidSet AppendSet(ProcessedBidSet appendSet)
 {
     return(new ProcessedBidSet(SuccessBids.Concat(appendSet.SuccessBids), FailedBids.Concat(appendSet.FailedBids)));
 }