Advertisement

poker game

Started by November 01, 2024 12:29 AM
171 comments, last by taby 2 hours, 10 minutes ago

I looked at line 51 but cannot find the hand variable itself all I find is Handinfo

Right next to it.

HandInfo is the type.
player2_hand is the instance (last week we called it player_hand)
the curly brackets are the initialization clearing the contents to zero.

The hand naming has always been used during function argument reference.
The evaluation or display functions are dealing with one hand at a time.
The outermost scope has to make a distinction of who's hand it is.

Dev careful. Pixel on board.

Advertisement

I am still a little confused

I blame Taby. 🙂
Life moves fast. That's the lesson.
I'll wait for you though. What are you confused about?
The variable name change?

Code is organic. It morphs a number of times as it grows.
Cleaned up the original main.cpp that you were accustomed to seeing.
The file you're looking for is main_iteration_01.cpp

In my spare time, I'll be editing other versions.
Making it my own and wreaking havoc like no tomorrow.

Dev careful. Pixel on board.

OK, I'm sorry, but I'm lost. Please let me know: which file contains the relevant function, and what is the name of that function? I'm referring to the function that handles straights.

The Readme explains which file is what. It's three sentences. main.cpp will get you there. I do the entire classification in one go. The function name is RankHand. Does that help?

Dev careful. Pixel on board.

Advertisement

It helps a little I just get a compiler error at the hand variable

I think that there is a misunderstanding here, and it's mostly my fault.

When I refer to wild card slots, I am talking about the hand card count having between 1 and 4 cards, and so the wild card count is $$w = 5 -count$$. I'm not talking about using a particular value as a wild card. The sliding window method is still required, and it's what I'll be working on next.

how does bitset work here is the code I am using

			HandInfo hand;

			bool flush_found = false;
			bitset<4> suit_bitset;
			for (int i = 0; i < 5; i++)
			{
				if (hand.cards[i] < 14) suit_bitset.set(0);                            // clubs
				if (hand.cards[i] > 13 && hand.cards[i] < 27) suit_bitset.set(1);      // diamonds
				if (hand.cards[i] > 26 && hand.cards[i] < 40) suit_bitset.set(2);      // spades
				if (hand.cards[i] > 39) suit_bitset.set(3);                            // hearts
			}
			if (suit_bitset.count() == 1) 
				flush_found = true;

@pbivens67 The best way to visualize that is to watch it with the debugger.
std::bitset<4> initializes to what basically looks like four bools but all in one variable.
The set function takes a zero based index position and changes a default 0 to a 1.
The count function returns how many 1's are in the set.

The way we're using it here is we iterate over our five cards.
When our range is hit we set the bit.
If after all that when only one bit was set, that tells us we have all of the same suit.

You can imagine it looks something like this in memory. { 0, 0, 0, 0 }
If hand.cards[i] < 14 is true the memory will look like { 1, 0, 0, 0 } after the set(0)
Again, if all the cards did this, it still looks like { 1, 0, 0, 0 } and count() would return 1.

I basically use this instead of if/else if/else if/else if/else.
It's just another tool to use.
With that said, my weakness is std::map (standard associative containers) because I never use them.
But hey, it's good to try new/old things.

GOOD Question BTW. Now that's what I'm talking about.

@taby ah, well good. Now you have an opportunity to do the joker(wildcards) thing after this wild card slot thing that I still don't understand. I think I didn't put two and two together because my game is 5-card draw poker.

Dev careful. Pixel on board.

Advertisement