Advertisement

poker game

Started by November 01, 2024 12:29 AM
173 comments, last by Alberth 6 hours, 57 minutes ago

I see. Well, I took a peak at main.cpp – void RankHand(HandInfo* hand)

There is no reason to use a pointer in this situation, when using C++. Rather, one can use a reference – void RankHand(HandInfo &hand) or void RankHand(const HandInfo &hand)

Don't use pointers when they're not needed. If there's one thing I know about C++ after like 25 years, is that pointers are not necessary 99% of the time.

I want to use pointers in order to learn about them

Advertisement

Yes, that's supposed to be a reference.
What else can you explain to Phil?

Other than what's already been said here
http://gamedev.net/forums/topic/717647-poker-game/5467696/?page=12

Dev careful. Pixel on board.

I’m not sure what needs to be explained.

the variable “make_ace_high=true” results in a runtime error otherwise the code compiles fine

I am trying to understand and use this code

			HandInfo *hand = NULL;

			bool make_ace_high = false;
			bool 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;
				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;
				}
			}

it causes the code to exit with an error code and exit prematurely.

Advertisement

nowhere in the code do we assign NULL to anything and then try to use it.
The runtime error that you've created is happening on the line just before make_ace_high = true

Re-read this again. http://gamedev.net/forums/topic/717647-poker-game/5467696/?page=12
That is an overview of what the code does. Once you understand what it does, we'll talk about how to use it.

You're doing pretty good Phil considering the noise.

Dev careful. Pixel on board.

Do you still not understand wanting to know what benefit there is to knowing what a 3-card hand can possibly make, depending on what cards are still not flipped? It's basic AI, if you can even call it that.

I am not very good with pointers so this line of code perplexes me.

When you have completed your hand classification functionality, you will want to test it against the standard poker probability – https://en.wikipedia.org/wiki/Poker_probability

For instance, when trying 2598960 different decks, one would expect the number (frequency) of the Royal Flush to be 4.

Here is my chart of hand type and frequency. for 5-card hands It's not perfect, but it's super close. It's what you should expect in your code.

As always, the code is at: https://github.com/sjhalayka/poker

High Card
1302248

One Pair
1098485

Two Pair
123431

Three of a kind
54989

Straight
10183

Flush
5203

Full House
3752

Four of a kind
636

Straight Flush
29

Royal Flush
4
Advertisement