int main( void )
{
    CardMask cards;
    HandVal handval1, handval2;
    EvxHandVal evxHandVal;

    ENUMERATE_5_CARDS(cards,
    {
        handval1 = Hand_EVAL_N(cards, 5);
        evxHandVal = Hand_EVAL_X5(CardMask_CLUBS(cards),
        CardMask_DIAMONDS(cards),
        CardMask_HEARTS(cards),
        CardMask_SPADES(cards));
        handval2 = EvxHandVal_toHandVal(evxHandVal);
        if (handval1 != handval2)
        {
            fprintf(stderr, "eval_n() and eval_x5() disagree\n");
            printf("0\n");
            Deck_printMask(cards);
            printf(": ");
            HandVal_print(handval1);
            printf(", ");
            HandVal_print(handval2);
            printf("\n");
            exit(0);
        }

        printf("%d %d %d %d %d %d\n",
        HandVal_HANDTYPE(handval1),
        HandVal_TOP_CARD(handval1),
        HandVal_SECOND_CARD(handval1),
        HandVal_THIRD_CARD(handval1),
        HandVal_FOURTH_CARD(handval1),
        HandVal_FIFTH_CARD(handval1));
    });
Exemple #2
0
int 
LowHandVal_toString(LowHandVal hv, char *outString) {
  char *p = outString;
  int htype = HandVal_HANDTYPE(hv);

  if (hv == LowHandVal_NOTHING) 
    p += sprintf(outString, "NoLow");
  else {
    p += sprintf(outString, "%s (", StdRules_handTypeNames[htype]);
    if (StdRules_nSigCards[htype] >= 1) 
      p += sprintf(p, "%c", 
                   StdDeck_rankChars[CARD_TO_RANK(HandVal_TOP_CARD(hv))]);
    if (StdRules_nSigCards[htype] >= 2) 
      p += sprintf(p, " %c", 
                   StdDeck_rankChars[CARD_TO_RANK(HandVal_SECOND_CARD(hv))]);
    if (StdRules_nSigCards[htype] >= 3) 
      p += sprintf(p, " %c", 
                   StdDeck_rankChars[CARD_TO_RANK(HandVal_THIRD_CARD(hv))]);
    if (StdRules_nSigCards[htype] >= 4) 
      p += sprintf(p, " %c", 
                   StdDeck_rankChars[CARD_TO_RANK(HandVal_FOURTH_CARD(hv))]);
    if (StdRules_nSigCards[htype] >= 5) 
      p += sprintf(p, " %c", 
                   StdDeck_rankChars[CARD_TO_RANK(HandVal_FIFTH_CARD(hv))]);
    p += sprintf(p, ")");
  };

  return p - outString;
}
Exemple #3
0
int 
AStudRules_HandVal_toString(HandVal handval, char *outString) {
  char *p = outString;
  int htype = HandVal_HANDTYPE(handval);

  p += sprintf(outString, "%s (", AStudRules_handTypeNames[htype]);
  if (AStudRules_nSigCards[htype] >= 1) 
    p += sprintf(p, "%c", 
                 AStudDeck_rankChars[HandVal_TOP_CARD(handval)]);
  if (AStudRules_nSigCards[htype] >= 2) 
    p += sprintf(p, " %c", 
                 AStudDeck_rankChars[HandVal_SECOND_CARD(handval)]);
  if (AStudRules_nSigCards[htype] >= 3) 
    p += sprintf(p, " %c", 
                 AStudDeck_rankChars[HandVal_THIRD_CARD(handval)]);
  if (AStudRules_nSigCards[htype] >= 4) 
    p += sprintf(p, " %c", 
                 AStudDeck_rankChars[HandVal_FOURTH_CARD(handval)]);
  if (AStudRules_nSigCards[htype] >= 5) 
    p += sprintf(p, " %c", 
                 AStudDeck_rankChars[HandVal_FIFTH_CARD(handval)]);
  p += sprintf(p, ")");

  return p - outString;
}
Exemple #4
0
int main( void )
{
  CardMask cards, cards1, peggedCards;
  HandVal handval1, handval2;
  EvxHandVal evxHandVal;

  StdDeck_CardMask_RESET(peggedCards);
  StdDeck_CardMask_SET(peggedCards, 
                       StdDeck_MAKE_CARD(StdDeck_Rank_ACE, 
                                         StdDeck_Suit_DIAMONDS));
  StdDeck_CardMask_SET(peggedCards, 
                       StdDeck_MAKE_CARD(StdDeck_Rank_ACE, 
                                         StdDeck_Suit_HEARTS));
  ENUMERATE_5_CARDS_D(cards, peggedCards, 
                    {
                      StdDeck_CardMask_OR(cards1, cards, peggedCards);
                      handval1 = Hand_EVAL_N(cards1, 7);
                      evxHandVal = Hand_EVAL_X7(CardMask_CLUBS(cards1), 
                                                CardMask_DIAMONDS(cards1),
                                                CardMask_HEARTS(cards1),
                                                CardMask_SPADES(cards1));
                      handval2 = EvxHandVal_toHandVal(evxHandVal);
                      if (handval1 != handval2)
                        {
                          fprintf(stderr, "eval_n() and eval_x7() disagree\n");
                          printf("0\n");
                          Deck_printMask(cards);                        
                          printf(": ");                                 
                          HandVal_print(handval1);                  
                          printf(", ");
                          HandVal_print(handval2);                  
                          printf("\n");                                 
                          exit(0);
                        }
		      printf("%d %d %d %d %d %d\n", 
			     HandVal_HANDTYPE(handval1),
			     HandVal_TOP_CARD(handval1),
			     HandVal_SECOND_CARD(handval1),
			     HandVal_THIRD_CARD(handval1),
			     HandVal_FOURTH_CARD(handval1),
			     HandVal_FIFTH_CARD(handval1));
                    });
Exemple #5
0
int main( void )
{
  CardMask cards;
  HandVal handval1, handval2;
  EvxHandVal evxHandVal;
  Md5Context ctx;
  Md5RawDigest raw;
  Md5CodedDigest coded;
  unsigned char hashvals[6];

  ctx = MD5Begin();
  ENUMERATE_5_CARDS(cards, 
                    {
                      handval1 = Hand_EVAL_N(cards, 5);
                      evxHandVal = Hand_EVAL_X5(CardMask_CLUBS(cards), 
                                                CardMask_DIAMONDS(cards),
                                                CardMask_HEARTS(cards),
                                                CardMask_SPADES(cards));
                      handval2 = EvxHandVal_toHandVal(evxHandVal);
                      if (handval1 != handval2)
                        {
                          fprintf(stderr, "eval_n() and eval_x5() disagree\n");
                          printf("0\n");
                          Deck_printMask(cards);                        
                          printf(": ");                                 
                          HandVal_print(handval1);                  
                          printf(", ");
                          HandVal_print(handval2);                  
                          printf("\n");                                 
                          exit(0);
                        }
                      
                      hashvals[0] = HandVal_HANDTYPE(handval1);
                      hashvals[1] = HandVal_TOP_CARD(handval1);
                      hashvals[2] = HandVal_SECOND_CARD(handval1);
                      hashvals[3] = HandVal_THIRD_CARD(handval1);
                      hashvals[4] = HandVal_FOURTH_CARD(handval1);
                      hashvals[5] = HandVal_FIFTH_CARD(handval1);
                      MD5DigestBytes(ctx, hashvals, 6);
                    });
static PyObject*
CardMask2SortedPyList(CardMask hand, int low)
{
  int i;
  HandVal handval;
  PyObject* result = PyList_New(0);

  if(StdDeck_CardMask_IS_EMPTY(hand)) {
    PyObject* pyvalue = Py_BuildValue("s", "Nothing");
    PyList_Append(result, pyvalue);
    Py_DECREF(pyvalue);
    return result;
  }

  if(low) {
    handval = Hand_EVAL_LOW8(hand, 5);
  } else {
    handval = Hand_EVAL_N(hand, 5);
  }

  int htype = HandVal_HANDTYPE(handval);
  {
    PyObject* pyvalue = Py_BuildValue("s", StdRules_handTypeNames[htype]);
    PyList_Append(result, pyvalue);
    Py_DECREF(pyvalue);
  }

  if(!low || htype != LowHandVal_NOTHING) {
    if (StdRules_nSigCards[htype] >= 1) {
      int rank = HandVal_TOP_CARD(handval);
      if(low) rank = LOWRANK2RANK(rank);

      if(htype == HandType_STRAIGHT || htype == HandType_STFLUSH) {
	for(i = rank; rank - i < 5; i--) {
	  int rank_modulo = i < 0 ? StdDeck_Rank_ACE : i;
	  PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank_modulo));
	  PyList_Append(result, pyvalue);
	  Py_DECREF(pyvalue);
	}
      } else {
	int count;
	switch(htype) {
	case HandType_ONEPAIR:
	case HandType_TWOPAIR:
	  count = 2;
	  break;
	case HandType_TRIPS:
	case HandType_FULLHOUSE:
	  count = 3;
	  break;
	case HandType_QUADS:
	  count = 4;
	  break;
	default:
	  count = 1;
	  break;
	}
	for(i = 0; i < count; i++) {
	  PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank));
	  PyList_Append(result, pyvalue);
	  Py_DECREF(pyvalue);
	}
      }
    }
    if (StdRules_nSigCards[htype] >= 2) {
      int rank = HandVal_SECOND_CARD(handval);
      int count = 1;
      if(low) rank = LOWRANK2RANK(rank);
      if(htype == HandType_TWOPAIR ||
	 htype == HandType_FULLHOUSE)
	count = 2;

      for(i = 0; i < count; i++) {
	PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank));
	PyList_Append(result, pyvalue);
	Py_DECREF(pyvalue);
      }
    }

    if (StdRules_nSigCards[htype] >= 3) {
      int rank = HandVal_THIRD_CARD(handval);
      if(low) rank = LOWRANK2RANK(rank);
      PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank));
      PyList_Append(result, pyvalue);
      Py_DECREF(pyvalue);
    }

    if (StdRules_nSigCards[htype] >= 4) {
      int rank = HandVal_FOURTH_CARD(handval);
      if(low) rank = LOWRANK2RANK(rank);
      PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank));
      PyList_Append(result, pyvalue);
      Py_DECREF(pyvalue);
    }

    if (StdRules_nSigCards[htype] >= 5) {
      int rank = HandVal_FIFTH_CARD(handval);
      if(low) rank = LOWRANK2RANK(rank);
      PyObject* pyvalue = Py_BuildValue("i", findanddelete(&hand, rank));
      PyList_Append(result, pyvalue);
      Py_DECREF(pyvalue);
    }

  }

  /*
   * Append remaining cards, highest first
   */
  for(i = Deck_N_CARDS - 1; i >= 0; i--) {
    if (StdDeck_CardMask_CARD_IS_SET(hand, i)) {
      PyObject* pyvalue = Py_BuildValue("i", i);
      PyList_Append(result, pyvalue);
      Py_DECREF(pyvalue);
    }
  }

  return result;
}