@@ -51,7 +51,7 @@ void print_ants(int bc, int ants, char *name)
5151 ft_printf ("L%d-%s " , ants , name );
5252 ft_putstr (RESET );
5353}
54- void sort_lists (t_path * * p , int max_path )
54+ void sort_lists (t_path * * p , int * max_path )
5555{
5656 int i ;
5757 t_path * * begin ;
@@ -61,9 +61,9 @@ void sort_lists(t_path **p, int max_path)
6161 i = 0 ;
6262 begin = p ;
6363 tmp = NULL ;
64- while (i < max_path )
64+ while (i < * ( max_path ) )
6565 {
66- if (i + 1 < max_path && (p [i ]-> size > p [i + 1 ]-> size ))
66+ if (i + 1 < * ( max_path ) && (p [i ]-> size > p [i + 1 ]-> size ))
6767 {
6868 tmp = p [i ];
6969 p [i ] = p [i + 1 ];
@@ -72,6 +72,21 @@ void sort_lists(t_path **p, int max_path)
7272 }
7373 i ++ ;
7474 }
75+ i = 0 ;
76+ p = begin ;
77+ while (i < * (max_path ))
78+ {
79+ if (i + 1 < * (max_path ) && (p [i + 1 ]-> size > (p [0 ]-> size + 2 )))
80+ {
81+ * (max_path ) = i + 1 ;
82+ p [i + 1 ] = NULL ;
83+ p = begin ;
84+ return ;
85+ // free(p[i + 1]);
86+ // i = 0;
87+ }
88+ i ++ ;
89+ }
7590 p = begin ;
7691}
7792void handles_path (t_path * * p , t_ant * a , int max_path )
@@ -91,11 +106,18 @@ void handles_path(t_path **p, t_ant *a, int max_path)
91106 while (i < max_path )
92107 {
93108 reverse_list (& p [i ],a );
94- tmp [i ] = p [i ];
109+ // tmp[i] = p[i];
95110 i ++ ;
96111 }
97112 if (max_path > 1 )
98- sort_lists (p ,max_path );
113+ sort_lists (p ,& max_path );
114+ i = 0 ;
115+ ft_printf ("\n\n" );
116+ while (i <= max_path )
117+ {
118+ tmp [i ] = p [i ];
119+ i ++ ;
120+ }
99121 i = 0 ;
100122 while (end <= a -> ant )
101123 {
@@ -107,7 +129,7 @@ void handles_path(t_path **p, t_ant *a, int max_path)
107129 {
108130 end ++ ;
109131 p [i ]-> ants = end ;
110- ft_printf ("[1]" );
132+ // ft_printf("[1]");
111133 print_ants (a -> bonus_color , p [i ]-> ants ,p [i ]-> name );
112134 if (end == a -> ant )
113135 return ;
@@ -118,14 +140,14 @@ void handles_path(t_path **p, t_ant *a, int max_path)
118140 start -- ;
119141 ants ++ ;
120142 p [i ]-> ants = ants ;
121- ft_printf ("[2]" );
143+ // ft_printf("[2]");
122144 print_ants (a -> bonus_color , p [i ]-> ants ,p [i ]-> name );
123145 }
124146 else if (p [i ]-> next && p [i ]-> next -> ants > 0 && p [i ]-> next -> start != 1 )
125147 {
126148 p [i ]-> ants = p [i ]-> next -> ants ;
127149 p [i ]-> next -> ants = 0 ;
128- ft_printf ("[3]" );
150+ // ft_printf("[3]");
129151 print_ants (a -> bonus_color , p [i ]-> ants ,p [i ]-> name );
130152 }
131153 p [i ] = p [i ]-> next ;
0 commit comments