Пример #1
0
int
parseStandardRanksSuits(JNIEnv *env, jintArray ranks, jintArray suits,
                        StdDeck_CardMask *mcards, int *ncards)
{
  int i, status = 0;
  jsize nranks = (*env)->GetArrayLength(env, ranks);
  jsize nsuits = (*env)->GetArrayLength(env, suits);
  jint *jranks = (*env)->GetIntArrayElements(env, ranks, 0);
  jint *jsuits = (*env)->GetIntArrayElements(env, suits, 0);

  StdDeck_CardMask_RESET(*mcards);
  *ncards = 0;
  if (nranks != nsuits) {
    status = 1;
    goto release1;
  }
  for (i=0; i<nranks; i++) {
    int card = StdDeck_MAKE_CARD(jranks[i], jsuits[i]);
    if (StdDeck_CardMask_CARD_IS_SET(*mcards, card)) {
      status = 1;
      goto release1;
    }
    StdDeck_CardMask_SET(*mcards, card);
    (*ncards)++;
  }
#ifdef DEBUG
  printf("In C: Hand %s\n", DmaskString(StdDeck, *mcards));
#endif

 release1:
  (*env)->ReleaseIntArrayElements(env, ranks, jranks, JNI_ABORT);
  (*env)->ReleaseIntArrayElements(env, suits, jsuits, JNI_ABORT);
  return status;
}
Пример #2
0
int main() {
  StdDeck_CardMask set_var[2];
  int num_sets = 2;
  int set_sizes[2] = {2, 1};
  StdDeck_CardMask dead_cards;
  int i;
  
  StdDeck_CardMask_RESET(dead_cards);
  for (i=0; i<39; i++) /* remove three suits to reduce output */
    StdDeck_CardMask_SET(dead_cards, i);
  DECK_ENUMERATE_COMBINATIONS_D(StdDeck, set_var, num_sets,
                                set_sizes, dead_cards,
  { 
    for (i=0; i<num_sets; i++) { 
      printf("%s | ", DmaskString(StdDeck, set_var[i])); 
    } 
    printf("\n"); 
  } 
    );
Пример #3
0
int
parseJokerRanksSuits(JNIEnv *env, jintArray ranks, jintArray suits,
                     JokerDeck_CardMask *mcards, int *ncards)
{
  int i, status = 0;
  jsize nranks = (*env)->GetArrayLength(env, ranks);
  jsize nsuits = (*env)->GetArrayLength(env, suits);
  jint *jranks = (*env)->GetIntArrayElements(env, ranks, 0);
  jint *jsuits = (*env)->GetIntArrayElements(env, suits, 0);

  JokerDeck_CardMask_RESET(*mcards);
  *ncards = 0;
  if (nranks != nsuits) {
    status = 1;
    goto release2;
  }
  for (i=0; i<nranks; i++) {
    int card;
    if (jranks[i] == JokerDeck_Rank_LAST + 1) {
      /* encode joker as any card with rank one higher than highest; this
         corresponds to rank 13 */
      card = JokerDeck_JOKER;
    } else {
      card = JokerDeck_MAKE_CARD(jranks[i], jsuits[i]);
    }
    if (JokerDeck_CardMask_CARD_IS_SET(*mcards, card)) {
      status = 1;
      goto release2;
    }
    JokerDeck_CardMask_SET(*mcards, card);
    (*ncards)++;
  }
#ifdef DEBUG
  printf("In C: Hand %s\n", DmaskString(JokerDeck, *mcards));
#endif

 release2:
  (*env)->ReleaseIntArrayElements(env, ranks, jranks, JNI_ABORT);
  (*env)->ReleaseIntArrayElements(env, suits, jsuits, JNI_ABORT);
  return status;
}
Пример #4
0
void
enumResultPrint(enum_result_t *result, StdDeck_CardMask pockets[],
                StdDeck_CardMask board) {
  int i;
  enum_gameparams_t *gp;
  int width;

  gp = enumGameParams(result->game);
  if (gp == NULL) {
    printf("enumResultPrint: invalid game type\n");
    return;
  }
  width = gp->maxpocket * 3 - 1;
  printf("%s: %d %s %s%s", gp->name, result->nsamples,
         (result->sampleType == ENUM_SAMPLE) ? "sampled" : "enumerated",
         (gp->maxboard > 0) ? "board" : "outcome",
         (result->nsamples == 1 ? "" : "s"));
  if (!StdDeck_CardMask_IS_EMPTY(board))
    printf(" containing %s", DmaskString(StdDeck, board));
  printf("\n");

  if (gp->haslopot && gp->hashipot) {
    printf("%*s %7s   %7s %7s %7s   %7s %7s %7s   %5s\n",
           -width, "cards", "scoop",
           "HIwin", "HIlos", "HItie",
           "LOwin", "LOlos", "LOtie",
           "EV");
    for (i=0; i<(int)(result->nplayers); i++) {
      printf("%*s %7d   %7d %7d %7d   %7d %7d %7d   %5.3f\n",
             -width, DmaskString(StdDeck, pockets[i]), result->nscoop[i],
             result->nwinhi[i], result->nlosehi[i], result->ntiehi[i],
             result->nwinlo[i], result->nloselo[i], result->ntielo[i],
             result->ev[i] / result->nsamples);
    }
#if 0
    {
    int j;
    /* experimental output format to show pot splitting */
    printf("\n%*s", -width, "cards");
    for (j=0; j<=result->nplayers; j++)
      printf(" %6s%d", "HI", j);
    for (j=0; j<=result->nplayers; j++)
      printf(" %6s%d", "LO", j);
    printf("\n");
    for (i=0; i<result->nplayers; i++) {
      printf("%*s", -width, DmaskString(StdDeck, pockets[i]));
      for (j=0; j<=result->nplayers; j++)
        printf(" %7d", result->nsharehi[i][j]);
      for (j=0; j<=result->nplayers; j++)
        printf(" %7d", result->nsharelo[i][j]);
      printf("\n");
    }
    }
#endif
    
  } else {
    printf("%*s %7s %6s   %7s %6s   %7s %6s     %5s\n",
           -width, "cards", "win", "%win", "lose", "%lose", "tie", "%tie", "EV");
    if (gp->haslopot) {
      for (i=0; i<(int)(result->nplayers); i++) {
        printf("%*s %7d %6.2f   %7d %6.2f   %7d %6.2f     %5.3f\n",
               -width, DmaskString(StdDeck, pockets[i]),
               result->nwinlo[i], 100.0 * result->nwinlo[i] / result->nsamples,
               result->nloselo[i], 100.0 * result->nloselo[i] / result->nsamples,
               result->ntielo[i], 100.0 * result->ntielo[i] / result->nsamples,
               result->ev[i] / result->nsamples);
      }
    } else if (gp->hashipot) {
      for (i=0; i<(int)(result->nplayers); i++) {
        printf("%*s %7d %6.2f   %7d %6.2f   %7d %6.2f     %5.3f\n",
               -width, DmaskString(StdDeck, pockets[i]),
               result->nwinhi[i], 100.0 * result->nwinhi[i] / result->nsamples,
               result->nlosehi[i], 100.0 * result->nlosehi[i] / result->nsamples,
               result->ntiehi[i], 100.0 * result->ntiehi[i] / result->nsamples,
               result->ev[i] / result->nsamples);
      }
    }
  }

  if (result->ordering != NULL)
    enumResultPrintOrdering(result, 0);
}