Пример #1
0
// Get bar summaries for cluster nodes
void ClusterMenu::get_lines() {
    // First we set the time of this update
    last_update = std::chrono::steady_clock::now();

    // Call SLURM API to write node information to pointer
    // Free pointer memory first if it has been previously set
    if (node_info_buffer_ptr != NULL) {
        slurm_free_node_info_msg(node_info_buffer_ptr);
    }
    slurm_load_node ((time_t) NULL, &node_info_buffer_ptr, SHOW_ALL);

    // Create a NodeContainer struct and populate with node information
    node_container.populate_nodes_from_slurm(node_info_buffer_ptr);

    // Call API function, pass job_info_ptr as reference (double pointer); flags must be SHOW_DETAIL to get job allocations
    // Free pointer memory first if it has been previously set
    if (job_info_buffer_ptr != NULL) {
        slurm_free_job_info_msg(job_info_buffer_ptr);
    }
    slurm_load_jobs((time_t) NULL, &job_info_buffer_ptr, SHOW_DETAIL);

    // Populate nodes with job allocations
    node_container.populate_job_allocations_from_slurm(job_info_buffer_ptr);

    // Get line content
    lines = node_container.get_node_bar_summary(32);

    // Record largest line for later use in horizontal scrolling
    get_longest_line();
}
int					ft_convert_path_to_int_tables(t_fdf_env *env, char *path)
{
	int			fd;
	t_fdf_file	*tmp;

	if (((fd = open(path, O_RDONLY)) < 0) ||
		(!(env->file = convert_path_to_linked_structs(fd, &env->line_nb))))
		return (0);
	tmp = env->file;
	if ((!(get_longest_line(&env->most_values_into_one_line, env->file))) ||
		(!(ft_convert_linked_structs_to_int_tables(env))))
		return (0);
	free_t_fdf_file(tmp);
	BIG_TAB = ft_malloc_triple_int_tab(env->line_nb,SIZE);
	return (1);
}
Пример #3
0
static int alpha_beta(int field[][MAX_FIELD_ROWS], int x, int y, int depth,
		int alpha, int beta, int maximizing_player)
{
	int done = FALSE;

	int their_longest = get_longest_line(x, y, game.settings.their_botid, field);
	int your_longest = get_longest_line(x, y, game.settings.your_botid, field);

	int last_player;

	int chldx;
	int chldy;

	int v;

	if (depth <= 0 || their_longest >= WIN_LENGTH ||
			your_longest >= WIN_LENGTH) {
		if (maximizing_player)
			last_player = 2;
		else
			last_player = 1;

		if (their_longest >= WIN_LENGTH)
			return evaluate(game.settings.your_botid,
					game.settings.their_botid,
					x, y, last_player, field)
				+ (ALPHABETA_LEVEL - depth);
		else if (your_longest >= WIN_LENGTH)
			return evaluate(game.settings.your_botid,
					game.settings.your_botid,
					x, y, last_player, field)
				- (ALPHABETA_LEVEL - depth);
		else
			return evaluate(game.settings.your_botid, 0,
					x, y, last_player, field)
				- (ALPHABETA_LEVEL - depth);
	} else if (board_full(game.round + ALPHABETA_LEVEL - depth))
		return 0;

	if (maximizing_player) {
		v = INT_MIN;

		for (chldx = 0; chldx < game.settings.field_columns; ++chldx) {
			for (chldy = 0; chldy < game.settings.field_rows; ++chldy) {
				if (can_be_placed(chldx, chldy, field)) {
					field[chldx][chldy] = game.settings.your_botid;

					v = max(v, alpha_beta(field, chldx, chldy, depth - 1, alpha, beta, FALSE));
					alpha = max(alpha, v);

					field[chldx][chldy] = 0;

					if (beta <= alpha) {
						done = TRUE;
						break;
					}
				}
			}

			if (done)
				break;
		}

		return v;
	} else {
		v = INT_MAX;

		for (chldx = 0; chldx < game.settings.field_columns; ++chldx) {
			for (chldy = 0; chldy < game.settings.field_rows; ++chldy) {
				if (can_be_placed(chldx, chldy, field)) {
					field[chldx][chldy] = game.settings.their_botid;

					v = min(v, alpha_beta(field, chldx, chldy, depth - 1, alpha, beta, TRUE));
					beta = min(beta, v);

					field[chldx][chldy] = 0;

					if (beta <= alpha) {
						done = TRUE;
						break;
					}
				}
			}

			if (done)
				break;
		}

		return v;
	}
}