const std::string pretty_pv(const Position &pos, int time, int depth,
                            uint64_t nodes, Value score, Move pv[]) {
  std::stringstream s;

  // Depth
  s << std::setw(2) << std::setfill(' ') << depth << "  ";

  // Score
  s << std::setw(8) << score_string(score);

  // Time
  s << std::setw(8) << std::setfill(' ') << time_string(time) << " ";

  // Nodes
  if(nodes < 1000000ULL)
    s << std::setw(8) << std::setfill(' ') << nodes << " ";
  else if(nodes < 1000000000ULL)
    s << std::setw(7) << std::setfill(' ') << nodes/1000ULL << 'k' << " ";
  else
    s << std::setw(7) << std::setfill(' ') << nodes/1000000ULL << 'M' << " ";

  // PV
  s << line_to_san(pos, pv, 30, true, 0);

  return s.str();
}
示例#2
0
static void card_enter (HandDisplay *handdisp, int card, int *seatp)
{
	PROTECT_BEGIN;
	char buf[100];

	board_statusbar(NULL);

	board *b = CUR_BOARD;
	if (!b->current_dd || b->current_dd->card_score[card] < 0 ||
			!seat_mask (*seatp, win->show_dd_scores))
		PROTECT_RETURN;

	snprintf(buf, 99, "%s: %s",
		card_string(card),
		score_string(b->level, b->trumps, b->declarer, b->doubled, b->vuln[b->declarer % 2],
			b->current_dd->card_score[card], b->current_turn));
	board_statusbar(buf);

	/* what-if */
	//hilight_next_dd_scores (b, card);
	//show_board (b, REDRAW_DD);
	PROTECT_END;
}
示例#3
0
static
void	_assert_scores(char *file, int line, int expected_score, char *string, char *pattern, unsigned *expected_match)
{
	int pat_len = strlen(pattern);
	int real_score;
	int i;
	unsigned match[pat_len];

	qry.pattern = pattern;
	real_score = score_string(string, &qry, strlen(string), match);
	if (real_score != expected_score) {
		_fail_unless(0, file, line, 0, "scoring %s against pattern %s should score 0x%x, not 0x%x",
			     string, pattern, expected_score, real_score,
			     0);
		return;
	}
	if (expected_match)
		for (i=0;i<pat_len;i++)
			if (expected_match[i] != match[i])
				_fail_unless(0, file, line, 0,
					     "match differs in pos %d. Expected %d, got %d",
					     i, expected_match[i], match[i], 0);
	_fail_unless(1, __FILE__, __LINE__, "cannot happen", 0);
}
示例#4
0
char *ipsumat_generate (const char *dict_path,
                        const char *charset,
                        const char *desired_glyphs,
                        int         max_wordlen,
                        int         max_words)
{
  gunichar *p;
  gunichar *ucharset;
  gunichar *udesired_glyphs = NULL;

  int      count = 0;
  int      best_sentence[MAX_WORDS]={0,};
  int      sentence[MAX_WORDS]={0,};
  char    *words_str = NULL;
  gunichar *uwords_str = NULL;
  GList   *words = NULL;
  GString *word = g_string_new ("");
  int      best_score = 0;
  int      i;
  if (!dict_path)
    dict_path = "/usr/share/dict/words";

  g_file_get_contents (dict_path, &words_str, NULL, NULL);

  if (!words_str)
    return g_strdup ("problem opening dictionary");

  uwords_str = g_utf8_to_ucs4 (words_str, -1, NULL, NULL, NULL);

  if (charset == NULL)
    charset = "abcdefghijklmnopqrstuvwxyz";

  ucharset = g_utf8_to_ucs4 (charset, -1, NULL, NULL, NULL);
  if (desired_glyphs)
    udesired_glyphs = g_utf8_to_ucs4 (desired_glyphs, -1, NULL, NULL, NULL);


  if (max_words > MAX_WORDS)
    max_words = MAX_WORDS;

  for (p = uwords_str; *p; p++)
    {
      switch (*p)
      {
        case '\n':
        case '\r':
        case ' ':
        case '\t':
          if (word->len)
          {
            int skip = 0;
            int i;
            gunichar *uword = g_utf8_to_ucs4 (word->str, -1, NULL, NULL, NULL);
            for (i = 0; uword[i]; i++)
              {
                int k;
                skip++;
                for (k = 0; ucharset[k]; k++)
                  if (ucharset[k]==uword[i])
                    {
                      skip--;break;
                    }
              }
            if (word->len > max_wordlen)
              skip++;

            if (!skip)
            {
              words = g_list_prepend (words, g_strdup (word->str));
              count ++;
            }
            g_free (uword);
          }
          g_string_assign (word, "");
          break;
        default:
          g_string_append_unichar (word, *p);
          break;
      }
    }
  g_free (ucharset);
  g_free (words_str);
  g_free (uwords_str);

  for (i = 0; i < attempts; i ++)
    {
      GString *example = g_string_new ("");
      int j;
      for (j = 0; j < max_words; j ++)
        {
          int n;
          const char *str;
          n = rand()%count;
 
          {
            int k;
            for (k = 0; k < j; k++)
              if (sentence[k]==n)
                {
                  /* we try once more if it collides with already picked
                   * random number,. - but this value will stick */
                  n = rand()%count;
                  break;
                }
          }
          sentence[j] = n;
          
          str = g_list_nth_data (words, n);
          if (str)
          {
            if (j)
              g_string_append (example, " ");
            g_string_append (example, str);
          }
        }
      float score = score_string ((void*)example->str, desired_glyphs);
      if (score >= best_score)
      {
        for (j = 0; j < max_words; j ++)
          best_sentence[j] = sentence[j];
        best_score = score;
      }
      g_string_free (example, TRUE);
    }

  if (print_score)
    printf ("Score: %i\n", best_score);

  {
    char *ret = NULL;
    int j;
    GString *s = g_string_new ("");

    if (desired_glyphs && desired_glyphs[0])
      {
        g_string_append (s, desired_glyphs);
        g_string_append (s, " ");
      }

    for (j = 0; j < max_words; j ++)
    {
      const char *str;
      str = g_list_nth_data (words, best_sentence[j]);
      if (str)
        {
          if (j)
            g_string_append (s, " ");
          g_string_append (s, str);
        }
    }
    ret = strdup (s->str);
    g_string_free (s, TRUE);
    g_free (udesired_glyphs);
    return ret;
  }
}
示例#5
0
文件: scorer.c 项目: ptmono/gpicker
int score_simple_string(const char *string, const char *pattern, unsigned *match)
{
	struct scorer_query qry = {.pattern = pattern,.right_match = 0};
	unsigned string_length = strlen(string);
	return score_string(string, &qry, string_length, match);
}