Exemplo n.º 1
0
        public static Enums.Winner Compare(List <Card> blackCards, List <Card> whiteCards)
        {
            Enums.Winner _winner = Enums.Winner.Tie;

            Enums.Hand _blackHand = HandRecognizer.Recognize(blackCards);
            Enums.Hand _whiteHand = HandRecognizer.Recognize(whiteCards);

            if (_blackHand > _whiteHand)
            {
                _winner = Enums.Winner.Black;
            }
            else if (_blackHand < _whiteHand)
            {
                _winner = Enums.Winner.White;
            }
            else             // Need to break the tie
            {
                switch (_blackHand)
                {
                case Enums.Hand.HighCard:
                    _winner = TieSettler.HighCard(blackCards, whiteCards);
                    break;

                case Enums.Hand.Pair:
                    _winner = TieSettler.Pair(blackCards, whiteCards);
                    break;

                case Enums.Hand.TwoPair:
                    _winner = TieSettler.TwoPair(blackCards, whiteCards);
                    break;

                case Enums.Hand.ThreeOfAKind:
                    _winner = TieSettler.ThreeOfAKind(blackCards, whiteCards);
                    break;

                case Enums.Hand.Straight:
                    _winner = TieSettler.Straight(blackCards, whiteCards);
                    break;

                case Enums.Hand.Flush:
                    _winner = TieSettler.Flush(blackCards, whiteCards);
                    break;

                case Enums.Hand.FullHouse:
                    _winner = TieSettler.FullHouse(blackCards, whiteCards);
                    break;

                case Enums.Hand.FourOfAKind:
                    _winner = TieSettler.FourOfAKind(blackCards, whiteCards);
                    break;

                case Enums.Hand.StraightFlush:
                    _winner = TieSettler.StraightFlush(blackCards, whiteCards);
                    break;
                }
            }

            return(_winner);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <Stopwatch> _runTimers = new List <Stopwatch>();

            for (int _runCount = 0; _runCount < TimesToRun; _runCount++)
            {
                // Read File
                string[] _lines = File.ReadAllLines(FilePath);


                int _blackCount = 0;
                int _whiteCount = 0;
                int _tieCount   = 0;

                // Initialize stopwatch
                Stopwatch _stopwatch = new Stopwatch();
                _stopwatch.Start();

                Console.WriteLine("Run #" + (_runCount + 1));

                foreach (string _line in _lines)
                {
                    // Parse the players' hands
                    List <Card> _blackCards = HandParser.Parse(_line.Substring(0, 14));                                 // First half of line
                    List <Card> _whiteCards = HandParser.Parse(_line.Substring(15));                                    // Second half of line

                    // Compare hands
                    Enums.Winner _winner = HandComparator.Compare(_blackCards, _whiteCards);

                    // Announce Winner
                    switch (_winner)
                    {
                    case Enums.Winner.Black:
                        //Console.WriteLine("Black wins.");
                        _blackCount++;
                        break;

                    case Enums.Winner.White:
                        //Console.WriteLine("White wins.");
                        _whiteCount++;
                        break;

                    case Enums.Winner.Tie:
                        //Console.WriteLine("Tie.");
                        _tieCount++;
                        break;
                    }
                }

                _stopwatch.Stop();
                _runTimers.Add(_stopwatch);
                Console.WriteLine("Black wins: " + _blackCount + ", White wins: " + _whiteCount + ", Ties: " + _tieCount);
                Console.WriteLine("Run " + (_runCount + 1) + " elapsed time: " + FormatTimeSpan(_stopwatch.Elapsed));
            }

            // Average run time
            Console.WriteLine();
            TimeSpan _averageRunTime = TimeSpan.FromMilliseconds(_runTimers.Average(x => x.Elapsed.TotalMilliseconds));

            Console.WriteLine("Average run time: " + FormatTimeSpan(_averageRunTime));
            Console.WriteLine();

            // Bye
            System.Console.ReadKey();
        }