View Single Post
Old 03-24-2005, 09:40 AM   #11 (permalink)
zen_tom
Guest
 
OK, I've got it to work and put in an acesHiLow variable (-1 for low, 0 for either or 1 for high) and this should work as a test to see if all the cards in a given hand are in a run.

Where aces are high or low, the thing only works for 5-card hands, but hopefully I'll work out a way to fix it so it will work for any number of cards.

Code:
public boolean isStrait(int acesHiLow){
		boolean isstrait = false;
		int maskval = 1;
		int val = 0;
		int lowest = Integer.MAX_VALUE;
		for (int i = 0; i< myHand.size();i++) {
			if (acesHiLow == -1 || myHand.card(i).value != 1){
			val = val | (1 << myHand.card(i).value);
			maskval = maskval << 1;
			lowest = Math.min(myHand.card(i).value, lowest);}
			if (acesHiLow == 0 && myHand.card(i).value == 1){
				val = val | (1 << myHand.card(i).value);
				val = val | (1 << 14);
				maskval = maskval << 1;
				maskval = maskval << 1;
				lowest = Math.min(myHand.card(i).value, lowest);}
			if (acesHiLow == 1 && myHand.card(i).value == 1){
				val = val | (1 << 14);
				maskval = maskval << 1;
				lowest = Math.min(14, lowest);}			
			}
		val = val >> lowest;

		if (val + 1 == maskval){return true;}
		if ((acesHiLow == 0 && val == 8223) || (acesHiLow == 0 && val == 15873)){return true;}
		// System.out.println(val + " " + maskval );
		return false;
	}
Thanks again.
 
 

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