/** * @brief Returns the json_doc used in the head log by exact_solver and ifes solvers. * * @param [in] call_level call level value * @param [in] gpx the current game position * @return the newly constucted json string */ gchar * game_tree_log_data_h_json_doc2 (const int call_level, const GamePositionX *const gpx) { gchar *ret = NULL; GString *json_doc; json_doc = g_string_sized_new(256); const gboolean is_leaf = !game_position_x_has_any_player_any_legal_move(gpx); const SquareSet legal_moves = game_position_x_legal_moves(gpx); const int legal_move_count = bit_works_bitcount_64(legal_moves); const SquareSet empties = game_position_x_empties(gpx); const int empty_count = bit_works_bitcount_64(empties); const int legal_move_count_adj = legal_move_count + ((legal_moves == 0 && !is_leaf) ? 1 : 0); gchar *legal_moves_pg_json_array = square_set_to_pg_json_array(legal_moves); /* * cl: call level * ec: empty count * il: is leaf * lmc: legal move count * lmca: legal move count adjusted * lma: legal move array ([""A1"", ""B4"", ""H8""]) */ g_string_append_printf(json_doc, "\"{ \"\"cl\"\": %2d, \"\"ec\"\": %2d, \"\"il\"\": %s, \"\"lmc\"\": %2d, \"\"lmca\"\": %2d, \"\"lma\"\": %s }\"", call_level, empty_count, is_leaf ? "true" : "false", legal_move_count, legal_move_count_adj, legal_moves_pg_json_array); g_free(legal_moves_pg_json_array); ret = json_doc->str; g_string_free(json_doc, FALSE); return ret; }
/** * @brief Returns the json_doc used in the head log by exact_solver and ifes solvers. * * @param [out] json_doc the newly constucted json string * @param [in] call_level call level value * @param [in] gpx the current game position * @return the length of the json_doc string */ int game_tree_log_data_h_json_doc3 (char *const json_doc, const int call_level, const GamePositionX *const gpx) { const gboolean is_leaf = !game_position_x_has_any_player_any_legal_move(gpx); const SquareSet legal_moves = game_position_x_legal_moves(gpx); const int legal_move_count = bit_works_bitcount_64(legal_moves); const SquareSet empties = game_position_x_empties(gpx); const int empty_count = bit_works_bitcount_64(empties); const int legal_move_count_adj = legal_move_count + ((legal_moves == 0 && !is_leaf) ? 1 : 0); gchar *legal_moves_pg_json_array = square_set_to_pg_json_array(legal_moves); /* * cl: call level * ec: empty count * il: is leaf * lmc: legal move count * lmca: legal move count adjusted * lma: legal move array ([""A1"", ""B4"", ""H8""]) */ const int len = sprintf(json_doc, "\"{ \"\"cl\"\": %2d, \"\"ec\"\": %2d, \"\"il\"\": %s, \"\"lmc\"\": %2d, \"\"lmca\"\": %2d, \"\"lma\"\": %s }\"", call_level, empty_count, is_leaf ? "true" : "false", legal_move_count, legal_move_count_adj, legal_moves_pg_json_array); return len; }
/* * Sorts moves in ascending order of mobility. */ static void sort_moves_by_mobility_count (MoveList *move_list, const GamePosition *const gp) { MoveListElement *curr = NULL; int move_index = 0; const SquareSet moves = game_position_legal_moves(gp); SquareSet moves_to_search = moves; for (int i = 0; i < legal_moves_priority_cluster_count; i++) { moves_to_search = legal_moves_priority_mask[i] & moves; while (moves_to_search) { curr = &move_list->elements[move_index]; const Square move = bit_works_bitscanLS1B_64(moves_to_search); moves_to_search &= ~(1ULL << move); GamePosition *next_gp = game_position_make_move(gp, move); const SquareSet next_moves = game_position_legal_moves(next_gp); game_position_free(next_gp); const int next_move_count = bit_works_bitcount_64(next_moves); curr->sq = move; curr->mobility = next_move_count; for (MoveListElement *element = move_list->head.succ; element != NULL; element = element->succ) { if (curr->mobility < element->mobility) { /* Insert current before element. */ MoveListElement *left = element->pred; MoveListElement *right = element; curr->pred = left; curr->succ = right; left->succ = curr; right->pred = curr; goto out; } } out: move_index++; } } return; }