static void run_tests (void) { Query *q; SCM val2str; int i; val2str = scm_c_eval_string ("gnc:value->string"); g_return_if_fail (scm_is_procedure (val2str)); for (i = 0; i < 1000; i++) { q = get_random_query (); test_query (q, val2str); qof_query_destroy (q); fflush(stdout); } { q = get_random_query (); test_query (q, val2str); qof_query_destroy (q); fflush(stdout); } }
void newGame() { srand((unsigned)time(NULL)); const char *first_query = "mikan"; std::pair<int, int> first_result; first_result = sendAttempt(first_query); if (pperm_ct == 0) { for (char a = 'a'; a <= 'z'; ++a) for (char b = 'a'; b <= 'z'; ++b) if (b != a) for (char c = 'a'; c <= 'z'; ++c) if (c != a && c != b) for (char d = 'a'; d <= 'z'; ++d) if (d != a && d != b && d != c) for (register char e = 'a'; e <= 'z'; ++e) if (e != a && e != b && e != c && e != d) { char *s = _pool + pperm_ct * 5 * sizeof(char); s[0] = a; s[1] = b; s[2] = c; s[3] = d; s[4] = e; pp[pperm_ct] = s; pp_res[pperm_ct] = check(pp[pperm_ct], first_query); ++pperm_ct; } //std::random_shuffle(pp, pp + pperm_ct); for (int i = pperm_ct - 64; i < pperm_ct; ++i) { int j = rand() % i; std::swap(pp[i], pp[j]); std::swap(pp_res[i], pp_res[j]); } } perm_ct = 0; for (int i = 0; i < pperm_ct; ++i) if (pp_res[i] == first_result) p[perm_ct++] = pp[i]; while (perm_ct > 1) { static std::pair<int, char *> q_cur, q_best; q_best = std::make_pair(0x7fffffff, nullptr); for (int i = 0; i < 4096; ++i) { q_cur.second = get_random_query(); q_cur.first = eval_entropy(q_cur.second); if (q_best.first > q_cur.first) q_best = q_cur; } std::pair<int, int> result = sendAttempt(q_best.second); for (int i = 0; i < perm_ct; ) { if (check(p[i], q_best.second) == result) { ++i; } else { std::swap(p[i], p[perm_ct - 1]); --perm_ct; } } } // The answer sendAttempt(p[0]); }
static void run_tests (int count) { Query *q; SCM val2str; int i; val2str = scm_c_eval_string ("gnc:value->string"); g_return_if_fail (scm_is_procedure (val2str)); for (i = 0; i < count; i++) { q = get_random_query (); test_query (q, val2str); qof_query_destroy (q); } success (""); }
static void run_tests (void) { QofQuery *q; int i; test_query (NULL); q = qof_query_create_for(GNC_ID_SPLIT); test_query (q); qof_query_destroy (q); for (i = 0; i < 50; i++) { q = get_random_query (); test_query (q); qof_query_destroy (q); } }