public static void Solve() { int cntP1 = 0; int cntP2 = 0; int handNum = 0; string[] deals = data.Split('\\'); foreach (string deal in deals) { HandOfCards hand1 = new HandOfCards(deal.Substring(0, 14)); HandOfCards hand2 = new HandOfCards(deal.Substring(15, 14)); //Console.Write(hand1.WinsAgainst(hand2) ? "P1" : "P2"); Console.WriteLine(); Console.Write("{0,3} ", handNum++); if (hand1.WinsAgainst(hand2)) { cntP1++; Console.WriteLine("P1"); } else { Console.WriteLine("P2"); cntP2++; } Console.WriteLine("\t{0}", hand1); Console.WriteLine("\t{0}", hand2); } Console.WriteLine("P1 = {0,4} P2 = {1,4}", cntP1, cntP2); }
public bool WinsAgainst(HandOfCards otherHand) { bool wins = false; if (_handResult > otherHand._handResult) wins = true; else if (_handResult < otherHand._handResult) wins = false; else { //normal hand check from high to low since the cards are sorted! for (int i = 0; i < numHighCards; i++) { if (_highCards[i] > otherHand._highCards[i]) { wins = true; break; } else if (_highCards[i] < otherHand._highCards[i]) { wins = false; break; } //else they're equal so check next card } } //{ // //tie breaker check the values of the cards // if ( HasFullHouse || HasFourOfaKind) // { // if (_highCards[0] > otherHand._highCards[0]) // { // wins = true; // } // else if (_highCards[0] < otherHand._highCards[0]) // { // wins = false; // } // else if (_highCards[1] > otherHand._highCards[1]) // { // wins = true; // } // else if (_highCards[1] < otherHand._highCards[1]) // { // wins = false; // } // else // { // throw new Exception("Cannot have a tie!!"); // } // } // else if ( HasTwoPair ) // { // if (_highCards[0] > otherHand._highCards[0]) // { // wins = true; // } // else if (_highCards[0] < otherHand._highCards[0]) // { // wins = false; // } // else if (_highCards[1] > otherHand._highCards[1]) // { // wins = true; // } // else if (_highCards[1] < otherHand._highCards[1]) // { // wins = false; // } // else if (_highCards[2] > otherHand._highCards[2]) // { // wins = true; // } // else if (_highCards[2] < otherHand._highCards[2]) // { // wins = false; // } // else // { // throw new Exception("Cannot have a tie!!"); // } // } // else // { // //normal hand check from high to low since the cards are sorted! // for (int i = 0; i < 5; i++) // { // if (_cards[i].Value > otherHand._cards[i].Value) // { // wins = true; // break; // } // else if (_cards[i].Value < otherHand._cards[i].Value) // { // wins = false; // break; // } // //else they're equal so check next card // } // } //} return wins; }