Re: A83:Black Jack


[Prev][Next][Index][Thread]

Re: A83:Black Jack




In a message dated 10/10/99 10:42:34 AM Central Daylight Time, 
NathanG@firstva.com writes:

> I'm making a Casino (For anyone who hasn't heard me say it a dozen
>  times), and for the black jack portion, I need something to generate a
>  random card (w/ suit since it will be graphical) Without repeats. I also
>  can't make it destructive so that it eventually runs out of cards, all I
>  need it to do is keep you from getting 2 aces of spades or anything like
>  that. Any ideas?

You could have an array of 54 numbers (all the cards) and create a routine to 
shuffle all those numbers throughout the array, which would involve program 
write back so that it could be even more random. To do the shuffling, you 
could use a random number routine and make it pick two integers between 1 and 
54 (inclusive) and then swap the bytes at those two places, and do that 
sequence like 30 times or so, on each round. Then you could "draw" the cards 
from the front of that array, and just move a pointer up through the array to 
not reuse the cards....

Btw, I have an idea on how you can do that byte storage to keep track of the 
cards... In a byte, each Nibble (4 bits) is capable of holding the numbers 
0-15, and that is perfect for the amount of cards there are in a suit. So the 
number 1 corrosponds to an Ace, a 2 is the 2 card, a 15 is the king card, 
etc. And then that upper Nibble of a byte has the bits Set corrosponding to 
each suit. For example, Bit 7 is Set for the Spades, and Bits 6, 5, and 4 are 
reset. Bit 6 can be for Hearts, Bit 5 can be for Clubs, and Bit 4 can be for 
the Diamonds... Then when you grab these bytes out of the array, you do bit 
checking like so "BIT 7, a \ jp nz, Its_A_Spade" and then draw it 
accordingly... And then you mask off the top 4 bits to find the number on the 
card which is left in the lower nibble, and then draw that to the screen 
accordingly...

I had this idea once when I got the urge to make a solitare game, but never 
carried that project out. I thought this idea was a damn good one though, but 
if anyone can think of a more efficient way for speed, randomness, byte 
storage, etc., I would surely like to hear it, thanks, and I hope my ideas 
could have helped a little bit, cya...

Jason_K
tcpa.calc.org


Follow-Ups: