I see Whiz beat me to it. Here is my version.
//Returns the rank of the highest card in the striaght, or 0 for no straight.
int ReturnIsStraight(object oCard1, object oCard2, object oCard3, object oCard4, object oCard5)
{
int iStraight;
// These return the cards ranking 1 = ace 2 =2 etc.. 13 = king
//int iCard1 = ReturnCardNumber(oCard1);
//int iCard2 = ReturnCardNumber(oCard2);
//int iCard3 = ReturnCardNumber(oCard3);
//int iCard4 = ReturnCardNumber(oCard4);
//int iCard5 = ReturnCardNumber(oCard5);
// Mak a map of the cards. ace in Bit 1, 2 in bit 2, ect..
int mCardMap = 1<<ReturnCardNumber(oCard1);
mCardMap |= 1<<ReturnCardNumber(oCard2);
mCardMap |= 1<<ReturnCardNumber(oCard3);
mCardMap |= 1<<ReturnCardNumber(oCard4);
mCardMap |= 1<<ReturnCardNumber(oCard5);
// This just get the rank of the low card in the set.
int nLowCardRank = -mCardMap & mCardMap;
nLowCardRank = FloatToInt( log(nLowCardRank*1.0)/log(2.0));
// Shift the map down so that the low card in in the 0 bit position.
int mShiftedMap = mCardMap>>nLowCardRank;
// and check agains the two patterns that will be a straight.
// The two patterns are first 5 bits set(31) and Bits 0 and bit 9 -12 set(7681)
//check for an ace high Straight first. If it is return 1 meaning that it is
// a stright to an ace.
if (mShiftedMap == 7681 ) iStraight = 1;
//Now check for all the other straights, return the rank of the hightest card.
else if (mShiftedMap == 31) iStraight = FloatToInt( log(mCardMap*1.0)/log(2.0));
//Returns the rank of the highest card in the stright, or 0 for no straight.
return iStraight;
}
EDIT: corrected my number for the check of the ace high straight.
Modifié par Lightfoot8, 25 octobre 2012 - 06:05 .