Commit 7c2de044 authored by Raphael's avatar Raphael

first merge done yooooopi

parent 8e69e2ed
......@@ -6,7 +6,7 @@
# By: rbeaufre <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/06/03 14:03:16 by rbeaufre #+# #+# #
# Updated: 2019/12/02 18:30:06 by rbeaufre ### ########.fr #
# Updated: 2019/12/02 19:00:57 by rbeaufre ### ########.fr #
# #
# **************************************************************************** #
......@@ -52,7 +52,8 @@ SRC_RAW = get_next_line.c \
print_ant_moves_inits.c \
algo.c \
bfs_gaspard.c \
ft_put_bibli.c
ft_put_bibli.c \
ft_put_arcw.c
SRC = $(addprefix $(SRC_DIR)/, $(SRC_RAW))
......
#include "lem_in.h"
void ft_put_arcw(t_node *end, t_list **list)
{
t_list *tmp;
t_node *node;
t_node *start;
tmp = end->father;
end->passed_flag = 2;
while (tmp)
{
node = (t_node *)tmp->content;
node->passed_flag = 2;
tmp = node->father;
}
start = ft_find_t_node_with_start(list);
tmp = start->next;
start->passed_flag = 3;
while (tmp)
{
node = (t_node *)tmp->content;
if (node->passed_flag == 2 && tmp->arcw <= 0)
{
node->passed_flag = 3;
if (tmp->arcw == -1)
tmp->arcw = 0;
else
tmp->arcw = 1;
tmp = node->next;
}
else
tmp = tmp->next;
}
tmp = end->next;
end->passed_flag = 0;
while (tmp)
{
node = (t_node *)tmp->content;
if (node->passed_flag == 3 && tmp->arcw >= 0)
{
node->passed_flag = 0;
if (tmp->arcw == 1)
{
tmp->arcw = 0;
ft_test_voisin(node);
}
else
{
tmp->arcw = -1;
node->passed_flag = 5;
}
tmp = node->next;
}
else
tmp = tmp->next;
}
}
void ft_test_voisin(t_node *node)
{
t_list *tmp;
int count;
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmoindro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/02 17:10:43 by gmoindro #+# #+# */
/* Updated: 2019/12/02 19:02:29 by rbeaufre ### ########.fr */
/* */
/* ************************************************************************** */
count = 0;
tmp = node->next;
while (tmp)
{
if (tmp->arcw == 1)
count++;
tmp = tmp->next;
}
if (count < 1)
node->passed_flag = 0;
else
node->passed_flag = 5;
}
#include "lem_in.h"
void ft_reset_passed_flags_gasp(t_list **list)
void ft_reset_passed_flags_gasp(t_list **list)
{
t_list *tmp;
t_node *node;
......@@ -94,35 +30,11 @@ void ft_reset_passed_flags_gasp(t_list **list)
}
}
void ft_test_g(t_list **list)
{
t_list *tmp;
t_list *tmp_2;
t_node *node;
tmp = *list;
ft_putchar('\n');
while (tmp && tmp->content && ((t_node *) tmp->content)->name)
{
node = (t_node *) tmp->content;
tmp_2 = node->next;
ft_printf("%s ||", node->name);
while (tmp_2)
{
node = (t_node *) tmp_2->content;
ft_printf("-> %s:%d ", node->name, tmp_2->arcw);
tmp_2 = tmp_2 -> next;
}
ft_printf("\n");
tmp = tmp->next;
}
}
int ft_connect_start(t_list **list)
int ft_connect_start(t_list **list)
{
t_node *start;
t_list *tmp;
int count;
int count;
start = ft_find_t_node_with_start(list);
tmp = start->next;
......@@ -135,26 +47,10 @@ int ft_connect_start(t_list **list)
return (count);
}
void ft_test_flag(t_list **list)
{
t_list *tmp;
t_node *node;
tmp = *list;
ft_putchar('\n');
while (tmp->next)
{
node = (t_node *) tmp->content;
ft_printf("%s - %d -> %d\n", node->name, node->passed_flag, node->chance_one);
tmp = tmp->next;
}
ft_putchar('\n');
}
t_list ***ft_malloc_result(t_params **params, t_list **list)
{
int size;
int i;
int size;
int i;
t_list ***result;
i = -1;
......@@ -167,52 +63,47 @@ t_list ***ft_malloc_result(t_params **params, t_list **list)
return (result);
}
void print_bibli(t_list ***result, int i)
void print_bibli(t_list ***result, int i)
{
t_node *node;
t_list *tmp;
int j;
t_node *node;
t_list *tmp;
int j;
j = -1;
ft_printf("\n");
while (++j <= i)
{
node = (t_node *)((*result)[j]->content);
ft_printf("%s ", node->name);
tmp = (*result)[j]->next;
while (tmp)
{
node = (t_node *) tmp->content;
ft_printf("-> %s ", node->name);
tmp = tmp->next;
}
ft_printf("\n");
}
j = -1;
ft_printf("\n");
while (++j <= i)
{
node = (t_node *)((*result)[j]->content);
ft_printf("%s ", node->name);
tmp = (*result)[j]->next;
while (tmp)
{
node = (t_node *)tmp->content;
ft_printf("-> %s ", node->name);
tmp = tmp->next;
}
ft_printf("\n");
}
}
void ft_algo(t_params **params, t_list **list)
void ft_algo(t_params **params, t_list **list)
{
t_node *node;
int index;
int index;
t_list ***result;
index = 0;
node = ft_find_t_node_with_start(list);
result = ft_malloc_result(params, list);
while (index < (*params)->ant_count && index < ft_connect_start(list) && ft_bfs_gaspard(list, params, node) > 0)
while (index < (*params)->ant_count && index < ft_connect_start(list)
&& ft_bfs_gaspard(list, params, node) > 0)
{
if (!(result[index] = (t_list **)malloc(sizeof(t_list) * (index + 1))))
return ;
//ft_test_flag(list);
ft_reset_passed_flags_gasp(list);
//ft_test_g(list);
ft_put_bibli(list, result, index);
index++;
}
//int l = -1; // test
//while (++l < index) // test
// print_bibli(&result[l], l); // test
(*params)->index_max = index;
ft_print_ant_moves(result, params);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bfs_gaspard.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmoindro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/02 17:15:01 by gmoindro #+# #+# */
/* Updated: 2019/12/02 18:22:38 by gmoindro ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void ft_add_path_history(t_node **son, t_node **father)
......@@ -11,6 +23,31 @@ static void ft_add_path_history(t_node **son, t_node **father)
}
}
static void ft_stack_flag(t_node *node, t_node *queue)
{
if (node->passed_flag == 5 && queue->chance_one % 2 == 0
&& queue->passed_flag == 1)
{
node->chance_one = queue->chance_one + 1;
node->passed_flag = -5;
}
else if (node->passed_flag == 5 && queue->chance_one % 2 == 0)
{
node->chance_one = queue->chance_one;
node->passed_flag = -5;
}
else if (node->passed_flag == 5)
{
node->chance_one = queue->chance_one + 1;
node->passed_flag = -5;
}
else if (node->passed_flag == 0)
{
node->chance_one = queue->chance_one;
node->passed_flag = 1;
}
}
static void ft_stack_virgin_neighbours(t_node **queue, int *i, int *j)
{
t_list *tmp;
......@@ -21,26 +58,15 @@ static void ft_stack_virgin_neighbours(t_node **queue, int *i, int *j)
while (tmp)
{
node = (t_node *)tmp->content;
if (((node->passed_flag == 0 && (queue[*i]->chance_one != 1 || queue[*i]->passed_flag == 1))
|| (node->passed_flag == 5 && (queue[*i]->chance_one == 0
|| (queue[*i]->passed_flag == -5 && tmp->arcw == -1)) && queue[*i]->is_start == 0))
&& tmp->arcw <= 0 && !(node->is_end == 1 && queue[*i]->passed_flag == -5))
if (((node->passed_flag == 0 && (queue[*i]->chance_one % 2 != 1
|| queue[*i]->passed_flag == 1)) || (node->passed_flag == 5
&& ((queue[*i]->chance_one % 2 == 0 && queue[*i]->passed_flag == 1)
|| (queue[*i]->passed_flag == -5 && tmp->arcw == -1))
&& queue[*i]->is_start == 0))
&& tmp->arcw <= 0
&& !(node->is_end == 1 && queue[*i]->passed_flag == -5))
{
if (node->passed_flag == 5 && queue[*i]->chance_one == 0)
{
node->chance_one = 1;
node->passed_flag = -5;
}
else if (node->passed_flag == 5)
{
node->chance_one = 2;
node->passed_flag = -5;
}
else if (node->passed_flag == 0)
{
node->chance_one = queue[*i]->chance_one;
node->passed_flag = 1;
}
ft_stack_flag(node, queue[*i]);
queue[*i + *j] = node;
ft_add_path_history(&(queue[*i + *j]), &(queue[*i]));
(*j)++;
......@@ -49,14 +75,13 @@ static void ft_stack_virgin_neighbours(t_node **queue, int *i, int *j)
}
}
int ft_bfs_gaspard(t_list **list, t_params **params, t_node *start)
int ft_bfs_gaspard(t_list **list, t_params **params, t_node *start)
{
t_node **queue;
int i;
int j;
int i;
int j;
i = 0;
(void)list;
queue = (t_node **)malloc(sizeof(t_node *) * (*params)->rooms_count);
if (!queue)
return (-1);
......
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_arcw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmoindro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/02 18:37:32 by gmoindro #+# #+# */
/* Updated: 2019/12/02 18:47:52 by gmoindro ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void ft_put_arcw_init(t_node *end)
{
t_list *tmp;
t_node *node;
tmp = end->father;
end->passed_flag = 2;
while (tmp)
{
node = (t_node *)tmp->content;
node->passed_flag = 2;
tmp = node->father;
}
}
static void ft_put_arcw_flag_start(t_list **list)
{
t_list *tmp;
t_node *node;
t_node *start;
start = ft_find_t_node_with_start(list);
tmp = start->next;
start->passed_flag = 3;
while (tmp)
{
node = (t_node *)tmp->content;
if (node->passed_flag == 2 && tmp->arcw <= 0)
{
node->passed_flag = 3;
if (tmp->arcw == -1)
tmp->arcw = 0;
else
tmp->arcw = 1;
tmp = node->next;
}
else
tmp = tmp->next;
}
}
static void ft_put_arcw_end(t_node *end, t_list **list)
{
ft_put_arcw_init(end);
ft_put_arcw_flag_start(list);
end->passed_flag = 0;
}
void ft_put_arcw(t_node *end, t_list **list)
{
t_list *tmp;
t_node *node;
tmp = end->next;
ft_put_arcw_end(end, list);
while (tmp)
{
node = (t_node *)tmp->content;
if (node->passed_flag == 3 && tmp->arcw >= 0)
{
node->passed_flag = 0;
if (tmp->arcw == 1)
ft_test_voisin(node, tmp);
else
{
tmp->arcw = -1;
node->passed_flag = 5;
}
tmp = node->next;
}
else
tmp = tmp->next;
}
}
void ft_test_voisin(t_node *node, t_list *tmp)
{
int count;
count = 0;
tmp->arcw = 0;
tmp = node->next;
while (tmp)
{
if (tmp->arcw == 1)
count++;
tmp = tmp->next;
}
if (count < 1)
node->passed_flag = 0;
else
node->passed_flag = 5;
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_bibli.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmoindro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/02 17:20:26 by gmoindro #+# #+# */
/* Updated: 2019/12/02 18:11:46 by gmoindro ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void ft_lstadd_back(t_list **alst, t_list *new)
......@@ -13,57 +25,59 @@ static void ft_lstadd_back(t_list **alst, t_list *new)
}
}
static void init_result(t_list ***result, t_list **list, int i, int j)
{
result[i][j] = (t_list *)malloc(sizeof(t_list));
result[i][j]->content = ft_find_t_node_with_start(list);
result[i][j]->content_size = sizeof(t_node);
result[i][j]->next = NULL;
}
static void ft_put_bibli_next(t_list *tmp_2, t_list *result)
{
t_list *new;
t_node *node;
while (tmp_2)
{
node = (t_node *)tmp_2->content;
if (tmp_2->arcw == 1)
{
new = ft_lstnew_revisited(node, sizeof(t_node));
ft_lstadd_back(&result, new);
if (node->is_end == 1)
break ;
tmp_2 = node->next;
}
else
tmp_2 = tmp_2->next;
}
}
void ft_put_bibli(t_list **list, t_list ***result, int i)
{
t_list *tmp;
t_list *tmp_2;
t_list *new;
t_node *node;
t_node *node_2;
t_node *end;
int j;
t_node *node[2];
int j;
end = ft_find_t_node_with_end(list);
node[0] = ft_find_t_node_with_end(list);
j = 0;
node = ft_find_t_node_with_start(list);
tmp = node->next;
while (tmp && i >= j && node)
node[1] = ft_find_t_node_with_start(list);
tmp = node[1]->next;
while (tmp && i >= j && node[1])
{
node = (t_node *) tmp->content;
node[1] = (t_node *)tmp->content;
if (tmp->arcw == 1 && i >= j)
{
//ft_printf("%d : %s", j,ft_find_t_node_with_start(list)->name); //printf
//ft_printf(" -> %s ", node->name); //printf
result[i][j] = (t_list *)malloc(sizeof(t_list));
result[i][j]->content = ft_find_t_node_with_start(list);
result[i][j]->content_size = sizeof(t_node);
result[i][j]->next = NULL;
new = ft_lstnew_revisited(node, sizeof(t_node));
init_result(result, list, i, j);
new = ft_lstnew_revisited(node[1], sizeof(t_node));
ft_lstadd_back(&result[i][j], new);
tmp_2 = node->next;
while (tmp_2)
{
node_2 = (t_node *) tmp_2->content;
if (tmp_2->arcw == 1)
{
//ft_printf("-> %s ", node_2->name); //printf
new = ft_lstnew_revisited(node_2, sizeof(t_node));
ft_lstadd_back(&result[i][j], new);
if (node_2->is_end == 1)
break;
tmp_2 = node_2->next;
}
else
tmp_2 = tmp_2->next;
}
tmp_2 = node[1]->next;
ft_put_bibli_next(tmp_2, result[i][j]);
j++;
//ft_putchar('\n'); //printf
}
tmp = tmp->next;
}
//ft_putchar('\n'); //printf
}
No preview for this file type
......@@ -6,7 +6,7 @@
/* By: rbeaufre <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/17 16:32:05 by rbeaufre #+# #+# */
/* Updated: 2019/12/02 17:05:54 by rbeaufre ### ########.fr */
/* Updated: 2019/12/02 19:03:08 by rbeaufre ### ########.fr */
/* */
/* ************************************************************************** */
......
......@@ -6,7 +6,7 @@
/* By: rbeaufre <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/17 07:39:34 by rbeaufre #+# #+# */
/* Updated: 2019/12/02 18:52:32 by rbeaufre ### ########.fr */
/* Updated: 2019/12/02 19:03:24 by rbeaufre ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -151,7 +151,7 @@ void ft_put_arcw(t_node *end, t_list **list);
void ft_put_bibli(t_list **list, t_list ***result, int i);
t_list ***ft_malloc_result(t_params **params, t_list **list);
int ft_connect_start(t_list **list);
void ft_test_voisin(t_node *node);
void ft_test_voisin(t_node *node, t_list *tmp);
void ft_init_length(int *length, int index);
#endif
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -6,7 +6,7 @@
/* By: rbeaufre <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/28 20:47:23 by rbeaufre #+# #+# */
/* Updated: 2019/12/02 18:57:56 by rbeaufre ### ########.fr */
/* Updated: 2019/12/02 18:59:35 by rbeaufre ### ########.fr */
/* */
/* ************************************************************************** */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment