Author Topic: Getting a straight , straight  (Read 309 times)

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Getting a straight , straight
« on: October 25, 2012, 05:25:15 am »


               Ok you prob. seen my poker Custom content. I been working all the custom functions for the hands and have all of them except the straight. I think I just have a little burn out after getting all the other functions in. I'm very thankful for any assistants.  I have other functions related to the cards if you need one let me know.

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);

//Returns the highest card from cards , if Ace it will return as the highest.
int iHigh = ReturnHighCard(oCard1,oCard2,oCard3,oCard4,oCard5);







return iStraight;
}
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting a straight , straight
« Reply #1 on: October 25, 2012, 06:02:32 am »


               

int ReturnIsStraight(object oCard1, object oCard2, object oCard3, object oCard4, object oCard5)
{
// 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);

int iSum = iCard1 + iCard2 + iCard3 + iCard4 + iCard5;
//Insert High Ace possibility here (see below)
int iAve = iSum/5;
int nDiff1 = 2;
int nDiff2 = 2;
if(iAve * 5 - iSum) return FALSE;
switch(abs(iCard1 - iAve))
  {
  case 0: break;
  case 1: nDiff1 -= 1; break;
  case 2: nDiff2 -= 1; break;
  return FALSE;
  }
switch(abs(iCard2 - iAve))
  {
  case 0: break;
  case 1: nDiff1 -= 1; break;
  case 2: nDiff2 -= 1; break;
  return FALSE;
  }
switch(abs(iCard3 - iAve))
  {
  case 0: break;
  case 1: nDiff1 -= 1; break;
  case 2: nDiff2 -= 1; break;
  return FALSE;
  }
switch(abs(iCard4 - iAve))
  {
  case 0: break;
  case 1: nDiff1 -= 1; break;
  case 2: nDiff2 -= 1; break;
  return FALSE;
  }
switch(abs(iCard5 - iAve))
  {
  case 0: break;
  case 1: nDiff1 -= 1; break;
  case 2: nDiff2 -= 1; break;
  return FALSE;
  }
return !(nDiff1 || nDiff2);
}

Edit: simplified ending

Edit2: Here is a section to insert if AKQJ10  is considered a straight.

if(iSum == 47)
{
iCard1 = 5 + abs(iCard1 -5);
iCard2 = 5 + abs(iCard2 -5);
iCard3 = 5 + abs(iCard3 -5);
iCard4 = 5 + abs(iCard4 -5);
iCard5 = 5 + abs(iCard5 -5);
iSum = iCard1 + iCard2 + iCard3 + iCard4 + iCard5;
}
               
               

               


                     Modifié par WhiZard, 25 octobre 2012 - 06:08 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting a straight , straight
« Reply #2 on: October 25, 2012, 06:55:38 am »


               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 .
                     
                  


            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Getting a straight , straight
« Reply #3 on: October 25, 2012, 11:38:54 pm »


               Thanks you two, much smother scripts. LOL *do not look at mine*. Yes high ace is part of it. LOL sorry went to bed after posting. So does this also account for low ace straight?  5â™  4♦ 3♦ 2â™  A♥
[/b]
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting a straight , straight
« Reply #4 on: October 26, 2012, 03:47:41 pm »


               Mine should cover all of the strights.     It basicly maps all of the cards to a bit, Then shifts the bits down to where the lowest card will be in bit 0.   So the check of the shifted map against 31 will catch all of the strights except the ace high straight, Since the ace is maped in as low.   The Check against  7681 will catch the ace High straight,, Given the presence of the ace would have the map shifted only by one position.

If you need a better explaination of anything just let me know.  

I also do see some draw backs to the system as it sits.   That being that it does not allow easy expansion of the functions into a 7 card games -like 7card stud - tx holdem - omaha   ect