示例#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));
        }
    }
示例#2
0
    public List <GameAction> FindSolution(PlayFieldData activePlayField, Stack <CardData> deck, List <CardData> hand)
    {
        solution = null;

        if (activePlayField.AreAnyCoordinatesAreIncompleteable())
        {
            Debug.Log("The current playing field already has incompleteable cards.");
            return(null);
        }

        SolutionTimeStopwatch = System.Diagnostics.Stopwatch.StartNew();

        StringBuilder deckString = new StringBuilder();

        Debug.Log("The deck is:");

        foreach (CardData cards in deck.ToList())
        {
            deckString.Append(cards.FaceValue);
            deckString.Append(", ");
        }

        Debug.Log(deckString.ToString().TrimEnd(' ').TrimEnd(','));

        SolutionIteration(activePlayField, deck, hand, new List <GameAction>());

        if (solution == null)
        {
            Debug.Log("No solutions found.");
        }
        else
        {
            Debug.Log($"Solution found in {solution.Count} moves");

            foreach (GameAction actionsTaken in solution)
            {
                Debug.Log(actionsTaken.GetActionText());
            }
        }
        SolutionTimeStopwatch.Stop();
        return(solution);
    }