public void RunTrials()
        {
            Console.WriteLine("Pretzel Solitaire Solver");
            string resultsHeader = "Suits: " + SuitCount.ToString();

            resultsHeader += ", Values: " + ValueCount.ToString();
            resultsHeader += ", Deal: " + Deal.ToString();
            resultsHeader += ", Approach: " + Approach.ToString();
            resultsHeader += ", Ouput: " + Output.ToString();
            Console.WriteLine(resultsHeader);

            string summaryHeader = "\nTrial \tIters \tSolved \tMvTot \tMvMean \tDuel2s \tDCrabs";

            if (Approach == ApproachType.FullTree)
            {
                summaryHeader += " \tNoFail \tDeadends_for_Solvable";
            }
            if (Output != OutputType.Verbose)
            {
                Console.WriteLine(summaryHeader);
            }

            CardDeck deck                             = new CardDeck(SuitCount, ValueCount);
            DateTime solveStartTime                   = DateTime.UtcNow;
            string   moveCounts                       = string.Empty;
            ushort   totalSolvedPretzels              = 0;
            ulong    totalMoves                       = 0;
            ushort   totalDuellingDeuces              = 0;
            ushort   totalDuckingCrabs                = 0;
            ushort   totalUnlosablePretzels           = 0;
            ulong    totalDeadendsForSolvablePretzels = 0;

            for (short t = 0; t < Trials; ++t)
            {
                ushort trialSolvedPretzels              = 0;
                ulong  trialMoves                       = 0;
                ushort trialDuellingDeuces              = 0;
                ushort trialDuckingCrabs                = 0;
                ushort trialUnlosablePretzels           = 0;
                ulong  trailDeadendsForSolvablePretzels = 0;
                for (short e = 0; e < Experiments; ++e)
                {
                    if (Output == OutputType.Verbose)
                    {
                        Console.WriteLine("\nTrial " + t.ToString() + " Experiment " + e.ToString());
                    }

                    deck.Shuffle(Deal);

                    PretzelPosition position = new PretzelPosition(deck);

                    if (Output == OutputType.Verbose)
                    {
                        Console.WriteLine(position.ToString());
                    }

                    SolveResults results = Solve(position, Approach, Output);

                    if (results.Solvable)
                    {
                        ++trialSolvedPretzels;
                        trialMoves += results.Moves;
                        if (Output == OutputType.SummaryWithMoveCounts)
                        {
                            moveCounts += results.Moves.ToString() + ", ";
                        }
                        trailDeadendsForSolvablePretzels += results.Deadends;
                        if (results.Deadends == 0)
                        {
                            ++trialUnlosablePretzels;
                        }
                    }
                    else
                    {
                        if (results.HasDuellingDeuces)
                        {
                            ++trialDuellingDeuces;
                            if (Output == OutputType.Verbose)
                            {
                                Console.WriteLine("Duelling Deuces Detected");
                            }
                        }
                        if (results.HasDuckingCrab)
                        {
                            ++trialDuckingCrabs;
                            if (Output == OutputType.Verbose)
                            {
                                Console.WriteLine("Ducking Crab Detected");
                            }
                        }
                    }
                }
                totalSolvedPretzels              += trialSolvedPretzels;
                totalMoves                       += trialMoves;
                totalDuellingDeuces              += trialDuellingDeuces;
                totalDuckingCrabs                += trialDuckingCrabs;
                totalUnlosablePretzels           += trialUnlosablePretzels;
                totalDeadendsForSolvablePretzels += trailDeadendsForSolvablePretzels;
                // output trial results
                if (Output == OutputType.Verbose)
                {
                    Console.WriteLine(summaryHeader);
                }
                string trialResults = t.ToString();
                trialResults += "\t" + Experiments.ToString();
                trialResults += "\t" + trialSolvedPretzels.ToString();
                trialResults += "\t" + trialMoves.ToString();
                trialResults += "\t" + ((double)trialMoves / (double)trialSolvedPretzels).ToString("F");
                trialResults += "\t" + trialDuellingDeuces.ToString();
                trialResults += "\t" + trialDuckingCrabs.ToString();
                if (Approach == ApproachType.FullTree)
                {
                    trialResults += "\t" + trialUnlosablePretzels.ToString();
                    trialResults += "\t" + trailDeadendsForSolvablePretzels.ToString();
                }
                Console.WriteLine(trialResults);
                if (Output == OutputType.SummaryWithMoveCounts)
                {
                    moveCounts += "\n\n";
                }
            }
            // output total results
            DateTime solveEndTime = DateTime.UtcNow;

            Console.WriteLine("");
            string totalResults = "TOTAL: ";

            totalResults += "\t" + (Trials * Experiments).ToString();
            totalResults += "\t" + totalSolvedPretzels.ToString();
            totalResults += "\t" + totalMoves.ToString();
            totalResults += "\t" + ((double)totalMoves / (double)totalSolvedPretzels).ToString("F");
            totalResults += "\t" + totalDuellingDeuces.ToString();
            totalResults += "\t" + totalDuckingCrabs.ToString();
            if (Approach == ApproachType.FullTree)
            {
                totalResults += "\t" + totalUnlosablePretzels.ToString();
                totalResults += "\t" + totalDeadendsForSolvablePretzels.ToString();
            }
            Console.WriteLine(totalResults);
            if (Output == OutputType.SummaryWithMoveCounts)
            {
                Console.WriteLine("\nMove Counts for All Solved Pretzels, Grouped by Trial");
                Console.WriteLine(moveCounts);
            }
            Console.WriteLine("");
            Console.WriteLine((solveEndTime - solveStartTime).ToString() + " Elapsed");
            Console.Write((char)7); // play bell
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="approachType"></param>
        /// <returns></returns>
        public Entity.ApproachTypeEntity GetApproachTypeEntity(ApproachType approachType)
        {
            var t = approachType.ToString();

            return(Query(x => x.ApproachMethod == approachType.ToString()).FirstOrDefault());
        }