Blackjack 
Author Message
 Blackjack

Hi,
    I recently posted  a message about rendomizing sets of arrays, but, i
didn't make it very easy to understand.  Now, I think I can make it a bit
easier. I am writing a blackjack program for a class.  I want to display the
deck of cards in an array(s).  I then need to be able to pick random cards
from that array and display them seperatly from the deck.  I've tried to
figure out records, with no luck (im all new at this).  I;m not asking for
the who program to be written, just a little insight as to how I can
acomplish this with as little lines of code as possible.

Thank you,
Kane



Wed, 18 Jun 1902 08:00:00 GMT  
 Blackjack
Are you asking how to shuffle a deck of cards?  I'm pretty sure the following
algorithm is (a) as fast as you can get, yet (b) "perfect", in that all possible
hands are equally likely (assuming your "Random()" function is good) --

1)  Start with a deck of 52 cards.
2)  Pick a card from 52 cards.  Put it as card 52.
3)  Pick a card from (the first) 51 cards.  Put it as card 51.
4)  Iterate this process until ...
5)  Pick a card from (the first) 2 cards.  Put it as card 2.
6)  For "symmetry", you can include the final (trivial) step ---
     Pick a card from (the first) 1 card.  Put it as card 1.

Bob Schor
Pascal Enthusiast

Quote:

> Hi,
>     I recently posted  a message about rendomizing sets of arrays, but, i
> didn't make it very easy to understand.  Now, I think I can make it a bit
> easier. I am writing a blackjack program for a class.  I want to display the
> deck of cards in an array(s).  I then need to be able to pick random cards
> from that array and display them seperatly from the deck.  I've tried to
> figure out records, with no luck (im all new at this).  I;m not asking for
> the who program to be written, just a little insight as to how I can
> acomplish this with as little lines of code as possible.

> Thank you,
> Kane




Wed, 18 Jun 1902 08:00:00 GMT  
 Blackjack

Quote:
> Hi,
>     I recently posted  a message about rendomizing sets of arrays, but, i
> didn't make it very easy to understand.  Now, I think I can make it a bit
> easier. I am writing a blackjack program for a class.  I want to display the
> deck of cards in an array(s).  I then need to be able to pick random cards
> from that array and display them seperatly from the deck.  I've tried to
> figure out records, with no luck (im all new at this).  I;m not asking for
> the who program to be written, just a little insight as to how I can
> acomplish this with as little lines of code as possible.

Could use this :
TYPE card = record
        color : byte; {or string, to simplify writing}
        value : byte;
     end;
VAR pack : array[0..53] of card; {that's where all cardss are at                                        
begining}    
    player1, player2 {...} : array[1..12] of card; {you always
have                                                    more of 21 with 12 cards}
    up : byte=0; {each time a card is get from the pack, increment, and
get the next at p[up] -> don't have to move all card in the array this
way}

{generate the pack, at the begining}
for c:=1 to 4 do for v:=1 to 13 do begin
  p:=random(54);
  while there's already a card at pack[p], search another p; {could be
long, but that's the cleanest way i've found to have 54 cards all
different}
  pack[p].col:=c; pack[p].val:=v;
end;

Then, just get card var to one array to another in the prog (and his
ex-position get to col=zero, val=zero).

Not sure it's clear or efficient, but i would do like this.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Blackjack sourcecode for Delphi?

2. Blackjack

3. Blackjack Pascal code

4. Blackjack program

5. Blackjack program

6. S: Source - Blackjack

7. ANNOUNCEMENT: BLACKJACK GAME

8. Blackjack program

9. Blackjack program

10. pascal source for blackjack

11. Looking for BlackJack Source code??

12. Thanks for the help; heres the blackjack program im turning in

 

 
Powered by phpBB® Forum Software