public ActionResult HoldemResult(SimulationRequestModel request)
        {
            var simulation = new Simulation();
            var rawOutput = new SimulationOutput();

            var hands = new List<int>(request.SetHands);
            for (int i = 0; i < hands.Count; i += 2 )
            {
                simulation.AddHand(hands.GetRange(i, 2));
            }
            simulation.AddRandomHands(request.RandomHands);
            if (request.SetBoard != null)
            {
                simulation.AddCardsToBoard(new List<int>(request.SetBoard));
            }
            simulation.Run(request.HandsToSimulate, request.RandomChange);

            rawOutput.PrintResults(simulation);
            rawOutput.PrintHands(simulation.SimulatedHands);
            var response = new SimulationResultModel
            {
                SetHands = request.SetHands,
                PlayerWinCounts = simulation.PlayerWinCounts,
                RankWinCounts = simulation.RankWinCounts,
                SimulatedHands = (IEnumerable<SimulatedHand>)simulation.SimulatedHands
            };
            //rawOutput.WriteLinesToFile(Server.MapPath("~") + @"/SimulationResults.txt");
            //return new FilePathResult("~/SimulationResults.txt", "text/plain");
            return View(response);
        }
Esempio n. 2
0
        public void GetUserInput()
        {
            string inString;
            int randomHands;
            var cards = new List<int>();

            while (true)
            {
                simulation = new Simulation();
                simOutput = new SimulationOutput();
                randomHands = 0;

                Console.WriteLine("Enter up to {0} specific hands to be dealt, separating the cards by a space (Ex. \"AS KD\"). Press Enter without typing anything when finished.\n", Simulation.MAX_HANDS);

                while (simulation.DealtHands.Count / 2 <= Simulation.MAX_HANDS)
                {
                    cards.Clear();
                    Console.Write("Hand {0}: ", (simulation.DealtHands.Count / 2 + 1));
                    inString = Console.ReadLine();
                    if (inString == string.Empty)
                        break;
                    if (inString.Trim().Length != 5 || !inString.Contains(" "))
                    {
                        Console.WriteLine("Invalid hand");
                        continue;
                    }
                    string[] handString = inString.Split(' ');

                    if (handString[0] == handString[1])
                    {
                        Console.WriteLine("Invalid Hand");
                        continue;
                    }

                    try
                    {
                        cards.Add(Deck.CardFromString(handString[0]));
                        cards.Add(Deck.CardFromString(handString[1]));
                        simulation.AddHand(cards);
                        PrintHand(simulation.DealtHands.Count / 2, simulation.DealtHands.GetRange(simulation.DealtHands.Count - 2, 2));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                int handsDealt = simulation.DealtHands.Count / 2;
                if (handsDealt < Simulation.MAX_HANDS)
                {
                    while (true)
                    {
                        Console.Write("Additional random hands: ");
                        inString = Console.ReadLine();
                        if (int.TryParse(inString, out randomHands))
                        {
                            if (randomHands + handsDealt == 0)
                            {
                                Console.WriteLine("There must be at least one hand, try again.");
                                continue;
                            }
                            if (randomHands + handsDealt <= Simulation.MAX_HANDS)
                            {
                                simulation.AddRandomHands(randomHands);
                                for (int j = handsDealt * 2; j < simulation.DealtHands.Count; j += 2)
                                {
                                    PrintHand(j / 2 + 1, simulation.DealtHands.GetRange(j, 2));
                                }
                            }
                            else
                            {
                                Console.WriteLine("Hand limit of {0} exceeded, try again.", Simulation.MAX_HANDS);
                                continue;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Please enter a valid number");
                            continue;
                        }
                        break;
                    }
                }

                bool randomChange = false;
                if (randomHands > 0)
                {
                    Console.WriteLine("Do you want different random hands dealt each time?");
                    Console.Write("(Choose no for the same {0} hands each time)", randomHands);

                    do
                    {
                        Console.WriteLine();
                        Console.Write("Y/N: ");
                        inString = Console.ReadLine().Trim().ToUpper();
                    } while (inString != "Y" && inString != "N");
                    if (inString == "Y")
                        randomChange = true;
                }

                while (true)
                {
                    Console.Write("Enter up to 4 specific cards to be dealt to the board each hand: ");
                    inString = Console.ReadLine();
                    if (inString == string.Empty)
                    {
                        break;
                    }
                    var boardStrings = new List<string>(inString.Split(' '));
                    if (boardStrings.Distinct().Count() != boardStrings.Count)
                    {
                        Console.WriteLine("All cards must be distinct");
                        continue;
                    }
                    try
                    {
                        cards.Clear();
                        foreach (string cardString in boardStrings)
                        {
                            cards.Add(Deck.CardFromString(cardString));
                        }
                        simulation.AddCardsToBoard(cards);
                        Console.Write("Set board cards: ");
                        foreach (int card in cards)
                        {
                            Console.Write(Deck.CardToString(card) + " ");
                        }
                        Console.WriteLine();
                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                var stopWatch = new Stopwatch();
                while (true)
                {
                    int numHands;
                    Console.Write("Number of hands to simulate: ");
                    inString = Console.ReadLine();
                    if (int.TryParse(inString, out numHands))
                    {
                        stopWatch.Restart();
                        simulation.Run(numHands, randomChange);
                        break;
                    }
                    else
                        Console.WriteLine("Please enter a valid number");
                }
                PrintResults();

                simOutput.PrintResults(simulation);
                simOutput.PrintHands(simulation.SimulatedHands);

                stopWatch.Stop();
                Console.WriteLine("({0}ms)", stopWatch.ElapsedMilliseconds);

                string filePath = @"SimulationResults.txt";
                simOutput.WriteLinesToFile(filePath);
                Process.Start(filePath);

                do
                {
                    Console.Write("Would you like to run another simulation? (Y/N): ");
                    inString = Console.ReadLine().Trim().ToUpper();
                } while (inString != "Y" && inString != "N");
                if (inString == "N")
                {
                    break;
                }

                Console.WriteLine("");
            }
        }