Re: A83:Black Jack


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

Re: A83:Black Jack




In accordance with the prophecy, Jkhum98@aol.com uttered:


> In a message dated 10/10/99 12:13:18 PM Central Daylight Time, 
> lairfight@softhome.net writes:

>>> I dont know what kind of deck you have, but in a normal deck of cards 
> there 
>> is
>>  > 52 cards..
>>  > Anyway, I think this method (useing a virtual deck of cards) is the best 
>> way, if
>>  > you want to do a _real_ simulation of Black Jack. A good BJ player keeps 
>> track
>>  > of what cards is already played, and makes his choices from that.
>>  > you can also have double, triple or more decks.
>>  > and useing a deck automatically solves the double ace of spades thing.. (
>> wich
>>  > actually is possible, if you play BJ with a double (or more) deck)
>>  
>>  > //Olle
>>  
>>  
>>  52 + 2 jokers = 54.
>>  
>>  Anyway, here's a good routine (in c-inspired pseudo code) to shuffle a 
> deck:
>>  
>>  deck[0] = 0;
>>  for(i=1; i<52; i++)
>>  {
>>    j = random number in the range 0 to i;
>>    deck[i] = deck[j]; deck[j] = i;
>>  }

> Yes, I drew the number 54 from the back of my mind somewhere, but 52 is 
> right... and this C code, how does it keep track of the suits? Is my idea for 
> storing the bits a good one, or is there another method...?

> Jason_K

The routine above uses the numbers 0 to 51 to represent the cards. If you
want to represent them in another way, you would have to add something like:

for(i=0; i<52; i++) deck[i] = f(deck[i]);

where f() converts a number in the range 0 to 51 into a byte coded using your
card representation system. Such a routine would be f(x) = x%13+1+(x/13)<<4,
but this could probably be better solved using a 52-byte table.

Linus

   - Linus Akesson ------------------------- http://linusworld.cjb.net -
   ::: :::. :.:: :. ::.. : :... ::.: ::. :::: :.:. :: :..: :.. :.: :....

 Unix is user-friendly. It's just very selective with who it's friends are.




References: