// Test mainframe /* public static void Main(string[] args) { uint card_id = 0; Card card = new Card("8; diamonds; what is this garbage?", card_id++); Card card2 = new Card("13; club; what IS this??", card_id++); Card card3 = new Card("what; WHAT; huh?", card_id++); card.display(); card2.display(); card3.display(); Console.Read(); } * */ public Card(Card other) { this.suite_p = other.suite_p; this.value_p = other.value_p; this.ID_p = other.ID_p; this.mark_p = other.mark_p; this.discarded_p = other.discarded_p; this.unavailable_p = other.unavailable_p; }
static private void display(Card_Suite suite, Card_Value value) { string val_str = value.ToString().ToLower(); val_str = val_str.ElementAt(0).ToString().ToUpper() + val_str.Substring(1); string sui_str = suite.ToString().ToLower(); sui_str = sui_str.ElementAt(0).ToString().ToUpper() + sui_str.Substring(1); // guard conditions if (value == Card_Value.JOKER) { Console.WriteLine("{0}", val_str); } else if (suite == Card_Suite.END || value == Card_Value.END) { Console.WriteLine("Invalid card passed"); } else { Console.WriteLine("{0} of {1}", val_str, sui_str); } }
public Card(Card_Info info, uint ID) { suite_p = info.suite; value_p = info.value; ID_p = ID; mark_p = info.mark; discarded_p = false; }
private static void display(Card_Suite suite, Card_Value value) { string val_str = value.ToString().ToLower(); val_str = val_str.ElementAt(0).ToString().ToUpper() + val_str.Substring(1); string sui_str = suite.ToString().ToLower(); sui_str = sui_str.ElementAt(0).ToString().ToUpper() + sui_str.Substring(1); // guard conditions if (value == Card_Value.JOKER) { Console.WriteLine("{0}", val_str); } else if (suite == Card_Suite.END || value == Card_Value.END) { Console.WriteLine("Invalid card passed"); } else { Console.WriteLine("{0} of {1}", val_str, sui_str); } }
public Card() { suite_p = Card_Suite.END; value_p = Card_Value.END; ID_p = 0; mark_p = ""; discarded_p = false; }
public Card(string card_info, uint ID) { Card_Info info = interpret(card_info); suite_p = info.suite; value_p = info.value; ID_p = ID; mark_p = info.mark; discarded_p = false; }
public CardDefinition(int index, int suite, int number) { Index = index; Suite = (Card_Suite)suite; Number = (Card_Number)number; }
public Hand_Values calculate_best_hand_value(out Card_Value straight_starting_value, out Card_Suite flush_suite) { // have to make sure that the best hand value is updated // need to make sure the best part of the hand (the pair, two pairs, etc.) are at the front // have to distinguish between hand values straight_starting_value = Card_Value.END; flush_suite = Card_Suite.END; // initialize hand value tracking array bool[] is_hand_value = new bool[(int)Hand_Values.END]; for(int i = 0; i < is_hand_value.Length; i++){ is_hand_value[i] = false; } // check for the possibility of a flush Card_Suite[] flush_suites = check_for_flushes(); is_hand_value[(int)Hand_Values.FLUSH] = flush_suites.Length > 0; // record if it's possible for a flush if(flush_suites.Length > 0){ flush_suite = flush_suites[0]; } // check for a normal straight is_hand_value[(int)Hand_Values.STRAIGHT] = check_for_straight(out straight_starting_value); // verify this will appropriately return TEN if royal straight present // check for a normal straight flush if(is_hand_value[(int)Hand_Values.FLUSH] && is_hand_value[(int)Hand_Values.STRAIGHT]){ is_hand_value[(int)Hand_Values.STRAIGHT_FLUSH] = check_for_straight_flush(straight_starting_value, flush_suites); flush_suite = get_straight_flush_suite(straight_starting_value, flush_suites); } else{ is_hand_value[(int)Hand_Values.STRAIGHT_FLUSH] = false; } // check for royal_straights/flushes if(is_hand_value[(int)Hand_Values.STRAIGHT]){ is_hand_value[(int)Hand_Values.ROYAL_STRAIGHT] = check_for_royal_straight(); if(is_hand_value[(int)Hand_Values.ROYAL_STRAIGHT] && is_hand_value[(int)Hand_Values.FLUSH]){ is_hand_value[(int)Hand_Values.ROYAL_FLUSH] = check_for_royal_flush(flush_suites); flush_suite = get_royal_flush_suite(flush_suites); } else{ is_hand_value[(int)Hand_Values.ROYAL_FLUSH] = false; } } // check for other non-flush things // check for multi-card things Hand_Values multi_card_hand_value = check_for_multi_card_hands(); switch(multi_card_hand_value){ case(Hand_Values.FULL_HOUSE): is_hand_value[(int)Hand_Values.FULL_HOUSE] = true; is_hand_value[(int)Hand_Values.THREE_OF_A_KIND] = true; is_hand_value[(int)Hand_Values.TWO_PAIR] = true; is_hand_value[(int)Hand_Values.ONE_PAIR] = true; is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; case(Hand_Values.TWO_PAIR): is_hand_value[(int)Hand_Values.TWO_PAIR] = true; is_hand_value[(int)Hand_Values.ONE_PAIR] = true; is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; case(Hand_Values.FOUR_OF_A_KIND): is_hand_value[(int)Hand_Values.FOUR_OF_A_KIND] = true; is_hand_value[(int)Hand_Values.THREE_OF_A_KIND] = true; is_hand_value[(int)Hand_Values.ONE_PAIR] = true; is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; case(Hand_Values.THREE_OF_A_KIND): is_hand_value[(int)Hand_Values.THREE_OF_A_KIND] = true; is_hand_value[(int)Hand_Values.ONE_PAIR] = true; is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; case(Hand_Values.ONE_PAIR): is_hand_value[(int)Hand_Values.ONE_PAIR] = true; is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; case(Hand_Values.HIGH_CARD): is_hand_value[(int)Hand_Values.HIGH_CARD] = true; break; } // find the best hand value for(int i = is_hand_value.Length - 1; i >= 0; i--){ if(is_hand_value[i]){ return (Hand_Values)i; } } return Hand_Values.HIGH_CARD; }
private Card_Suite get_royal_flush_suite(Card_Suite[] flush_suites) { int[] royals_in_suite = new int[flush_suites.Length]; // initialize royals_in_suite explicitly for(int i = 0; i < royals_in_suite.Length; i++){ royals_in_suite[i] = 0; } for(int i = 0; i < n_held; i++){ Card current_card = cards_p[i]; if(current_card.value == Card_Value.ACE || (current_card.value >= Card_Value.TEN && current_card.value <= Card_Value.KING)){ for(int royals_in_suite_index = 0; royals_in_suite_index < royals_in_suite.Length; royals_in_suite_index++){ if(current_card.suite == flush_suites[royals_in_suite_index]){ // if it's a royal, update the appropriate royals in suite number ++royals_in_suite[royals_in_suite_index]; } } } } for(int i = 0; i < royals_in_suite.Length; i++){ if(royals_in_suite[i] >= STRAIGHT_LENGTH){ return flush_suites[i]; } } return Card_Suite.END; }
private Card_Suite get_straight_flush_suite(Card_Value starting_value, Card_Suite[] flush_suites) { Card_Suite royal_flush_suite = get_royal_flush_suite(flush_suites); if(royal_flush_suite != Card_Suite.END){ return royal_flush_suite; } int[] n_in_suite = new int[flush_suites.Length]; for(int i = 0; i < n_held; i++){ Card current_card = cards_p[i]; if(current_card.value < (Card_Value)((int)starting_value + 5) && current_card.value >= starting_value){ // if it's the right value for(int suite_index = 0; suite_index < flush_suites.Length; suite_index++){ if(current_card.suite == flush_suites[suite_index]){ n_in_suite[suite_index]++; if(n_in_suite[suite_index] >= STRAIGHT_LENGTH){ return flush_suites[suite_index]; } } } } } return Card_Suite.END; }
private Card[] get_flush_best(Card_Suite flush_suite) { organize_by_value(); Card[] best = new Card[5]; int index = 0; for(int i = 0; i < n_held; i++){ if(cards_p[i].suite == flush_suite){ best[index++] = cards_p[i]; } } return best; }
private void fill_best(bool straight, bool flush, Card_Value straight_starting_value, Card_Suite flush_suite) { if(straight && flush){ if(best_hand_value_p == Hand_Values.ROYAL_FLUSH){ the_best_p = get_royal_straight_best(); } else{ the_best_p = get_straight_flush_best(straight_starting_value); } } else if(straight){ if(best_hand_value_p == Hand_Values.ROYAL_STRAIGHT){ the_best_p = get_royal_straight_best(); } else{ the_best_p = get_straight_best(straight_starting_value); } } else if(flush){ the_best_p = get_flush_best(flush_suite); } else{ organize_by_value(); the_best_p = get_multi_card_best(best_hand_value_p); } }
private bool check_for_straight_flush(Card_Value starting_value, Card_Suite[] flush_suites) { if(check_for_royal_flush(flush_suites)){ return true; } if(starting_value > (Card_Value)((int)Card_Value.END - 5)){ return false; } return get_straight_flush_suite(starting_value, flush_suites) != Card_Suite.END; }
private bool check_for_royal_flush(Card_Suite[] flush_suites) { return get_royal_flush_suite(flush_suites) != null; }
private Card_Suite[] check_for_flushes(int flush_length = 5) { int[] n_in_suite = new int[(int)Card_Suite.END]; for(int i = 0; i < n_in_suite.Length; i++){ n_in_suite[i] = 0; } int n_flush_suites = 0; for(int i = 0; i < n_held; i++){ int suite_index = (int)cards_p[i].suite; ++n_in_suite[suite_index]; if(n_in_suite[suite_index] == flush_length){ ++n_flush_suites; } } Card_Suite[] flush_suites = new Card_Suite[n_flush_suites]; int flush_suite_index = 0; for(int i = 0; i < n_in_suite.Length; i++){ if(n_in_suite[i] >= flush_length){ flush_suites[flush_suite_index++] = (Card_Suite)i; } } return flush_suites; }