This commit is contained in:
kinou-p 2022-01-19 04:01:40 +01:00
parent bf24b5da96
commit e9fdc6a0dc
8 changed files with 141 additions and 35 deletions

View File

@ -6,11 +6,11 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/11/13 13:06:47 by apommier #+# #+# #
# Updated: 2022/01/18 05:51:26 by apommier ### ########.fr #
# Updated: 2022/01/19 03:50:25 by apommier ### ########.fr #
# #
# **************************************************************************** #
NAME = push_swap
NAME = push_swap checker
SRCS = Utils/push_swap.c \
Utils/process.c\
main.c\
@ -24,6 +24,7 @@ SRCS = Utils/push_swap.c \
OBJS = ${SRCS:.c=.o}
BONUS_C = checker_folder/main.c\
checker_folder/checker_utils.c\
checker_folder/checker_process.c\
Utils/push_swap.c \
Utils/process.c\
Utils/sorting.c\
@ -44,15 +45,16 @@ ${NAME}:${OBJS}
gcc -g ${OBJS} ${LIBFT}/libft.a
mv a.out push_swap
bonus:${BONUS_C}
bonus:${BONUS_O}
make bonus -C ${LIBFT}
gcc -g ${CFLAGS} ${LIBFT}/libft.a
gcc -g ${CFLAGS} ${BONUS_O} ${LIBFT}/libft.a
mv a.out checker
all: ${NAME}
clean:
${RM} ${OBJS}
${RM} ${BONUS_O}
make clean -C ${LIBFT}
fclean: clean

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/25 23:15:17 by apommier #+# #+# */
/* Updated: 2022/01/18 21:45:38 by apommier ### ########.fr */
/* Updated: 2022/01/19 03:53:31 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,6 +47,13 @@ t_list *ft_pa(t_list **list_a, t_list **list_b, t_slist **process);
void ft_pb(t_list **list_a, t_list **list_b, t_slist **process);
void ft_rra_rrb(t_list **list, t_slist **process, char type);
/*process fonction for checker*/
int sa_sb(t_list **list, t_slist **process, char type, int set);
int ra_rb(t_list **list, t_slist **process, char type);
int pa(t_list **list_a, t_list **list_b, t_slist **process);
int pb(t_list **list_a, t_list **list_b, t_slist **process);
int rra_rrb(t_list **list, t_slist **process, char type);
/*sort fonction*/
t_list *best_b(t_list **b, t_list *start_b, t_list *a, int best_move);
t_list *swap(t_list *a, t_list **b, t_slist **action, t_list *to_swap);
@ -77,8 +84,8 @@ int ft_strcmp(const char *s1, t_slist *str);
/*checker*/
int checker(t_slist *action, t_list **a);
void do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete);
void do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete);
int do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete);
int do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete);
t_slist *verify_list(t_slist *a);
void big_slstclear(t_slist **lst);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/18 03:31:31 by apommier #+# #+# */
/* Updated: 2022/01/18 21:59:23 by apommier ### ########.fr */
/* Updated: 2022/01/19 03:32:05 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -98,6 +98,8 @@ t_list *sort5(t_list *list, t_slist **action, t_list *b)
int is_sorted(t_list *list)
{
if (!list)
return (0);
while (list->next)
{
if (list->index > list->next->index)

Binary file not shown.

View File

@ -0,0 +1,92 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/17 11:52:37 by apommier #+# #+# */
/* Updated: 2022/01/17 11:52:37 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Utils/push_swap.h"
int sa_sb(t_list **list, t_slist **process, char type, int set)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
swap = (*list)->next->next;
(*list)->next->next = *list;
*list = (*list)->next;
(*list)->next->next = swap;
if (set)
{
if (type == 'a')
s_lstadd_back(process, new_slist("sa"));
else if (type == 'b')
s_lstadd_back(process, new_slist("sb"));
}
return (1);
}
int ra_rb(t_list **list, t_slist **process, char type)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
swap = *list;
(ft_lstlast(*list))->next = *list;
*list = (*list)->next;
swap->next = 0;
if (type == 'a')
s_lstadd_back(process, new_slist("ra"));
else if (type == 'b')
s_lstadd_back(process, new_slist("rb"));
return (1);
}
int pa(t_list **list_a, t_list **list_b, t_slist **process)
{
t_list *swap;
if (!(*list_b))
return (1);
swap = *list_b;
*list_b = (*list_b)->next;
ft_lstadd_front(list_a, swap);
s_lstadd_back(process, new_slist("pa"));
return (1);
}
int pb(t_list **list_a, t_list **list_b, t_slist **process)
{
t_list *swap;
if (!(*list_a))
return (1);
swap = *list_a;
*list_a = (*list_a)->next;
ft_lstadd_front(list_b, swap);
s_lstadd_back(process, new_slist("pb"));
return (1);
}
int rra_rrb(t_list **list, t_slist **process, char type)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
swap = ft_lstlast(*list);
ft_lstbeforelast(*list)->next = 0;
ft_lstadd_front(list, swap);
if (type == 'a')
s_lstadd_back(process, new_slist("rra"));
else if (type == 'b')
s_lstadd_back(process, new_slist("rrb"));
return (1);
}

View File

@ -6,24 +6,27 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/18 02:14:22 by apommier #+# #+# */
/* Updated: 2022/01/18 06:49:36 by apommier ### ########.fr */
/* Updated: 2022/01/19 03:42:58 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Utils/push_swap.h"
void do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete)
int do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete)
{
if (!ft_strcmp("rr\n", a))
{
if ((*lst)->next)
ft_ra_rb(lst, delete, 'a');
if ((*lst_b)->next)
ft_ra_rb(lst_b, delete, 'b');
if (!ra_rb(lst, delete, 'a'))
return (0);
if (!ra_rb(lst_b, delete, 'b'))
return (0);
}
if (!ft_strcmp("rrr\n", a))
{
ft_rra_rrb(lst, delete, 'a');
ft_rra_rrb(lst_b, delete, 'a');
if (!rra_rrb(lst, delete, 'a'))
return (0);
if (!rra_rrb(lst_b, delete, 'a'))
return (0);
}
return (1);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/17 21:29:45 by apommier #+# #+# */
/* Updated: 2022/01/18 06:49:49 by apommier ### ########.fr */
/* Updated: 2022/01/19 03:44:06 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -50,26 +50,26 @@ t_slist *verify_list(t_slist *a)
return (start);
}
void do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete)
int do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete)
{
if (!ft_strcmp("pa\n", a))
ft_pa(lst, lst_b, &delete);
else if (!ft_strcmp("pb\n", a))
ft_pb(lst, lst_b, &delete);
else if (!ft_strcmp("sa\n", a))
ft_sa_sb(lst, &delete, 'a', 0);
else if (!ft_strcmp("sb\n", a))
ft_sa_sb(lst_b, &delete, 'b', 0);
else if (!ft_strcmp("ra\n", a))
ft_ra_rb(lst, &delete, 'a');
else if (!ft_strcmp("rb\n", a))
ft_ra_rb(lst_b, &delete, 'b');
else if (!ft_strcmp("rra\n", a))
ft_rra_rrb(lst, &delete, 'a');
else if (!ft_strcmp("rrb\n", a))
ft_rra_rrb(lst_b, &delete, 'b');
if (!ft_strcmp("pa\n", a) && !pa(lst, lst_b, &delete))
return (0);
else if (!ft_strcmp("pb\n", a) && !pb(lst, lst_b, &delete))
return (0);
else if (!ft_strcmp("sa\n", a) && !sa_sb(lst, &delete, 'a', 0))
return (0);
else if (!ft_strcmp("sb\n", a) && !sa_sb(lst, &delete, 'a', 0))
return (0);
else if (!ft_strcmp("ra\n", a) && !ra_rb(lst, &delete, 'a'))
return (0);
else if (!ft_strcmp("rb\n", a) && !ra_rb(lst_b, &delete, 'b'))
return (0);
else if (!ft_strcmp("rra\n", a) && !rra_rrb(lst, &delete, 'a'))
return (0);
else if (!ft_strcmp("rrb\n", a) && !rra_rrb(lst_b, &delete, 'b'))
return (0);
else
do_move2(lst, lst_b, a, &delete);
return (do_move2(lst, lst_b, a, &delete));
s_lstclear(&delete);
}

Binary file not shown.