View Single Post
Old 03-23-2005, 10:30 AM   #1 (permalink)
zen_tom
Guest
 
[java] Contiguous Array Test

I'm writing a client-server poker-tournament game (which I later want to extend to playing other games) and have started on the part where the system analyses the hand a given player has.

I have a jCard object that represents a card. A player's hand is represented by a jHand object that contains a Stack, which contains a set of jCards.

jCard properties are:
String suit; (Text version of suit, i.e. "Clubs", "Diamonds" etc)
String code; (2 char code 1st Char = suit, 2nd char = value - i.e. HK = King of Hearts)
int value; 1-13 (Aces through Kings)

So, I've another object called a jHandAnalyser that has a number of methods for checking what a hand might be worth. The main property of this object is a jHand reference called myHand.

Calling the constructor of jHandAnalyser passes in the hand you want to analyse. e.g.

jHandAnalyser aPlayer = new jHandAnalyser(aHand);

This jHandAnalyser needs to look at the jHand object it's given and decide what the hand is worth.

So far I have a method called isFlush() that returns true if the cards are all of the same suit, but am wondering how to implement the isStrait (sp?) method. i.e. I want to check that all the cards are in a sequential run. Has anyone got any ideas how I can do this nice and cleanly?
 
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76