示例#1
0
        /*
         * Return 0 if draw
         * Return less then 0 if this hand losses to opposing hand
         * return greater then 0 if this hand beats opposing hand
         **/
        public int Compare(PokerHand opposingHand)
        {
            int comparison = this.score - opposingHand.getScore();

            if(comparison == 0) {
                List<int> otherHandRelaventComparisons = opposingHand.getReleaventComparisons();
                for (int i = relaventComparisons.Count - 1; i < relaventComparisons.Count; i--) {
                    comparison = relaventComparisons[i] - otherHandRelaventComparisons[i];
                    if(comparison != 0) {
                        return comparison;
                    }
                }

                return 0;
            }

            return comparison;
        }
示例#2
0
        static void Main(string[] args)
        {
            int count = 0;
            List<String> pokerMatches = new List<string>();

            try {
                FileStream file = new FileStream("Poker.txt", FileMode.Open);
                StreamReader stream = new StreamReader(file);

                while(!stream.EndOfStream) {
                    pokerMatches.Add(stream.ReadLine());
                }

                stream.Close();
                file.Close();
            }
            catch(Exception e) {
                Console.WriteLine(e);
            }

            for (int i = 0; i < pokerMatches.Count; i++) {
                String[] pokerHands = pokerMatches[i].Split(' ');
                String[] playerOneHand = new String[5];
                String[] playerTwoHand = new String[5];
                for (int j = 0; j < 5; j++) {
                    playerOneHand[j] = pokerHands[j];
                }

                for (int j = 5; j < pokerHands.Length; j++) {
                    playerTwoHand[j - 5] = pokerHands[j];
                }
                PokerHand playerOne = new PokerHand(playerOneHand);
                PokerHand playerTwo = new PokerHand(playerTwoHand);

                if(0 < playerOne.Compare(playerTwo)) {
                    count++;
                }
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }