Advertisement

poker game

Started by November 01, 2024 12:29 AM
158 comments, last by pbivens67 8 hours, 43 minutes ago

I am doing 5 card stud nothing wild

I renamed all the instances of the word wild in my code to open_slots. This way it's not confusing, sorry.

Edit: I included the is_possible_ functions purely for use with the AI.

Advertisement

what does “→ ”do

The arrow operator accesses members of pointers, or iterators. It’s like the dot operator, in a way.

OK, check this code out. This function checks a 5-card hand for a quadruplet.

bool is_four_of_a_kind(const vector<card>& sorted_hand)
{
	// Use a map to store the count of values
	map<short unsigned int, size_t> value_counts;

	// Fill the map with counts of the values
	for (size_t i = 0; i < MAX_NUM_CARDS_PER_HAND; i++)
		value_counts[sorted_hand[i].value]++;

	// For each element in the map
	for (map<short unsigned int, size_t>::const_iterator ci = value_counts.begin(); ci != value_counts.end(); ci++)
		if (ci->second == 4) // Is the size_t equal to 4?
			return true;

	// If we made it this far, then no quad was found
	return false;
}

Does this help?

Also, try this one:

bool is_flush(const vector<card>& sorted_hand)
{
	// Use a map to store the count of suits
	map<short unsigned int, size_t> suit_counts;

	// Fill the map with counts of the suits
	for (size_t i = 0; i < MAX_NUM_CARDS_PER_HAND; i++)
		suit_counts[sorted_hand[i].suit]++;

	// If only one suit, then it's a flush
	if (suit_counts.size() == 1)
		return true;

	// If we made it this far, then no flush was found
	return false;
}

I thought the arrow operator has something to do with pointers

Advertisement

It does. Also, iterators use the same operator.

can you give me an example of how to use the arrow operator, I want to use it in my straight determination in my poker game

What do you mean? You want to use a pointer? A pointer to what?

I want to use this code and understand how it works

  straight_found = true; // default true for sequential test
   if ((hand->cards[4] % 13 == 12) && (hand->cards[0] % 13 == 0))
   {   // King is present. rotate Ace to the back.
       make_ace_high = true;
       std::rotate(&hand->cards[0], &hand->cards[0]+1, &hand->cards[5]);
   }
   for (int i = 0; i < 4; i++)
   {
       int a = hand->cards[i] % 13;
       int b = hand->cards[i + 1] % 13;
       if (make_ace_high)
       {
           if (a == 0) a = 13;
           if (b == 0) b = 13;
       }
       if( b - a != 1 )
       {
           straight_found = false;
       }
   }
  
Advertisement