Example #1
0
int 
main(int argc, char **argv) {
  enum_game_t game;
  enum_sample_t enumType;
  int niter, npockets, nboard, err, terse;
  StdDeck_CardMask pockets[ENUM_MAXPLAYERS];
  StdDeck_CardMask board;
  StdDeck_CardMask dead;
  enum_result_t result;

  if (parseArgs(argc, argv, &game, &enumType, &niter,
                pockets, &board, &dead, &npockets, &nboard, &terse)) {
    printf("usage: %s [-t] [-mc niter]\n", argv[0]);
    printf("\t[-h|-h8|-o|-o8|-7s|-7s8|-7snsq|-r|-5d|-5d8|-5dnsq|-l|-l27]\n");
    printf("\t<pocket1> - <pocket2> - ... [ -- <board> ] [ / <dead> ] ]\n");
    return 1;
  }
  if (enumType == ENUM_EXHAUSTIVE) {
    err = enumExhaustive(game, pockets, board, dead, npockets, nboard,
                         &result);
  } else if (enumType == ENUM_SAMPLE) {
    err = enumSample(game, pockets, board, dead, npockets, nboard, niter,
                     &result);
  } else
    err = 1;
  if (err) {
    printf("enumeration function failed err=%d\n", err);
    return 1;
  }
  if (terse)
    enumResultPrintTerse(&result, pockets, board);
  else
    enumResultPrint(&result, pockets, board);
  return 0;
}
Example #2
0
int 
main(int argc, char **argv) {
  enum_game_t game;
  enum_sample_t enumType;
  int niter = 0, npockets, nboard, err, terse, orderflag;
  StdDeck_CardMask pockets[ENUM_MAXPLAYERS];
  StdDeck_CardMask board;
  StdDeck_CardMask dead;
  enum_result_t result;
  int fromStdin;

  fromStdin = (argc == 2 && !strcmp(argv[1], "-i"));
  if (fromStdin)
    argv = (char **) malloc(MAX_ARGS * sizeof(char *));
  do {
    err = 0;
    enumResultClear(&result);
    if (fromStdin) {	/* read one line from stdin, split into argv/argc */
      char buf[BUF_LEN], *p;
      if (fgets(buf, sizeof(buf), stdin) == NULL)
        break;
      argc = 0;
      argv[argc++] = "pokenum";
      p = strtok(buf, " \t\r\n");
      while (p != NULL) {
        argv[argc++] = p;
        p = strtok(NULL, " \t\r\n");
      }
    }
    if (parseArgs(argc, argv, &game, &enumType, &niter,
                  pockets, &board, &dead, &npockets, &nboard,
                  &orderflag, &terse)) {
      if (fromStdin) {
        printf("ERROR\n");
      } else {
        printf("single usage: %s [-t] [-O] [-mc niter]\n", argv[0]);
        printf("\t[-h|-h8|-o|-o8|-7s|-7s8|-7snsq|-r|-5d|-5d8|-5dnsq|-l|-l27]\n");
        printf("\t<pocket1> - <pocket2> - ... [ -- <board> ] [ / <dead> ] ]\n");
        printf("streaming usage: %s -i < argsfile\n", argv[0]);
      }
      err = 1;
    } else {
      if (enumType == ENUM_EXHAUSTIVE) {
        err = enumExhaustive(game, pockets, board, dead, npockets, nboard,
                             orderflag, &result);
      } else if (enumType == ENUM_SAMPLE) {
        err = enumSample(game, pockets, board, dead, npockets, nboard, niter,
                         orderflag, &result);
      } else {
        err = 1;
      }
      if (err) {
        if (fromStdin)
          printf("ERROR\n");
        else
          printf("enumeration function failed err=%d\n", err);
      } else {
        if (terse)
          enumResultPrintTerse(&result, pockets, board);
        else
          enumResultPrint(&result, pockets, board);
      }
    }
    enumResultFree(&result);
    fflush(stdout);
  } while (fromStdin);
  return err;
}
Example #3
0
int main(int argc, char* argv[]) {
  enum_game_t game = game_razz;
  {
    enum_result_t result;
    StdDeck_CardMask board;
    StdDeck_CardMask dead;
    StdDeck_CardMask pockets[2];
    char* hand0[] = { "Ad", "2d", "3d", "4d", "5d", "Tc", "Th" };
    //char* hand1[] = { "Ac", "2c", "3c", "4c", "5c", "Tc", "Th" };
    char* hand1[] = { "4d", "4c", "8d", "8c", "9d", "9c", "9h" };

    enumResultClear(&result);
    CardMask_RESET(board);
    CardMask_RESET(dead);
    pockets[0] = Strings2CardMask(7, hand0);
    pockets[1] = Strings2CardMask(7, hand1);

    assert(enumExhaustive(game, pockets, board, dead, 2, 0 /* nboard */,
                          0 /* orderflag */, &result) == 0);

    if(verbose) enumResultPrint(&result, pockets, board);

    assert(result.ev[0] == 1.0);
    assert(result.ev[1] == 0.0);
  }
  
  {
    /* http://shipitfish.livejournal.com/59671.html 

        If after removing straights and flushes, if hand X beats hand
        Y under normal poker rules, the hand Y beats hand X under
        razz.

        There should *never* be a case where one hand wins over
        another in both normal poker rules and razz (after removing
        straights and flushes).

        Therefore, 6s full of 5s loses 4s full of 8s in razz and
        likewise by the same logic 6s and 5s beat 4s and 8s in razz.

        4s and 8s should definately *NOT* beat 6s and 5s in both
        7-card stud and razz. If one hand wins in 7-card stud, the
        other hand wins in razz. It is that simple.

     */
    
    enum_result_t result;
    StdDeck_CardMask board;
    StdDeck_CardMask dead;
    StdDeck_CardMask pockets[2];
    char* hand0[] = { "5d", "5c", "6d", "6c", "7d", "7c", "7h" };
    char* hand1[] = { "4d", "4c", "8d", "8c", "9d", "9c", "9h" };

    enumResultClear(&result);
    CardMask_RESET(board);
    CardMask_RESET(dead);
    pockets[0] = Strings2CardMask(7, hand0);
    pockets[1] = Strings2CardMask(7, hand1);

    assert(enumExhaustive(game, pockets, board, dead, 2, 0 /* nboard */,
                          0 /* orderflag */, &result) == 0);

    if(verbose) enumResultPrint(&result, pockets, board);

    assert(result.ev[0] == 1.0);
    assert(result.ev[1] == 0.0);
  }

  return 0;
}