• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Card class straight

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic