aspose file tools*
The moose likes Beginning Java and the fly likes Card class straight Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Card class straight" Watch "Card class straight" New topic
Author

Card class straight

Joe Wilkes
Greenhorn

Joined: Oct 29, 2005
Posts: 7
Hey guys, maybe someone can help me, I am working on a problem for class and it is from the Deitel java book. Chapter 7 problem 31, It has to do with calling a straight function. I have it calling the full house, pair, two pair, and flush. How do I see if there is striaght? My cards are strings numbered Ace, Duece, Three... Not ints 1, 2, 3... So how can I determine if Duece+1 == Three? Can anyone help me out on this???
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

I don't have that book so I can't speak to the specifics of your problem although I once wrote a program that did poker calculations from scratch. I would suggest creating a Card Class (if you don't have one all ready). Then you can add a property to the class such as card.getNumericValue().

For a straight, you just take the card with the lowest numeric value (cost of O(n) to find min card) then determine if remaining cards have values x+1, x+2, x+3 etc (Cost of O(5*n) total where n is 5 for 5-card poker, so very fast technique). You do need to put some special logic in their for aces but the case of aces happens so rarely that its not a difficult specific case to write. Probably could be handled with one if statement such as, if the lowest card value is 2, check if there exists an ACE (with value 14) then reset that as the lowest card and look for 2 though 5.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Card class straight
 
Similar Threads
TYPE THREE DRIVERS
packages and compailation
Getting rid of unchecked operations related to Vector class
retrieve other class method
can I pass a parameter to run method in java