Exemplo n.º 1
0
        public virtual bool RemoveStartingPeg(Dictionary <char, bool> pegs)
        {
            startingPeg = nextStartingPeg < GameInterface.PegChars.Length ? GameInterface.PegChars[nextStartingPeg] : (char?)null;

            if (startingPeg.HasValue)
            {
                history.TryAdd(startingPeg.Value, new List <History.GameRecord>());
                wins.TryAdd(startingPeg.Value, new List <History.GameRecord>());

                currentPath = new History.JumpList();

                if (history.ContainsKey(startingPeg.Value))
                {
                    var paths = history[startingPeg.Value];
                    lastPath = paths.Count > 0 ? paths[paths.Count - 1].JumpList : (History.JumpList)null;
                }

                GameInterface.RemovePeg(pegs, startingPeg.Value);

                return(true);
            }

            currentPath = (History.JumpList)null;
            lastPath    = (History.JumpList)null;

            return(false);
        }
Exemplo n.º 2
0
        public virtual bool RemoveStartingPeg(Dictionary <char, bool> pegs)
        {
            Func <char, bool> HasPeg = (char selectedPeg) => Array.IndexOf(GameInterface.PegChars, selectedPeg) >= 0;

            Console.Write("Choose the peg to remove: ");

            var peg = ReadPeg(HasPeg);

            Console.WriteLine(peg);

            if (peg.HasValue)
            {
                GameInterface.RemovePeg(pegs, peg.Value);
            }

            return(peg.HasValue);
        }
Exemplo n.º 3
0
        static void ShowStats()
        {
            var model = new InteractiveWithHintsModel(new string[0]);

            Console.Clear();
            Console.WriteLine("Calculating game stats for each starting peg.\n");

            var totalHints = new Hints();

            foreach (var startingPeg in GameInterface.PegChars)
            {
                Console.Write($"Peg {startingPeg}: ");

                var pegs = GameInterface.InitializePegs();
                GameInterface.RemovePeg(pegs, startingPeg);

                var finished = model.CalculateGameStats(pegs, false);

                if (finished)
                {
                    var hints = model.GetHints(pegs);
                    Console.WriteLine($"Possibilities: {hints.Possibilities.ToString("N0").PadLeft(9)} - Best/Worst Score: {hints.BestScore.ToString("N0").PadLeft(2)}/{hints.WorstScore.ToString("N0").PadRight(2)} - Wins: {hints.Wins.ToString("N0").PadLeft(7)} - Win Rate: {hints.WinRate.ToString("P2").PadLeft(7)}");

                    totalHints.Possibilities += hints.Possibilities;
                    totalHints.Wins          += hints.Wins;
                    totalHints.BestScore      = Math.Min(totalHints.BestScore, hints.BestScore);
                    totalHints.WorstScore     = Math.Max(totalHints.WorstScore, hints.WorstScore);
                }
                else
                {
                    Console.WriteLine("Aborted");

                    if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine($"Total: Possibilities: {totalHints.Possibilities.ToString("N0").PadLeft(9)} - Best/Worst Score: {totalHints.BestScore.ToString("N0").PadLeft(2)}/{totalHints.WorstScore.ToString("N0").PadRight(2)} - Wins: {totalHints.Wins.ToString("N0").PadLeft(7)} - Win Rate: {totalHints.WinRate.ToString("P2").PadLeft(7)}");
        }