static void game_position_has_any_player_any_legal_move_test (GamePositionDbFixture *fixture, gconstpointer test_data) { GamePositionDb *db = fixture->db; g_assert(TRUE == game_position_has_any_player_any_legal_move(get_gp_from_db(db, "initial"))); g_assert(TRUE == game_position_has_any_player_any_legal_move(get_gp_from_db(db, "early-game-b-9-moves"))); g_assert(TRUE == game_position_has_any_player_any_legal_move(get_gp_from_db(db, "black-has-to-pass"))); g_assert(TRUE == game_position_has_any_player_any_legal_move(get_gp_from_db(db, "early-game-c-12-moves"))); g_assert(FALSE == game_position_has_any_player_any_legal_move(get_gp_from_db(db, "final-b37-w27"))); }
/** * @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] gp the current game position * @return the newly constucted json string */ gchar * game_tree_log_data_h_json_doc (const int call_level, const GamePosition *const gp) { gchar *ret = NULL; GString *json_doc; json_doc = g_string_sized_new(256); const gboolean is_leaf = !game_position_has_any_player_any_legal_move(gp); const SquareSet legal_moves = game_position_legal_moves(gp); const int legal_move_count = bit_works_bitcount_64(legal_moves); const SquareSet empties = board_empties(gp->board); 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; }