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

Username:   Password: 
 RegisterRegister   
 Poker Flush- I know there is a better way to do this
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
berf




PostPosted: Sat Jun 24, 2006 9:20 am   Post subject: Poker Flush- I know there is a better way to do this

I know theres a better way to do this flush likely with arrays but I have a brain cramp and caan't think of how to do it. here is my code:
code:

card_suit := (playershand (s, h) - 7001) div 13     % determines the suit of the card by dividing by 13(leaves 0-3)

            if card_suit = 0 then
                club_count := club_count + 1
            elsif card_suit = 1 then
                spade_count := spade_count + 1
            elsif card_suit = 2 then
                diamond_count := diamond_count + 1
            elsif card_suit = 3 then
                heart_count := heart_count + 1
            end if

Please help me out on this one, and I'm also having trouble trying to figure out how to do straights, any hints on that would be great as well. thanks all
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Jun 24, 2006 11:37 am   Post subject: (No subject)

Have you considered using types for this? It appears that you're using a 2-dim array, which isn't a bad idea, but types might help a little:
code:

type card :
   record
     value : int
     suit : string
   end record

var deck : array 1..52 of card


You would then create an initialization function to iniitialize all of the elements. If you use the 1-dim approach, you'll have to break down the init into 4 areas, one for each suit (read: nested for loops!). You could also opt for a 2-dim array (4x13) which would essentially mean the same thing but a little less maths.
The use of having the 'suit' field means that for a flush, you would only consider that dimension in your analysis. For a straight, you'd only consider the 'value' field. And for a straight flush...!
Good luck.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: