Advertisement

poker game

Started by November 01, 2024 12:29 AM
175 comments, last by pbivens67 1 day, 14 hours ago

I'm sticking with std::shuffle believing i get a better distribution because it doesn't rely on rand().

Dev careful. Pixel on board.

Well, for what it’s worth, random_shuffle does a much better job than just swapping card pairs at random position in the card pile. Thanks again for your input.

Advertisement

taby said:
Well, for what it’s worth, random_shuffle does a much better job than just swapping card pairs at random position in the card pile. Thanks again for your input.

It doesn't. std::shuffle is literally just an advancement, and eventual replacement of std::random_shuffle. https://en.cppreference.com/w/cpp/algorithm/random_shuffle. Both their example-implementations as well as publically available implementations of libstd and libc use the exact same algorithm for both, see th elink. MSVC is likely to be the same. The only subtle difference is in what random-generator you pass to std::shuffle, but that's only determining the randomness, and not whether it “just swapps card pairs at random positions” or not.

Well, the thing is.. I was forever getting the highest ace as the first dealt card. When I switched to random_shuffle, this obvious problem went away. Using MSVC.

What I’m saying is that my old shuffle code was disastrously buggy.

Also, I will visualize the classification distributions for 3 and 4-card hands.

Here are the distribution of the classifications for 1-card to 5-card hands.

	srand(static_cast<unsigned int>(time(0)));

	map<short unsigned int, size_t> hand_class_counts;

	size_t count = 1000000;

	for(size_t i = 0; i < count; i++)
	{
		vector<card> deck;
		init_deck(deck);
		shuffle_cards(deck);

		vector<card> hand;

		size_t num_init_cards = 1;// MAX_NUM_CARDS_PER_HAND;

		deal_hand(deck, hand, num_init_cards);

		short unsigned int classification = 0;
		
		if (num_init_cards < 5)
			classification = get_best_wild_classification(hand, deck);
		else
			classification = classify_hand(hand);

		hand_class_counts[classification]++;

	}


	ofstream out_file("distribution.txt");

	for (map<short unsigned int, size_t>::const_iterator ci = hand_class_counts.begin(); ci != hand_class_counts.end(); ci++)
	{
		print_hand_classification(ci->first);
		cout << ci->second << endl << endl;

		out_file << ci->first << " " << ci->second << endl;
	}

The following graph shows that for the 1-card distribution that only Straight Flush and Royal Flush are found, and that for 5-card distribution everything except Royal Flushes are found. This is symptomatic that we need to add more hands to the distributions.

Advertisement

I am not using wild cards

OK, good. I'm not using wild cards.

Well, I am :P

Dev careful. Pixel on board.

There are many types of poker: some with and without wild cards. There is no one best poker, although Texas Hold Em is pretty popular. I am making a game called Blind Poker. It is a game that originated with the First Nation of English River. No wild cards.

A screenshot of a prototype from a long while ago:

Advertisement