Ejemplo n.º 1
0
        protected virtual CardColor PickAColor()
        {
            var colorsToChoose = new List <CardColor>();

            if (ColorRequest.HasValue)
            {
                // we have a pending color request; honor it
                var color = ColorRequest.Value;
                StrategyLogger.LogDebug("honoring color request {Color}", color);
                ColorRequest = null;
                return(color);
            }

            // -> add all four colors once to allow for some chaotic color switching
            colorsToChoose.Add(CardColor.Red);
            colorsToChoose.Add(CardColor.Green);
            colorsToChoose.Add(CardColor.Blue);
            colorsToChoose.Add(CardColor.Yellow);

            // -> add all the (non-wild) colors from our hand to increase the chances of a useful pick
            var handColors = CurrentHand.Select(c => c.Color).Where(c => c != CardColor.Wild).ToList();

            for (int i = 0; i < Config.ColorInHandPreference; ++i)
            {
                colorsToChoose.AddRange(handColors);
            }

            // -> choose at random
            return(colorsToChoose[Randomizer.Next(colorsToChoose.Count)]);
        }
Ejemplo n.º 2
0
        protected virtual void PlayACard()
        {
            var possibleCards = new List <Card>();

            var strategies = AssembleStrategies();
            var filters    = AssembleFilters();

            StrategyLogger.LogDebug("current hand: [{HandCards}]", CurrentHand.Select(c => c.Color + " " + c.Value).StringJoin(", "));

            if (Config.DrawAllTheTime && !DrewLast)
            {
                DrawACard();
                return;
            }

            // apply strategies
            foreach (var strategy in strategies)
            {
                var continuation = strategy(possibleCards);

                if (continuation == StrategyContinuation.SkipAllOtherStrategies)
                {
                    break;
                }

                // apply filters
                foreach (var filter in filters)
                {
                    filter(possibleCards);
                }

                if (continuation == StrategyContinuation.ContinueToNextStrategy)
                {
                    continue;
                }
                else if (continuation == StrategyContinuation.DontPlayCard)
                {
                    return;
                }
                else if (continuation == StrategyContinuation.SkipAllOtherStrategiesUnlessFilteredEmpty)
                {
                    if (possibleCards.Any())
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            // perform the final pick
            var maybeCard = PerformFinalPick(possibleCards);

            if (maybeCard.HasValue)
            {
                // final pick chose a card
                var card = maybeCard.Value;

                StrategyLogger.LogDebug("playing card: {CardColor} {CardValue}", card.Color, card.Value);

                if (card.Color == CardColor.Wild)
                {
                    // pick a color
                    var chosenColor = PickAColor();
                    StrategyLogger.LogDebug("chosen color: {Color}", chosenColor);

                    // play the card
                    PlayWildCard(card.Value, chosenColor);
                }
                else
                {
                    // play it
                    PlayColorCard(card);
                }
                ColorRequest       = null;
                DrewLast           = false;
                DrawsSinceLastPlay = 0;
                return;
            }

            if (DrewLast)
            {
                StrategyLogger.LogDebug("passing");
                PassAfterDrawing();
                ColorRequest = null;
            }
            else
            {
                if (Config.ManyDrawsCurseThreshold >= 0 && DrawsSinceLastPlay > Config.ManyDrawsCurseThreshold)
                {
                    StrategyLogger.LogDebug("cursing because of too many draws");
                    Curse();
                }
                StrategyLogger.LogDebug("drawing");
                DrawACard();
            }
        }