View Single Post
Old 03-23-2005, 12:03 PM   #7 (permalink)
zen_tom
Guest
 
I've just gone away and had a think about this, and think that using a bitmask is genius!
so each card value is assigned a bit i.e.
Code:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][1] = Ace
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][1][ ] = Duece
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][1][ ][ ] = 3
[ ][ ][ ][ ][ ][ ][ ][ ][ ][1][ ][ ][ ] = 4
[ ][ ][ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ] = 5
[ ][ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ] = 6
[ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ] = 7
[ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ] = 8
[ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ] = 9
[ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ][ ] = 10
[ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] = Jack
[ ][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] = Queen
[1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] = King

Then, all the cards in a hand are ORed into a hand array

[ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ] = 7
[ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ] = 8
[ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ] = 9
[ ][ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ][ ] = 10
[ ][ ][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] = Jack

[ ][ ][1][1][1][1][1][ ][ ][ ][ ][ ][ ] = All Cards

Now by finding the first 1 and the last one, and filling in the gaps, I should be able to make a mask.

[ ][ ][1][1][1][1][1][ ][ ][ ][ ][ ][ ] = Mask

Now if I XOR the mask and the card array, I should always get zero if there is a straight, or something else if not.
It also solves the roaming Ace problem too.
 
 

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