Example #1
0
    void TakeAction(GameAction toTake, PlayFieldData startingPlayField, Stack <CardData> startingDeck, List <CardData> startingHand,
                    out PlayFieldData resultPlayField, out Stack <CardData> resultDeck, out List <CardData> resultHand, out bool resultsInIncompleteness)
    {
        resultPlayField = startingPlayField.CloneData();

        // Frustratingly, creating a new stack creates that stack upsidedown! Reverse it, again
        resultDeck = new Stack <CardData>(new Stack <CardData>(startingDeck));

        resultHand = new List <CardData>(startingHand);

        resultHand.Remove(toTake.CardPlayed.Value);

        if (resultDeck.Count > 0)
        {
            resultHand.Add(resultDeck.Pop());
        }

        resultPlayField.SetCard(toTake.CardPlayed.Value, toTake.CoordinatePlayedOn.Value);

        if (resultPlayField.AreAnyCoordinatesAreIncompleteable())
        {
            resultsInIncompleteness = true;
        }
        else
        {
            resultsInIncompleteness = false;
        }

        if (resultDeck.Count > 0 && resultHand.Count > 0 && !resultPlayField.AreAnyMovesPossible(resultHand))
        {
            resultPlayField = new PlayFieldData();
            resultPlayField.SetCard(resultDeck.Pop(), new Coordinate(0, 0));
        }
    }
    public void GetNewHypotheticalPlacementEffects(PlayingCard forCard, Coordinate onCoordinate,
                                                   out HashSet <PlayingCard> newHypotheticalIncompleteableCards, out HashSet <PlayingCard> newHypotheticalHappyCards)
    {
        newHypotheticalIncompleteableCards = new HashSet <PlayingCard>();
        newHypotheticalHappyCards          = new HashSet <PlayingCard>();

        PlayFieldData hypotheticalPlayField = CurrentPlayField.CloneData();

        hypotheticalPlayField.SetCard(forCard.RepresentingCard, onCoordinate);

        IEnumerable <Coordinate> newHypotheticalIncompleteableCoordinates = hypotheticalPlayField.GetIncompleteableCoordinates().Except(CurrentPlayField.GetIncompleteableCoordinates());
        IEnumerable <Coordinate> newHypotheticalHappyCoordinates          = hypotheticalPlayField.GetHappyCoordinates().Except(CurrentPlayField.GetHappyCoordinates());

        newHypotheticalIncompleteableCards = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalIncompleteableCoordinates.Contains(card.OnCoordinate)));
        newHypotheticalHappyCards          = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalHappyCoordinates.Contains(card.OnCoordinate)));

        if (newHypotheticalIncompleteableCoordinates.Contains(onCoordinate))
        {
            newHypotheticalIncompleteableCards.Add(forCard);
        }

        if (newHypotheticalHappyCoordinates.Contains(onCoordinate))
        {
            newHypotheticalHappyCards.Add(forCard);
        }
    }