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

Username:   Password: 
 RegisterRegister   
 Question Regarding a Card Combinations Program
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
_Dan_




PostPosted: Sun Jan 13, 2008 6:02 pm   Post subject: Re: Question Regarding a Card Combinations Program

Damnit, I remember why I needed the flush to go through all possible combinations. I need to also check whether a 4 card hand is both a flush AND a straight/all prime, I also need to check whether a hand is a fractor (all cards in the hand are factors of the largest) AND all prime.

Do I have to do the following now?:

1. Make an isStraightFlush method
-Make a custom sorting method that sorts the 4 card hands by numerical value, but also changes the location of the suits int the array as well
-Sort the hand using the custom sort, check if there are 4 consecutive values and 4 consecutive suits in every possible 4 card combination

2. Make an is flushPrime method
-Goes through every possible 4 card hand, checks to see if all of the suits are the same, and all of the values are prime

3. Fractor prime
-Goes through every possible 4 card hand, checks to see if the values all divide into the highest AND are prime

Or is there a better/easier way of doing this :S (the above will take quite a while...).
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Sun Jan 13, 2008 6:55 pm   Post subject: Re: Question Regarding a Card Combinations Program

_Dan_ @ Sun Jan 13, 2008 6:02 pm wrote:
2. Make an is flushPrime method
-Goes through every possible 4 card hand, checks to see if all of the suits are the same, and all of the values are prime
I'll focus on this one as an example. You can use the counter method that was used with plain flushes but only increment when the value is prime. Try to see if thinking differently about the problem helps.

Also:
Quote:
Goes through every possible 4 card hand, checks to see if the values all divide into the highest AND are prime
...isn't that just 0?
_Dan_




PostPosted: Sun Jan 13, 2008 7:13 pm   Post subject: Re: Question Regarding a Card Combinations Program

Quote:
...isn't that just 0?

Quadruple Primes Smile. 2,2,2,2 all divide into the highest value, 2, and are all prime :p. Though I could just check if all the values are identical, and that the first value is prime, this method is easy to create.

Quote:
I'll focus on this one as an example. You can use the counter method that was used with plain flushes but only increment when the value is prime. Try to see if thinking differently about the problem helps.

Good idea XD, ok finished this part.

So now all I need is the Straight Flush checking method.
OneOffDriveByPoster




PostPosted: Sun Jan 13, 2008 7:34 pm   Post subject: Re: Question Regarding a Card Combinations Program

_Dan_ @ Sun Jan 13, 2008 7:13 pm wrote:
So now all I need is the Straight Flush checking method.
You don't need to go through all 4-hands with this one either.
_Dan_




PostPosted: Sun Jan 13, 2008 8:27 pm   Post subject: Re: Question Regarding a Card Combinations Program

Do I HAVE to make a custom sort -.-.
_Dan_




PostPosted: Sun Jan 13, 2008 11:59 pm   Post subject: Re: Question Regarding a Card Combinations Program

The program says there are no straight flushes, what's wrong with my method :S?

Java:
public static boolean straightFlushC (int fCard, int sCard, int tCard, int foCard,
            int fiCard, int siCard, int fCardV, int sCardV, int tCardV, int foCardV,
            int fiCardV, int siCardV)
    {
        int suits[] = {fCard, sCard, tCard, foCard, fiCard, siCard};
        int values[] = {fCardV, sCardV, tCardV, foCardV, fiCardV, siCardV};

        for (int numberCounter = 0 ; numberCounter < 5 ; numberCounter++)
        {
            int indexOfSmallest = numberCounter;
            for (int indexCounter = numberCounter ; indexCounter < 6 ; indexCounter++)
            {
                if (values [indexCounter] < values [indexOfSmallest])
                {
                    indexOfSmallest = indexCounter;
                }
            }

            if (indexOfSmallest != numberCounter)
            {
                int tempValue = values [numberCounter];
                int tempSuit = suits [numberCounter];
                values [numberCounter] = values [indexOfSmallest];
                suits [numberCounter] = suits [indexOfSmallest];
                values [indexOfSmallest] = tempValue;
                suits [indexOfSmallest] = tempSuit;
            }
        }
        for (int hand = 0 ; hand < 3 ; hand++)
        {
            if ((suits [hand] == suits [hand + 1] && suits [hand] == suits [hand + 2] && suits [hand] == suits [hand + 3]) && (values [hand] == values [hand + 1] - 1 && values [hand] == values [hand + 2] - 2 && values [hand] == values [hand + 3] - 3))
                return true;
        }
        return false;
    }
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 36 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: