Advertisement

poker game

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

Here's the detect possible flush:

size_t get_suit_count(const short unsigned int suit, const vector<card>& remaining_unflipped_cards)
{
	size_t count = 0;

	for (size_t i = 0; i < remaining_unflipped_cards.size(); i++)
		if (suit == remaining_unflipped_cards[i].suit)
			count++;

	return count;
}

bool is_possible_flush(const vector<card>& sorted_hand, const vector<card>& remaining_unflipped_cards)
{
	const size_t num_wildcards = MAX_NUM_CARDS_PER_HAND - sorted_hand.size();

	map<short unsigned int, size_t> value_counts;
	map<short unsigned int, size_t> suit_counts;

	for (size_t i = 0; i < sorted_hand.size(); i++)
	{
		value_counts[sorted_hand[i].value]++;
		suit_counts[sorted_hand[i].suit]++;
	}

	// Is there only one suit?
	if (suit_counts.size() != 1)
		return false;

	size_t the_suit_count = get_suit_count(suit_counts.begin()->first, remaining_unflipped_cards);

	if (the_suit_count < num_wildcards)
		return false;

	return true;
}

If you think that these codes are big, they are about as simple as you can get. The straight and the straight flush will be the the most complicated code – it uses a sliding window. I should have that code today or tomorrow. Thanks for your patience.

Advertisement

@NubDevice in this bitset code the hand variable is undefined

@pbivens67 not in my version
Also, re-downloaded from the github link. Compiles good.
Can you please be more descriptive of your error?

@taby I see what you mean about this slots and sleeves thing.
Never the less, I got mine done without that concept.
https://github.com/MarkKughler/Poker
The wild card stand-alone version is main_iteration_02.cpp

I'm going to bail soon boys.
Really getting into the AngelScript stuff today finally.
But it was nice to take a break and bang out the wildcard thing.
Thanks. Wicked cool.

Dev careful. Pixel on board.

I think I have to implement a class

Can you please paste the relevant code in here, for reference? I'm very interested to see how you got away from using a sliding window.

Advertisement

nah, too much.
I try to not do wall of code.
required quite a few changes and some creative logic in a few places.

Github if you're that curious.
I gave the link in the post above that you just responded to.

Dev careful. Pixel on board.

pbivens67 said:

I think I have to implement a class

Probably not, my friend. More than likely missed a copy/paste.
You know, if you were to also set up a github like Taby inquired, I could perhaps pinpoint your mistakes quite a bit better.
I'm cool with SDL2 but skipped that for the most part and have SDL3 somewhere on this system or the external drive.
Not really a problem.

Dev careful. Pixel on board.

I looked at marks code but cannot find the hand variable initial position

There you go.

The instance has been renamed to player2_hand on line 52.
Was already making moves to have multiple players. That's the reason.

Dev careful. Pixel on board.

Advertisement