-
random number
I am working on my own project that is eventually going to simulate a poker game, and give each player their % of winning.
But I am a rather new programmer, so I am going to start out small. I am only going to have cards 1 through 4 and only two suites.
What I need to do is randomly pick one of the 8 cards, then randomly pick another card. But every time a card is picked, eliminate it from the options.
In other words, pick a card from one of the 8 possible cards, but dont pick the same card twice.
thank you in advance.
-
Create a deck, which knows which cards have been dealt, and which cards remain.
-
and I would make a deck... how?
-
-
-
-
A bunch of flags. Ace through King take 0 through 12 in the array for one suit, then 13 through 25 for another suit, and so on. If the flag is 1, meaning the card is available, then it can be chosen. Once chosen, the flag is set to 0 to indicate it cannot be used again. If the random draw returns a card with the flag at 0, then the draw must be repeated until it gets something with a 1. When the card is put back, the flag is set back to 1 so it can be redrawn. Player hands could be done in a very similar way, except, perhaps, using a card ID instead to save on memory (as long as fewer than 6 cards are needed anyway).
-
Quote:
Originally Posted by
s_jsstevens
thanks.. big help
Well what did you expect, we're not going to give you flat out code. You asked how to make a deck, I said with structures and that was the right answer. Now, since what now I believe you meant to say is : "How do I represent a deck with structures ?" here's how you'd do that :
All you do is have a card structure which is bascially 2 intergers, one interger represents the card's value, the other represent's the card's suit. Then, your deck would just be an array of 52 of these structures, as Salem has posted above.
-
If I was to store flags, I wouldn't use an array of bytes, rather a bitset. Your then only using 7 bytes to store 52 "bytes" of flags.
But I suppose this is over-complex. Stick with an array of structures as Salem said.
-
Yeah, using bitwise operators are a bit complex. Merely using an array with 52 items is the easiest way.