Advertisement

blackjack

Started by September 25, 2024 07:27 PM
34 comments, last by pbivens67 4 weeks, 2 days ago

ouch.
Started joining along a couple days ago.

The approach I'm considering over here is to pre-mix an int array of size fifty two that holds indices into the full ordered card group instead of calling rand per card draw. At the moment, all I have is a shuffle animation and an ability to render cards from atlas and a small amount of structure.

true, false, maybe, probably_not

I am using sdl and c++. it is nice that we are working on the same thing, good luck

Advertisement

okay, that's fine.

Here is a first pass at the shuffle to answer the original question.

#include <vector>
#include <algorithm>                             // pre-invented wheels
#include <random>
#include <chrono>

std::vector<int> indices = 
{   0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
   10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
   20, 21, 22, 23, 24, 25, 26, 27, 28, 29,       // an ordered int container so we have some data to manipulate
   30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
   40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 
   50, 51, 52 
};
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); // set up 
std::default_random_engine rng(seed);                                        // simular to srand(0)
std::shuffle(indices.begin(), indices.end(), rng);                           // standard library container shuffle (entire deck is mixed up in one line of code)
for (int i = 0; i < 52; ++i) deck.shuffled_state[i] = indices[i];            // demonstrating copy vector content to regular array (optional)

true, false, maybe, probably_not

I can't pass a vector to a switch statement I want to keep using the rand()% command.

Yeah, above deck.shuffled_state is a regular array.

No, GOod luck to you dear sir.

true, false, maybe, probably_not

Good luck to you as well sir however I am making good progress on my game.

Advertisement

I watched your video, and I liked the shuffling animation.

So do I.

Today's progress:
Added token texture atlas
Added the chip token animation driven by user selected wager amount.
Added int array index shuffle
Added custom GUI slider

Never give up Phil.

true, false, maybe, probably_not

good work!!! I am using sdl and c++ what are you using?

raylib / C++ but more towards a C form.

Good to hear you're making progress.

[end of page]

true, false, maybe, probably_not

This topic is closed to new replies.

Advertisement