fuckinlem_in/srcs/score_utils.c
Tanguy MAZE 1f24922155 Works a bit less but on in a better way
changed rules of queue addition
still problems on map4 with 2 merged paths
2019-04-19 13:26:13 +02:00

90 lines
2.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* score_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/18 18:05:06 by tmaze #+# #+# */
/* Updated: 2019/04/19 12:52:45 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))
{
while (i < nb_paths && nbants > 0)
{
if (scores[i] == min)
{
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])
{
scores[i] = (ret[i]->weight > 0) * (get_nb_nodes(ret[i]) + ret[i]->weight - 1);
if (min < scores[i])
min = scores[i];
}
}
return (min);
}