예제 #1
0
        public Card_Info[] extract_cards(string raw_input)
        {
            Card_Info[] info_arr = new Card_Info[10];
             int arr_index = 0;
             string[] raw_choices = raw_input.Split(new char[] { ',', ';' });
             foreach (string raw_choice in raw_choices)
             {
            string[] split_raw = raw_choice.Split(new char[] { ' ' });
            for (int i = 0; i < split_raw.Length; i++)
            {
               Card_Value val = text_to_value(split_raw[i]);
               if (val != Card_Value.END)
               {
                  // found the card value of the split
                  Card_Info card_info = new Card_Info();
                  card_info.value = val;
                  card_info.suite = text_to_suite(split_raw[i + 2]);

                  info_arr[arr_index++] = card_info;
               }
            }
             }

             return info_arr;
        }
예제 #2
0
        public Card_Info[] extract_cards(string raw_input)
        {
            Card_Info[] info_arr  = new Card_Info[10];
            int         arr_index = 0;

            string[] raw_choices = raw_input.Split(new char[] { ',', ';' });
            foreach (string raw_choice in raw_choices)
            {
                string[] split_raw = raw_choice.Split(new char[] { ' ' });
                for (int i = 0; i < split_raw.Length; i++)
                {
                    Card_Value val = text_to_value(split_raw[i]);
                    if (val != Card_Value.END)
                    {
                        // found the card value of the split
                        Card_Info card_info = new Card_Info();
                        card_info.value = val;
                        card_info.suite = text_to_suite(split_raw[i + 2]);

                        info_arr[arr_index++] = card_info;
                    }
                }
            }

            return(info_arr);
        }
예제 #3
0
 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;
 }
예제 #4
0
        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;
        }
예제 #5
0
 static public void get_mark(Card_Info info)
 {
     if (info.mark.Equals(""))
     {
         Console.WriteLine("It is a plain card.");
     }
     else
     {
         Console.WriteLine(info.mark);
     }
 }
예제 #6
0
        static Deck()
        {
            rand = new Random();

             // construct the standard deck
             standard_deck = new Card[52];
             uint ID = 0;

             for (int i = 0; i < (int)Card_Suite.END; i++)
             {
            for (int j = 1; j < (int)Card_Value.END; j++)
            {
               Card_Info info = new Card_Info();
               info.suite = (Card_Suite)i;
               info.value = (Card_Value)j;
               info.mark = "A fresh playing card with no markings.";
               standard_deck[i * ((int)Card_Value.END - 1) + j - 1] = new Card(info, ID);
               ++ID;
            }
             }
        }
예제 #7
0
        static Deck()
        {
            rand = new Random();

            // construct the standard deck
            standard_deck = new Card[52];
            uint ID = 0;

            for (int i = 0; i < (int)Card_Suite.END; i++)
            {
                for (int j = 1; j < (int)Card_Value.END; j++)
                {
                    Card_Info info = new Card_Info();
                    info.suite = (Card_Suite)i;
                    info.value = (Card_Value)j;
                    info.mark  = "A fresh playing card with no markings.";
                    standard_deck[i * ((int)Card_Value.END - 1) + j - 1] = new Card(info, ID);
                    ++ID;
                }
            }
        }
예제 #8
0
        public void get_card_info(string info, out Card_Info card_info)
        {
            string[] parsed_elements = info.Split(';');
             string card_value_str = "";
             string card_suite_str = "";
             string mark = "";
             if (parsed_elements.Length > 0)
             {
            card_value_str = parsed_elements[0];
            if (parsed_elements.Length > 1)
            {
               card_suite_str = parsed_elements[1];
               if (parsed_elements.Length > 2)
               {
                  mark = parsed_elements[2].TrimStart();
               }
            }
             }

             card_info.suite = text_to_suite(card_suite_str);
             card_info.value = text_to_value(card_value_str);
             card_info.mark = mark;
        }
예제 #9
0
        public void get_card_info(string info, out Card_Info card_info)
        {
            string[] parsed_elements = info.Split(';');
            string   card_value_str  = "";
            string   card_suite_str  = "";
            string   mark            = "";

            if (parsed_elements.Length > 0)
            {
                card_value_str = parsed_elements[0];
                if (parsed_elements.Length > 1)
                {
                    card_suite_str = parsed_elements[1];
                    if (parsed_elements.Length > 2)
                    {
                        mark = parsed_elements[2].TrimStart();
                    }
                }
            }

            card_info.suite = text_to_suite(card_suite_str);
            card_info.value = text_to_value(card_value_str);
            card_info.mark  = mark;
        }
예제 #10
0
 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;
 }
예제 #11
0
 public static void get_mark(Card_Info info)
 {
     if (info.mark.Equals(""))
      {
     Console.WriteLine("It is a plain card.");
      }
      else
      {
     Console.WriteLine(info.mark);
      }
 }
예제 #12
0
 public static void display(Card_Info info)
 {
     display(info.suite, info.value);
 }
예제 #13
0
 static public void display(Card_Info info)
 {
     display(info.suite, info.value);
 }
예제 #14
0
        /*

          public void organize()
          {
         if(n_held == 0
            || cards_p[0] == null)
         {
            return;
         }
         // organize by suite - check for flush or royal flush
         // organize by value - check for straight, straight flush, royal flush, royal straight, pairs, three of a kinds
         organize_by_suite();

         if(check_for_flush()){
            // hand is full and has flush --> check for straight
            organize_by_value(cards_p);

            Card_Value straight_start_val;
            bool straight = check_for_straight(out straight_start_val);

            if(straight){
               // done
               fill_best(true, true, cards_p[0].value, Card_Value.END, cards_p[0].suite);
            }
            else{
               fill_best(true, false, cards_p[0].value, Card_Value.END, cards_p[0].suite);
            }

            return;
         }
         else{
            bool flush = check_for_flush(true);
            bool potential_flush = (flush && n_held == max_size - 1) || (!flush && n_held == max_size && cards_p[0].suite == cards_p[max_size - 1].suite);
            organize_by_value(cards_p);
            Card_Value straight_start_val;
            bool straight = check_for_straight(out straight_start_val);

            if(straight){
               fill_best(false, true, straight_start_val, Card_Value.END, Card_Suite.END);
               return;
            }
            else{
               organize_unexemplary_hand();
            }

            if(best_hand_value_p == Hand_Values.HIGH_CARD
               && potential_flush){
               organize_by_suite();
               if (n_held > 1
                  && cards_p[1].suite != cards_p[0].suite)
               {
                  Card temp = cards_p[n_held - 1];
                  for (int i = 0; i < n_held; i++)
                  {
                     Card temp2 = cards_p[i];
                     cards_p[i] = temp;
                     temp = temp2;
                  }
               }
            }
         }
          }

          // if a straight or a flush doesn't exist in organize(), it calls this to find the non-straight or non-flush cards
          // that result in the best value
          private void organize_unexemplary_hand()
          {
         // four of a kind first
         // two pair
         // three of a kind
         // one pair
         // high card

         organize_by_value(cards_p);

         if (n_held == 0
            || cards_p[0] == null)
         {
            return;
         }

         Card_Value val_1 = Card_Value.END;
         Card_Value val_2 = Card_Value.END;
         bool val_1_found = false;
         bool val_2_found = false;

         for(int i = 1; i < n_held; i++){
            if(!val_1_found
               && cards_p[i].value == cards_p[i-1].value){
               val_1 = cards_p[i].value;
               val_1_found = true;
            }
            else if(cards_p[i].value == cards_p[i-1].value
               && cards_p[i].value != val_1
               && val_1_found
               && !val_2_found){
               val_2 = cards_p[i].value;
               val_2_found = true;
               break;
            }
         }

         fill_best(false, false, val_1, val_2, Card_Suite.END);
          }

          private void fill_best(bool flush, bool straight, Card_Value val_1, Card_Value val_2, Card_Suite suite)
          {
         int best_arr_index = 0;
         int rest_arr_index = 0;
         Card[] temp_best = new Card[max_size];
         Card[] temp_rest = new Card[max_size];
         // handle flushes
         if(flush){
            for(int i = 0; i < n_held; i++){
               if(cards_p[i].suite == suite){
                  temp_best[best_arr_index++] = cards_p[i];
               }
               else{
                  temp_rest[rest_arr_index++] = cards_p[i];
               }
            }
            organize_by_value(temp_best);
            if(straight){
               if(the_best_p[0].value == (Card_Value)((int)Card_Value.KING - temp_best.Length)){
                  best_hand_value_p = Hand_Values.ROYAL_FLUSH;
               }
               best_hand_value_p = Hand_Values.STRAIGHT_FLUSH;
            }
            else
            {
               best_hand_value_p = Hand_Values.FLUSH;
            }
         }
         else if(straight){
            Card_Value value_tracker = val_1;
            organize_by_value(cards_p);
            for(int i = 0; i < n_held; i++){
               if(cards_p[i].value == value_tracker){
                  temp_best[best_arr_index++] = cards_p[i];
                  ++value_tracker;
               }
               else
               {
                  temp_rest[rest_arr_index++] = cards_p[i];
               }
            }
            if (the_best_p[0].value == (Card_Value)((int)Card_Value.KING - temp_best.Length))
            {
               best_hand_value_p = Hand_Values.ROYAL_STRAIGHT;
            }
            else
            {
               best_hand_value_p = Hand_Values.STRAIGHT;
            }
         }
         else{
            // handle everything else: four of a kind, full house, two pair, three of a kind, one pair, high card
            if (val_2 != Card_Value.END)
            {
               // handle full house, two pair
               // determine higher of the values
               Card_Value highest_val;
               if (val_2 > val_1)
               {
                  highest_val = val_2;
               }
               else
               {
                  highest_val = val_1;
               }

               int n_val_1 = 0;
               int n_val_2 = 0;
               for (int i = 0; i < n_held; i++)
               {
                  if (cards_p[i].value == val_1)
                  {
                     ++n_val_1;
                  }
                  else if (cards_p[i].value == val_2)
                  {
                     ++n_val_2;
                  }
               }

               Card_Value higher_value;
               Card_Value lower_value;
               if (n_val_2 > n_val_1)
               {
                  higher_value = val_2;
                  lower_value = val_1;
               }
               else
               {
                  higher_value = val_1;
                  lower_value = val_2;
               }

               for (int i = 0; i < n_held; i++)
               {
                  if (cards_p[i].value == higher_value)
                  {
                     temp_best[best_arr_index++] = cards_p[i];
                  }
                  else if(cards_p[i].value != lower_value)
                  {
                     temp_rest[rest_arr_index++] = cards_p[i];
                  }
               }
               for (int i = 0; i < n_held; i++)
               {
                  if (cards_p[i].value == lower_value)
                  {
                     temp_best[best_arr_index++] = cards_p[i];
                  }
               }

               if (n_val_1 == 3
                  || n_val_2 == 3)
               {
                  best_hand_value_p = Hand_Values.FULL_HOUSE;
               }
               else
               {
                  best_hand_value_p = Hand_Values.TWO_PAIR;
               }
            }

            // handle four of a kind, three of a kind, one pair, high card
            else
            {
               int counter = 0;
               for (int i = 0; i < n_held; i++)
               {
                  if (cards_p[i].value == val_1)
                  {
                     ++counter;
                     temp_best[best_arr_index++] = cards_p[i];
                  }
                  else
                  {
                     temp_rest[rest_arr_index++] = cards_p[i];
                  }
               }

               switch (counter)
               {
                  case 1:
                     best_hand_value_p = Hand_Values.HIGH_CARD;
                     break;
                  case 2:
                     best_hand_value_p = Hand_Values.ONE_PAIR;
                     break;
                  case 3:
                     best_hand_value_p = Hand_Values.THREE_OF_A_KIND;
                     break;
                  case 4:
                     best_hand_value_p = Hand_Values.FOUR_OF_A_KIND;
                     break;
                  default:
                     best_hand_value_p = Hand_Values.HIGH_CARD;
                     break;
               }
            }
         }

         // recreate best_p and fill it with temp_best's contents up to best_arr_index's index
         // also recreate rest_p
         the_best_p = new Card[best_arr_index];
         the_rest_p = new Card[rest_arr_index];

         for (int i = 0; i < best_arr_index; i++)
         {
            the_best_p[i] = temp_best[i];
         }
         for (int i = 0; i < rest_arr_index; i++)
         {
            the_rest_p[i] = temp_rest[i];
         }

         // reestablish the hand based off of the_best and the_rest
         int hand_index = 0;
         for (int i = 0; i < the_best_p.Length; i++)
         {
            cards_p[hand_index++] = the_best_p[i];
         }
         for (int i = 0; i < the_rest_p.Length; i++)
         {
            cards_p[hand_index++] = the_rest_p[i];
         }
          }

          private void fill_best_flush(bool straight, Card_Value val_1)

          // bubble sort by suite
          private void organize_by_suite()
          {
         for (int i = 0; i < n_held; i++)
         {
            for (int j = i; j < n_held; j++)
            {
               if (cards_p[i] != null
                  && cards_p[j] != null
                  && cards_p[i].suite < cards_p[j].suite)
               {
                  Card temp = cards_p[i];
                  cards_p[i] = cards_p[j];
                  cards_p[j] = temp;
               }
            }
         }
          }

          private bool check_for_flush(bool ignore_n_held)
          {
         Card_Suite flush_suite;
         if(n_held == 0
            || cards_p[0] == null){
            return false;
         }
         else if(n_held < max_size
            && !ignore_n_held)
         {
            return false;
         }
         else{
            flush_suite = cards_p[0].suite;
         }

         for (int i = 1; i < n_held; i++)
         {
            if (cards_p[i].suite != flush_suite)
            {
               return false;
            }
         }

         return true;
          }

          private bool check_for_flush()
          {
         return check_for_flush(false);
          }

          private bool check_for_straight(out Card_Value straight_start_val, bool ignore_n_held)
          {
         if(n_held == 0
            || cards_p.Length < 1)
         {
            straight_start_val = Card_Value.END;
            return false;
         }
         else
         {
            straight_start_val = cards_p[0].value;
         }

         // handle royal straight
         if (check_for_royal_straight())
         {
            straight_start_val = Card_Value.TEN;
            return true;
         }

         // handle normal straights
         int n_straight = 1;
         for (int i = 1; i < n_held; i++)
         {
            if (cards_p[i].value == cards_p[i - 1].value)
            {
               continue;
            }
            else if (cards_p[i].value == cards_p[i - 1].value - 1)
            {
               ++n_straight;
               straight_start_val = cards_p[i].value;
            }
            else
            {
               n_straight = 1;
               straight_start_val = cards_p[i].value;
            }
         }

         if (n_straight == 4 && ignore_n_held)
         {
            return true;
         }
         else if (n_straight >= 5)
         {
            return true;
         }
         else
         {
            return false;
         }
          }

          private bool check_for_royal_straight()
          {
         bool king_held = false;
         bool queen_held = false;
         bool jack_held = false;
         bool ten_held = false;
         bool ace_held = false;

         if (n_held < 5)
         {
            return false;
         }

         for (int i = 0; i < n_held; i++)
         {
            switch (cards_p[i].value)
            {
               case(Card_Value.ACE):
                  ace_held = true;
                  break;
               case(Card_Value.KING):
                  king_held = true;
                  break;
               case(Card_Value.QUEEN):
                  queen_held = true;
                  break;
               case(Card_Value.JACK):
                  jack_held = true;
                  break;
               case(Card_Value.TEN):
                  ten_held = true;
                  break;
               default:
                  continue;
            }
         }

         if(ace_held
            && king_held
            && queen_held
            && jack_held
            && ten_held)
         {
            return true;
         }
         else
         {
            return false;
         }
          }

          private bool check_for_straight(out Card_Value straight_start_val)
          {
         return check_for_straight(out straight_start_val, false);
          }

          */
        public int discard(Card_Info[] info_arr)
        {
            int n_discarded = 0;

             foreach (Card_Info info in info_arr)
             {
            for (int hand_index = 0; hand_index < n_held; hand_index++)
            {
               if (cards_p[hand_index].value == info.value
                  && cards_p[hand_index].suite == info.suite)
               {
                  deck_p.discard(cards_p[hand_index]);

                  if (hand_index == n_held)
                  {
                     cards_p[hand_index] = null;
                  }
                  else
                  {
                     cards_p[hand_index] = cards_p[n_held-1];
                     cards_p[n_held-1] = null;
                  }

                  --n_held_p;

                  ++n_discarded;
               }
            }
             }

             return n_discarded;
        }