Skip to content

Commit 1b73865

Browse files
author
Allan BARRIELLE
committed
need to handles lenght path and color fun
1 parent 71ccbb5 commit 1b73865

File tree

8 files changed

+106
-56
lines changed

8 files changed

+106
-56
lines changed

abarriel2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b3e5c22f7559b5b5c5885cc45099cf16372820e2

fdf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 9f5fdff8e394878180927e54d4859f494da9d8fb

libft/Makefile

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,37 @@
1-
2-
# Library output
1+
# Output's Name
32
NAME = libft.a
43

54
# GCC flags
65
CFLAGS = -Werror
76
ALL_CFLAGS = -Wall -Wextra $(CFLAGS)
87

9-
# Ojects/Sources directories
10-
INC_LIBFT = includes/
11-
SRC_LIBFT = $(shell find . | grep "\.c$$" | sed "s/\.c$$//g")
12-
INCLUDES += $(addprefix -iquote , $(INC_LIBFT))
13-
SRCS += $(addsuffix .c, $(SRC_LIBFT))
8+
# Includes directories
9+
INC_PATH = includes/
10+
INCLUDES_FILES= $(shell find . | grep "\.h")
11+
INCLUDES += $(addprefix -iquote , $(INC_PATH))
1412

15-
# Final OBJS
13+
# Sources Objects directories
14+
SRCS = $(shell find . | grep "\.c")
1615
OBJS = $(SRCS:.c=.o)
1716

18-
# Layout
19-
VERBOSE = false
20-
21-
all: header $(NAME) footer
17+
all: $(NAME)
2218

2319
header:
24-
@echo "\033[1;36m[\033[1m$(NAME)]\033[0m\033[1;33m Compile, link & archive\033[0m"
25-
26-
footer:
27-
@echo "\033[1;36m[\033[1m$(NAME)]\033[0m\033[1;32m Well Done\033[0m"
28-
29-
$(NAME): $(OBJS)
30-
ifeq ($(VERBOSE),true)
31-
@echo "\033[1;36m. Archive .\033[0m $(NAME)"
32-
else
33-
@printf "\033[1;31m.\033[0m\n"
34-
endif
35-
@$(AR) rcus $(NAME) $(OBJS)
20+
@echo "\033[1;36m[${NAME}]\033[1;32m Compile && Archive\033[0m"
3621

22+
$(NAME): $(OBJS) $(INCLUDES_FILES)
23+
@printf "\n\r\e\033[0m\e[K\033[1;31m $@ \033[1;32m - Finished\033[0m\n"
24+
@ar rc $(NAME) $(OBJS)
3725
%.o: %.c
38-
ifeq ($(VERBOSE),true)
39-
@echo "\033[1;36m. Compile .\033[0m $<"
40-
else
41-
@printf "\033[1;31m.\033[0m"
42-
endif
43-
@$(CC) $(ALL_CFLAGS) $(INCLUDES) -c $< -o $@
26+
@printf "\r\033[1;32m. Compile .\e\033[0m\e[K \033[1;31m$<"
27+
@gcc $(ALL_CFLAGS) $(INCLUDES) -c $< -o $@
4428

4529
clean:
46-
@echo "\033[1;36m[\033[1m$(NAME)]\033[0m\033[1;33m >>\033[0m \033[1;33mclean (*.o)\033[0m"
30+
4731
@$(RM) $(OBJS)
4832

4933
fclean: clean
50-
@echo "\033[1;36m[\033[1m$(NAME)]\033[0m\033[1;33m >>\033[0m \033[1;33mfclean ($(NAME))\033[0m"
34+
5135
@$(RM) $(NAME)
5236

5337
re: fclean all

map/tes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
10
1+
6
22
##start
33
1 2 5
44
4 5 6

map/test_short

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
3-6
1919
6-7
2020
7-4
21-
4-5
22-
5-10
21+
4-10
2322
8-9
24-
9-10
23+
9-10

srcs/lemin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ t_ant *init_ant(char *name)
4646
ft_strcmp(name, "##end") && *name == '#')
4747
get_next_line(0, &name);
4848
i = ft_atol(name);
49+
ft_printf("%s\n");
4950
if (i <= 0 || !name || i > INT_MAX)
5051
ft_exit("Wrong ant's numbers");
5152
if (!(r = (t_ant*)malloc(sizeof(t_ant))))

srcs/path.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ t_path *init_path(char *name, int start, int p)
6666
if (!(u = (t_path*)malloc(sizeof(t_path))))
6767
ft_exit("Failed to Malloc");
6868
u->name = name;
69+
u->ants = 0;
6970
u->start = start;
7071
u->size += p;
7172
u->next = NULL;

srcs/send.c

Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,102 @@
66
/* By: abarriel <marvin@42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2017/03/07 03:03:25 by abarriel #+# #+# */
9-
/* Updated: 2017/03/07 03:03:27 by abarriel ### ########.fr */
9+
/* Updated: 2017/03/08 11:28:02 by abarriel ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "lemin.h"
1414

15-
void one_path(t_path *p, t_ant *a)
15+
void reverse_list(t_path **list, t_ant *a)
1616
{
17-
int i;
18-
int ants;
17+
t_path *p;
18+
t_path *q;
19+
t_path *r;
1920

20-
ants = 1;
21-
i = 0;
22-
if (p->start == 1)
23-
p = p->next;
24-
while(p)
25-
{
26-
ft_printf("L%d-%s ",a->ant,p->name);
27-
ants = p->ants;
21+
p = *list;
22+
p->ants = a->ant;
23+
q = NULL;
24+
while (p)
25+
{
26+
r = q;
27+
q = p;
2828
p = p->next;
29-
if(p)
30-
p->ants += ants;
29+
q->next = r;
3130
}
32-
ft_printf("\n");
31+
q->start = 2;
32+
*list = q;
3333
}
34+
ft_putstr_fd(RED, fd);
35+
if (color_nfun == 2)
36+
ft_putstr_fd(GREEN, fd);
37+
if (color_nfun == 3)
38+
ft_putstr_fd(BLUE, fd);
39+
if (color_nfun == 4)
40+
ft_putstr_fd(PURPLE, fd);
41+
if (color_nfun == 5)
42+
ft_putstr_fd(YELLOW, fd);
3443
void handles_path(t_path **p, t_ant *a, int max_path)
3544
{
3645
int i;
3746
int ants;
47+
int end;
48+
int start;
3849

39-
ants = 1;
50+
t_path **tmp;
51+
end = 0;
52+
tmp = NULL;
53+
ants = 0;
4054
i = 0;
41-
ft_printf("Nb ants = %d\nNb max_chemin = %d\n\n\n",a->ant, max_path);
42-
if (max_path == 1)
43-
one_path(*p,a);
44-
}
55+
start = a->ant;
56+
tmp = (t_path**)malloc(sizeof(t_path) * max_path);
57+
while(i < max_path)
58+
{
59+
reverse_list(&p[i],a);
60+
tmp[i] = p[i];
61+
i++;
62+
}
63+
i = 0;
64+
while(end <= a->ant)
65+
{
66+
ft_printf("{GRE}%d\n",p[i]->ants);
67+
while(i < max_path)
68+
{
69+
while(p[i])
70+
{
71+
if (p[i]->start == 2 && p[i]->next->ants > 0)
72+
{
73+
end++;
74+
p[i]->ants = end;
75+
ft_putstr("0;[")
76+
ft_printf("L%d-%s ",p[i]->ants,p[i]->name);
77+
if (end == a->ant)
78+
return ;
79+
// if(p[i]->ants == a->ant)
80+
// return;
81+
}
82+
else if (p[i]->next && p[i]->next->start == 1 && start > 0)
83+
{
84+
p[i]->next->ants--;
85+
start--;
86+
ants++;
87+
p[i]->ants = ants;
88+
ft_printf("L%d-%s ",p[i]->ants,p[i]->name);
89+
}
90+
else if (p[i]->next && p[i]->next->ants > 0 && p[i]->next->start != 1)
91+
{
92+
p[i]->ants = p[i]->next->ants;
93+
p[i]->next->ants = 0;
94+
ft_printf("L%d-%s ",p[i]->ants,p[i]->name);
95+
}
96+
p[i] = p[i]->next;
97+
}
98+
p[i] = tmp[i];
99+
i++;
100+
}
101+
102+
i = 0;
103+
ft_printf("\n");
104+
p[i] = tmp[i];
105+
// i++;
106+
}
107+
}

0 commit comments

Comments
 (0)