Пример #1
0
static void ai_init_glib_et_al(int argc, char **argv)
{
	GOptionContext *context;
	GError *error = NULL;

	context =
	    /* Long description in the commandline for pioneersai: help */
	    g_option_context_new(_("- Computer player for Pioneers"));
	g_option_context_add_main_entries(context, commandline_entries,
					  PACKAGE);
	g_option_context_parse(context, &argc, &argv, &error);
	g_option_context_free(context);

	if (error != NULL) {
		g_print("%s\n", error->message);
		g_error_free(error);
		exit(1);
	}
	if (show_version) {
		g_print(_("Pioneers version:"));
		g_print(" ");
		g_print(FULL_VERSION);
		g_print("\n");
		exit(0);
	}

	g_type_init();
	set_ui_driver(&Glib_Driver);
	log_set_func_default();
}
Пример #2
0
static void ai_init(int argc, char **argv)
{
	GOptionContext *context;
	GError *error = NULL;

	/* Long description in the commandline for pioneersai: help */
	context =
	    g_option_context_new(_("- Computer player for Pioneers"));
	g_option_context_add_main_entries(context, commandline_entries,
					  PACKAGE);
	g_option_context_parse(context, &argc, &argv, &error);
	if (error != NULL) {
		g_print("%s\n", error->message);
		g_error_free(error);
		exit(1);
	}
	if (show_version) {
		g_print(_("Pioneers version:"));
		g_print(" ");
		g_print(FULL_VERSION);
		g_print("\n");
		exit(0);
	}

	set_enable_debug(enable_debug);

	if (server == NULL)
		server = g_strdup(PIONEERS_DEFAULT_GAME_HOST);
	if (port == NULL)
		port = g_strdup(PIONEERS_DEFAULT_GAME_PORT);

	printf("ai port is %s\n", port);

	g_random_set_seed(time(NULL) + getpid());

	if (!name) {
		/* ai commandline error */
		g_print(_("A name must be provided.\n"));
		exit(0);
	}

	set_ui_driver(&Glib_Driver);
	log_set_func_default();

	if (ai != NULL) {
		gint i;
		for (i = 0; i < G_N_ELEMENTS(algorithms); i++) {
			if (!strcmp(algorithms[i].name, ai))
				active_algorithm = i;
		}
	}
	log_message(MSG_INFO, _("Type of computer player: %s\n"),
		    algorithms[active_algorithm].name);
	algorithms[active_algorithm].init_func(argc, argv);
}