/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* score_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/18 18:05:06 by tmaze #+# #+# */ /* Updated: 2019/04/18 20:13:29 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "lem_in.h" static void init_scores(t_ind **ret, int *scores) { int i; i = 0; while (ret[i]) { scores[i] = ret[i]->weight; ret[i]->weight = 0; i++; } } static int get_nb_nodes(t_ind *lst) { t_ind *it; int i; i = 0; it = lst; while (it && (++i)) it = it->next; return (i); } int get_score(t_lmdata *data, t_ind **ret, int nb_paths) { int nbants; int i; int min; int scores[nb_paths]; if (nb_paths == 1) { ret[0]->weight = data->nbants; min = (ret[0]->weight > 0) * (get_nb_nodes(ret[0]) + ret[0]->weight - 1); } else { min = FT_INT_MAX; i = -1; nbants = data->nbants; init_scores(ret, scores); while (ret[++i]) if (min > scores[i]) min = scores[i]; while (nbants > 0 && !(i = 0)) { ft_printf("=== debug score ===\nnb_paths: %d\nscore[%d]: %d\nmin: %d\nnbants: %d\n\n", nb_paths, i, scores[i], min, nbants); while (i < nb_paths && nbants > 0) { ft_printf("score[%d]: %d\n\n", i, scores[i]); if (scores[i] == min) { ft_printf("increment\n\n"); nbants--; ret[i]->weight++; scores[i] = (ret[i]->weight > 0) * (get_nb_nodes(ret[i]) + ret[i]->weight - 1); } i++; } i = -1; min = FT_INT_MAX; while (ret[++i]) if (min > scores[i]) min = scores[i]; } i = -1; min = 0; while (ret[++i]) if (min < scores[i]) min = scores[i]; } return (min); }