Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Poker Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
poomanchunk




PostPosted: Mon Jun 14, 2004 5:55 pm   Post subject: Poker Help

Ok I'm making a casino, and I got alot of stuff to work already. But I can't get poker to work.
It's because of 52 cards, and not being able to get the same one twice. Unlike blackjack, I didn't need suits, so it's not bad. I thought poker would be just as easy, but I've been through 3 days of racking my brain trying to figure it out.

Finally I just gave up and came here Very Happy
I know there is a long way to do this... I very long way, which I do not wanna do, unless I have to.
(which is somewhat like this)
code:
loop
    If card (1) = card (2) then
    elsif card (1) = card (3) then
    else
        drawbox (100, 50, 200, 150, black)
        Font.Draw (intstr (card (1)), 130, 70, font, black)
        exit
    end if
end loop

and so on...


As you can see that'll take forever to do.

Is there any way I can get it so that you cannot get 2 of the same card, that is relatary short?
Sponsor
Sponsor
Sponsor
sponsor
SuperGenius




PostPosted: Mon Jun 14, 2004 6:40 pm   Post subject: (No subject)

you do need suits in poker... because a flush and a straight flush have different values, yet the numbers on the cards could be the same.
poomanchunk




PostPosted: Mon Jun 14, 2004 10:27 pm   Post subject: (No subject)

Umm... ya. ?
That didn't help me at all
I was asking how I could make it so I wouldn't get two of the same cards.
I knew I had to make suits, with different numbers. If I didn't I wouldn't asked that!
zylum




PostPosted: Mon Jun 14, 2004 10:54 pm   Post subject: (No subject)

here's a deck generator i mind a while ago... it generates the deck with initDeck and then shuffles it with shuffleDeck...

code:
type cards :
    record
        number : string
        suit : string
    end record

var deck : array 1 .. 52 of cards
var suits : array 0 .. 3 of string := init ("CLUBS", "DIAMONDS", "HEARTS", "SPADES")

proc initDeck
    for i : 1 .. 52
        case (i mod 13) of
            label 0 :
                deck (i).number := "ACE"
            label 12 :
                deck (i).number := "KING"
            label 11 :
                deck (i).number := "QUEEN"
            label 10 :
                deck (i).number := "JACK"
            label :
                deck (i).number := intstr (i mod 13 + 1)
        end case
        deck (i).suit := suits ((i - 1) div 13)
    end for
end initDeck

proc shuffleDeck
    var temp : string
    var idx : int
    for i : 1 .. 52
        idx := Rand.Int (1, 52)
        temp := deck (i).number
        deck (i).number := deck (idx).number
        deck (idx).number := temp
        temp := deck (i).suit
        deck (i).suit := deck (idx).suit
        deck (idx).suit := temp
    end for
end shuffleDeck

initDeck
shuffleDeck

for i : 1 .. 52
    put deck (i).number, " ", deck (i).suit
end for


-zylum
SuperGenius




PostPosted: Tue Jun 15, 2004 8:25 am   Post subject: Re: Poker Help

poomanchunk wrote:
Unlike blackjack, I didn't need suits, so it's not bad.


sorry if this threw me off a little.
beard0




PostPosted: Tue Jun 15, 2004 9:46 am   Post subject: Re: Poker Help

I think poomanchunk meant:
Unlike blackjack, where I didn't need suits, so it wasn't so bad, I need suits in poker.
English can be a beautiful thing, when used properly.
TheFerret




PostPosted: Sat Jun 26, 2004 6:44 pm   Post subject: (No subject)

Here is some code to make all cards delt different... This code is from my Euchre game and needs to be modified for poker...

hands is a int array from 8..52, cards in suit are 8..13, 21..26, 34..39, 47..52... For your game you have to use all #s and change temp to 1,52 and the part below does not need to be there...

code:
for ii : 1 .. 4
    for iii : 1 .. 5
        loop
            loop
                temp := Rand.Int (8, 52)
                exit when temp <= 13 or (temp >= 21 and temp <= 26) or (temp >= 34 and temp <= 39) or temp >= 47
            end loop
            if not allCards (temp) %allcads is boolean var for all card from 8..52
                    then
                hands (ii, iii) := temp %what player had which card in which spot
                allCards (temp) := true
                exit
            end if
        end loop
    end for
end for
DanShadow




PostPosted: Mon Jun 28, 2004 1:41 pm   Post subject: (No subject)

Well...in my opion, you should make a record array with the name of every card.
code:

type card:
record
value:int
suite:string
end record
var deck:array 1..52 of card

Then when you draw a card, you could erase it from the deck like this:
code:

var num:int:=0
loop
randint(num,1,52)
exit when deck(num).string not="null"
end loop
put "You drew the ",deck(num).value," of ",deck(num).suite,"."
deck(num).value:=0
deck(num).suite:="null"

Anyway, I hope this helped in some way...
Sponsor
Sponsor
Sponsor
sponsor
blackwhite




PostPosted: Sat Jul 03, 2004 12:35 pm   Post subject: (No subject)

What i did when I made my black jack game (to make sure there's no card picked twice), I used an array for "used cards" and used a for loop to set them all to 0. Then when I was dealling out a card, I put it through a conditional loop and used an if statement to make sure that the card's "used card" value isn't 1. if it is, then redeal, if not then set it to one and continue.

Edit: Don't forget to include the loop to set them all to 0 in the program loop if the program repeats.
zylum




PostPosted: Sun Jul 04, 2004 12:25 am   Post subject: (No subject)

thats not very efficient in card game programs because once you get to the last card you only have a 1 in 52 chance for the card to come up...
cbc




PostPosted: Wed Jul 07, 2004 8:15 pm   Post subject: (No subject)

cudnt u make a 2 layer array representing a deck?

eg:
var deck : array 1 .. 4, 1 .. 13 of int

so 1 .. 4 is for the 4 diff suits.
Delos




PostPosted: Wed Jul 07, 2004 8:22 pm   Post subject: (No subject)

Yes you could, but that wouldn't make checking for the dealtedness of a card easier...
Given, it would make your life easier seeing as you can see your deck a bit easier...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: