mirror of
https://github.com/LucasCodeur/alcu.git
synced 2026-04-28 17:44:34 +02:00
end of project
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -52,9 +52,11 @@ $(LIBFT):
|
||||
|
||||
clean:
|
||||
rm -rf $(P_OBJ)
|
||||
$(MAKE) -C $(P_LIBFT) clean
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
$(MAKE) -C $(P_LIBFT) fclean
|
||||
|
||||
re: fclean all
|
||||
|
||||
|
||||
@@ -1,716 +0,0 @@
|
||||
[
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/main.c",
|
||||
"-o",
|
||||
".obj/main.o"
|
||||
],
|
||||
"file": "src/main.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/fill_array.c",
|
||||
"-o",
|
||||
".obj/fill_array.o"
|
||||
],
|
||||
"file": "src/fill_array.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/check_input.c",
|
||||
"-o",
|
||||
".obj/check_input.o"
|
||||
],
|
||||
"file": "src/check_input.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/get_next_line.c",
|
||||
"-o",
|
||||
".obj/get_next_line.o"
|
||||
],
|
||||
"file": "src/get_next_line.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/print_board.c",
|
||||
"-o",
|
||||
".obj/print_board.o"
|
||||
],
|
||||
"file": "src/print_board.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/ai.c",
|
||||
"-o",
|
||||
".obj/ai.o"
|
||||
],
|
||||
"file": "src/ai.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/game.c",
|
||||
"-o",
|
||||
".obj/game.o"
|
||||
],
|
||||
"file": "src/game.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-MMD",
|
||||
"-Iinc/",
|
||||
"-Ilibft/",
|
||||
"-c",
|
||||
"src/vector.c",
|
||||
"-o",
|
||||
".obj/vector.o"
|
||||
],
|
||||
"file": "src/vector.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_isdigit.o",
|
||||
"-c",
|
||||
"ft_isdigit.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_isdigit.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_isalpha.o",
|
||||
"-c",
|
||||
"ft_isalpha.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_isalpha.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_isalnum.o",
|
||||
"-c",
|
||||
"ft_isalnum.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_isalnum.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_isascii.o",
|
||||
"-c",
|
||||
"ft_isascii.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_isascii.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_isprint.o",
|
||||
"-c",
|
||||
"ft_isprint.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_isprint.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strlen.o",
|
||||
"-c",
|
||||
"ft_strlen.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strlen.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_memset.o",
|
||||
"-c",
|
||||
"ft_memset.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_memset.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_bzero.o",
|
||||
"-c",
|
||||
"ft_bzero.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_bzero.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_memcpy.o",
|
||||
"-c",
|
||||
"ft_memcpy.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_memcpy.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_memmove.o",
|
||||
"-c",
|
||||
"ft_memmove.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_memmove.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strlcpy.o",
|
||||
"-c",
|
||||
"ft_strlcpy.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strlcpy.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strlcat.o",
|
||||
"-c",
|
||||
"ft_strlcat.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strlcat.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_toupper.o",
|
||||
"-c",
|
||||
"ft_toupper.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_toupper.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_tolower.o",
|
||||
"-c",
|
||||
"ft_tolower.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_tolower.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strchr.o",
|
||||
"-c",
|
||||
"ft_strchr.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strchr.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strrchr.o",
|
||||
"-c",
|
||||
"ft_strrchr.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strrchr.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strncmp.o",
|
||||
"-c",
|
||||
"ft_strncmp.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strncmp.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_memcmp.o",
|
||||
"-c",
|
||||
"ft_memcmp.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_memcmp.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_memchr.o",
|
||||
"-c",
|
||||
"ft_memchr.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_memchr.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strnstr.o",
|
||||
"-c",
|
||||
"ft_strnstr.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strnstr.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_atoi.o",
|
||||
"-c",
|
||||
"ft_atoi.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_atoi.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_calloc.o",
|
||||
"-c",
|
||||
"ft_calloc.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_calloc.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strdup.o",
|
||||
"-c",
|
||||
"ft_strdup.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strdup.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_substr.o",
|
||||
"-c",
|
||||
"ft_substr.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_substr.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strjoin.o",
|
||||
"-c",
|
||||
"ft_strjoin.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strjoin.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strtrim.o",
|
||||
"-c",
|
||||
"ft_strtrim.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strtrim.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_split.o",
|
||||
"-c",
|
||||
"ft_split.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_split.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_itoa.o",
|
||||
"-c",
|
||||
"ft_itoa.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_itoa.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_strmapi.o",
|
||||
"-c",
|
||||
"ft_strmapi.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_strmapi.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_striteri.o",
|
||||
"-c",
|
||||
"ft_striteri.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_striteri.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_putchar_fd.o",
|
||||
"-c",
|
||||
"ft_putchar_fd.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_putchar_fd.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_putstr_fd.o",
|
||||
"-c",
|
||||
"ft_putstr_fd.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_putstr_fd.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_putendl_fd.o",
|
||||
"-c",
|
||||
"ft_putendl_fd.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_putendl_fd.c"
|
||||
},
|
||||
{
|
||||
"directory": "/home/lud-adam/Documents/rush/libft",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-o",
|
||||
"ft_putnbr_fd.o",
|
||||
"-c",
|
||||
"ft_putnbr_fd.c",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Ilibft.h"
|
||||
],
|
||||
"file": "ft_putnbr_fd.c"
|
||||
}
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+9
-9
@@ -11,19 +11,19 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ALCU_H
|
||||
# define ALCU_H
|
||||
#define ALCU_H
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
char *read_file(int fd);
|
||||
bool check_input(t_vector* lines);
|
||||
void print_board(int *game_state, size_t nb_line);
|
||||
bool fill_vector(t_vector* lines, int fd);
|
||||
int ai(int *gamestate, int nb_line);
|
||||
void game(int *lines, int size);
|
||||
int* fill_array(t_vector* lines, int* size);
|
||||
char *read_file(int fd);
|
||||
bool check_input(t_vector *lines);
|
||||
void print_board(int *game_state, size_t nb_line);
|
||||
bool fill_vector(t_vector *lines, int fd);
|
||||
int ai(int *gamestate, int nb_line);
|
||||
bool game(int *lines, int size);
|
||||
int *fill_array(t_vector *lines, int *size);
|
||||
|
||||
#endif
|
||||
|
||||
+25
-22
@@ -11,36 +11,39 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VECTOR_H
|
||||
# define VECTOR_H
|
||||
#define VECTOR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#define VECTOR_INIT_CAPACITY 6
|
||||
#define UNDEFINE -1
|
||||
#define UNDEFINE -1
|
||||
#define SUCCESS 0
|
||||
|
||||
#define VECTOR_INIT(vec) t_vector vec;\
|
||||
vector_init(&vec)
|
||||
|
||||
typedef struct s_vector_list
|
||||
{
|
||||
void **items;
|
||||
int capacity;
|
||||
int total;
|
||||
} t_vector_list;
|
||||
typedef struct s_vector_list {
|
||||
void **items;
|
||||
int capacity;
|
||||
int total;
|
||||
} t_vector_list;
|
||||
|
||||
typedef struct s_vector t_vector;
|
||||
|
||||
struct s_vector
|
||||
{
|
||||
t_vector_list vector_list; /**< List to store vector elements */
|
||||
int (*pfVectorTotal)(t_vector *); /**< Retrieves the total number of elements in the vector */
|
||||
int (*pfVectorResize)(t_vector *, int); /**< Resizes the vector to a new capacity */
|
||||
int (*pfVectorAdd)(t_vector *, void *); /**< Adds an element to the vector */
|
||||
int (*pfVectorSet)(t_vector *, int, void *); /**< Sets an element at a specific index in the vector */
|
||||
void *(*pfVectorGet)(t_vector *, int); /**< Retrieves an element from the vector */
|
||||
int (*pfVectorDelete)(t_vector *, int); /**< Deletes an element from the vector */
|
||||
int (*pfVectorFree)(t_vector *); /**< Frees the memory allocated for the vector */
|
||||
struct s_vector {
|
||||
t_vector_list vector_list; /**< List to store vector elements */
|
||||
int (*pfVectorTotal)(
|
||||
t_vector *); /**< Retrieves the total number of elements in the vector */
|
||||
int (*pfVectorResize)(t_vector *,
|
||||
int); /**< Resizes the vector to a new capacity */
|
||||
int (*pfVectorAdd)(t_vector *, void *); /**< Adds an element to the vector */
|
||||
int (*pfVectorSet)(
|
||||
t_vector *, int,
|
||||
void *); /**< Sets an element at a specific index in the vector */
|
||||
void *(*pfVectorGet)(t_vector *,
|
||||
int); /**< Retrieves an element from the vector */
|
||||
int (*pfVectorDelete)(t_vector *,
|
||||
int); /**< Deletes an element from the vector */
|
||||
int (*pfVectorFree)(
|
||||
t_vector *); /**< Frees the memory allocated for the vector */
|
||||
};
|
||||
|
||||
void vector_init(t_vector* v);
|
||||
bool vector_init(t_vector *v);
|
||||
|
||||
#endif
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "usage: bash map_gen.sh [size] [range]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
unset var
|
||||
for i in $( seq 1 $1 )
|
||||
do
|
||||
var+="\n$(( RANDOM % $2 + 1))"
|
||||
done
|
||||
var="${var}\n";
|
||||
echo -e $var | tail -n +2
|
||||
|
||||
+34
-28
@@ -15,37 +15,43 @@
|
||||
#include "get_next_line.h"
|
||||
|
||||
#include "alcu.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
bool fill_vector(t_vector* lines, int fd)
|
||||
{
|
||||
char *line;
|
||||
bool fill_vector(t_vector *lines, int fd) {
|
||||
char *line;
|
||||
|
||||
line = get_next_line(fd);
|
||||
while (line != NULL)
|
||||
{
|
||||
lines->pfVectorAdd(lines, line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
return (true);
|
||||
line = get_next_line(fd);
|
||||
if (!line)
|
||||
return (false);
|
||||
while (line != NULL) {
|
||||
if (!ft_strncmp("\n", line, ft_strlen(line))) {
|
||||
free(line);
|
||||
return (true);
|
||||
}
|
||||
if (lines->pfVectorAdd(lines, line) == UNDEFINE) {
|
||||
free(line);
|
||||
return (false);
|
||||
}
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
int* fill_array(t_vector* lines, int* size)
|
||||
{
|
||||
int* res;
|
||||
int i;
|
||||
char* line;
|
||||
int *fill_array(t_vector *lines, int *size) {
|
||||
int *res;
|
||||
int i;
|
||||
char *line;
|
||||
|
||||
i = 0;
|
||||
line = NULL;
|
||||
*size = lines->pfVectorTotal(lines);
|
||||
res = malloc(sizeof(int) * *size);
|
||||
if (!res)
|
||||
return (NULL);
|
||||
while (i < *size)
|
||||
{
|
||||
line = (char*)lines->pfVectorGet(lines, i);
|
||||
res[i] = ft_atoi(line);
|
||||
i++;
|
||||
}
|
||||
return (res);
|
||||
i = 0;
|
||||
line = NULL;
|
||||
*size = lines->pfVectorTotal(lines);
|
||||
res = malloc(sizeof(int) * *size);
|
||||
if (!res)
|
||||
return (NULL);
|
||||
while (i < *size) {
|
||||
line = (char *)lines->pfVectorGet(lines, i);
|
||||
res[i] = ft_atoi(line);
|
||||
i++;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
+78
-89
@@ -14,105 +14,94 @@
|
||||
#include "alcu.h"
|
||||
#include "get_next_line.h"
|
||||
|
||||
static int check_char_int(char *str)
|
||||
{
|
||||
int i;
|
||||
static int check_char_int(char *str) {
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (str[++i] && i < 100)
|
||||
if (!(str[i] >= '0' && str[i] <= '9') && str[i] != '\n')
|
||||
return (0);
|
||||
return (1);
|
||||
i = -1;
|
||||
while (str[++i] && i < 100)
|
||||
if (!(str[i] >= '0' && str[i] <= '9') && str[i] != '\n')
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int play_choice(int *line, int choice)
|
||||
{
|
||||
if (choice > 0 && choice < 4)
|
||||
{
|
||||
if (choice > *line)
|
||||
{
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
return (0);
|
||||
}
|
||||
*line -= choice;
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
return (0);
|
||||
}
|
||||
static int play_choice(int *line, int choice) {
|
||||
if (choice > 0 && choice < 4) {
|
||||
if (choice > *line) {
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
return (0);
|
||||
}
|
||||
*line -= choice;
|
||||
return (1);
|
||||
} else {
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
static void player_turn(int *line)
|
||||
{
|
||||
char *temp;
|
||||
int choice;
|
||||
static bool player_turn(int *line) {
|
||||
char *temp;
|
||||
int choice;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ft_putstr_fd("\nPlease choose between 1 and 3 items\n", 1);
|
||||
temp = get_next_line(0);
|
||||
if (temp && ft_strlen(temp) > 0)
|
||||
{
|
||||
if (!check_char_int(temp))
|
||||
{
|
||||
free(temp);
|
||||
continue ;
|
||||
}
|
||||
choice = ft_atoi(temp);
|
||||
if (play_choice(line, choice))
|
||||
break ;
|
||||
}
|
||||
else
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
if (temp)
|
||||
free(temp);
|
||||
}
|
||||
if (temp)
|
||||
free(temp);
|
||||
while (1) {
|
||||
ft_putstr_fd("\nPlease choose between 1 and 3 items\n", 1);
|
||||
temp = get_next_line(0);
|
||||
if (!temp)
|
||||
return (false);
|
||||
if (temp && ft_strlen(temp) > 0) {
|
||||
if (!check_char_int(temp)) {
|
||||
free(temp);
|
||||
continue;
|
||||
}
|
||||
choice = ft_atoi(temp);
|
||||
if (play_choice(line, choice))
|
||||
break;
|
||||
} else
|
||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
||||
if (temp)
|
||||
free(temp);
|
||||
}
|
||||
if (temp)
|
||||
free(temp);
|
||||
return (true);
|
||||
}
|
||||
|
||||
static void play_turns(int *lines, int i, int *ai_turn, int size)
|
||||
{
|
||||
int choice;
|
||||
static bool play_turns(int *lines, int i, int *ai_turn, int size) {
|
||||
int choice;
|
||||
|
||||
while (lines[i] != 0)
|
||||
{
|
||||
ft_putstr_fd("\n------------------------------\n", 1);
|
||||
if (!*ai_turn)
|
||||
{
|
||||
print_board(lines, size);
|
||||
player_turn(&lines[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print_board(lines, size);
|
||||
ft_putstr_fd("\n", 1);
|
||||
choice = ai(lines, size);
|
||||
ft_putstr_fd("AI play ", 1);
|
||||
ft_putnbr_fd(choice, 1);
|
||||
ft_putstr_fd("\n", 1);
|
||||
lines[i] -= choice;
|
||||
}
|
||||
*ai_turn = *ai_turn == 0;
|
||||
}
|
||||
while (lines[i] != 0) {
|
||||
ft_putstr_fd("\n------------------------------\n", 1);
|
||||
if (!*ai_turn) {
|
||||
print_board(lines, size);
|
||||
if (player_turn(&lines[i]) == false)
|
||||
return (false);
|
||||
} else {
|
||||
print_board(lines, size);
|
||||
ft_putstr_fd("\n", 1);
|
||||
choice = ai(lines, size);
|
||||
ft_putstr_fd("AI play ", 1);
|
||||
ft_putnbr_fd(choice, 1);
|
||||
ft_putstr_fd("\n", 1);
|
||||
lines[i] -= choice;
|
||||
}
|
||||
*ai_turn = *ai_turn == 0;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
void game(int *lines, int size)
|
||||
{
|
||||
int ai_turn;
|
||||
int i;
|
||||
bool game(int *lines, int size) {
|
||||
int ai_turn;
|
||||
int i;
|
||||
|
||||
ai_turn = 1;
|
||||
i = size - 1;
|
||||
while (i >= 0)
|
||||
{
|
||||
play_turns(lines, i, &ai_turn, size);
|
||||
i--;
|
||||
}
|
||||
if (!ai_turn)
|
||||
ft_putstr_fd("AI win ! It will replace you\n", 1);
|
||||
else
|
||||
ft_putstr_fd("You win ! Well done\n", 1);
|
||||
ai_turn = 1;
|
||||
i = size - 1;
|
||||
while (i >= 0) {
|
||||
if (play_turns(lines, i, &ai_turn, size) == false)
|
||||
return (false);
|
||||
i--;
|
||||
}
|
||||
if (!ai_turn)
|
||||
ft_putstr_fd("AI win ! It will replace you\n", 1);
|
||||
else
|
||||
ft_putstr_fd("You win ! Well done\n", 1);
|
||||
return (true);
|
||||
}
|
||||
|
||||
+92
-105
@@ -10,129 +10,116 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft/libft.h"
|
||||
#include "get_next_line.h"
|
||||
#include "../libft/libft.h"
|
||||
|
||||
size_t ft_strlen_with_c(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
size_t ft_strlen_with_c(char *str, char c) {
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i] && str[i] != c)
|
||||
i++;
|
||||
return (i);
|
||||
i = 0;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i] && str[i] != c)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
size_t detect_newline(char *str)
|
||||
{
|
||||
size_t i;
|
||||
size_t detect_newline(char *str) {
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == '\n')
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
i = 0;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i]) {
|
||||
if (str[i] == '\n')
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void fill_line(char *line, char *c_remaining, char *src, size_t *index)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
static void fill_line(char *line, char *c_remaining, char *src, size_t *index) {
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (c_remaining && c_remaining[i])
|
||||
{
|
||||
line[i] = c_remaining[i];
|
||||
i++;
|
||||
}
|
||||
while (src[j] && src[j] != '\n')
|
||||
{
|
||||
line[i + j] = src[j];
|
||||
src[j] = 0;
|
||||
j++;
|
||||
}
|
||||
if (src[j] == '\n')
|
||||
line[i + j] = '\n';
|
||||
*index = j;
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (c_remaining && c_remaining[i]) {
|
||||
line[i] = c_remaining[i];
|
||||
i++;
|
||||
}
|
||||
while (src[j] && src[j] != '\n') {
|
||||
line[i + j] = src[j];
|
||||
src[j] = 0;
|
||||
j++;
|
||||
}
|
||||
if (src[j] == '\n')
|
||||
line[i + j] = '\n';
|
||||
*index = j;
|
||||
}
|
||||
|
||||
char *build_line(char *src, char *c_remaining, size_t *index)
|
||||
{
|
||||
char *line;
|
||||
size_t size;
|
||||
size_t is_jump;
|
||||
char *build_line(char *src, char *c_remaining, size_t *index) {
|
||||
char *line;
|
||||
size_t size;
|
||||
size_t is_jump;
|
||||
|
||||
is_jump = detect_newline(src);
|
||||
size = ft_strlen_with_c(src, '\n') + ft_strlen_with_c(c_remaining, '\0')
|
||||
+ is_jump + 1;
|
||||
line = ft_calloc(size, sizeof(char));
|
||||
if (!line)
|
||||
{
|
||||
free(c_remaining);
|
||||
return (NULL);
|
||||
}
|
||||
if (!src)
|
||||
return (NULL);
|
||||
fill_line(line, c_remaining, src, index);
|
||||
if (c_remaining)
|
||||
free(c_remaining);
|
||||
return (line);
|
||||
is_jump = detect_newline(src);
|
||||
size = ft_strlen_with_c(src, '\n') + ft_strlen_with_c(c_remaining, '\0') +
|
||||
is_jump + 1;
|
||||
line = ft_calloc(size, sizeof(char));
|
||||
if (!line) {
|
||||
free(c_remaining);
|
||||
return (NULL);
|
||||
}
|
||||
if (!src)
|
||||
return (NULL);
|
||||
fill_line(line, c_remaining, src, index);
|
||||
if (c_remaining)
|
||||
free(c_remaining);
|
||||
return (line);
|
||||
}
|
||||
|
||||
static void read_file(int fd, char *buffer, ssize_t *nb_read)
|
||||
{
|
||||
*nb_read = read(fd, buffer, BUFFER_SIZE);
|
||||
if (*nb_read < 0)
|
||||
return ;
|
||||
buffer[*nb_read] = '\0';
|
||||
static void read_file(int fd, char *buffer, ssize_t *nb_read) {
|
||||
*nb_read = read(fd, buffer, BUFFER_SIZE);
|
||||
if (*nb_read < 0)
|
||||
return;
|
||||
buffer[*nb_read] = '\0';
|
||||
}
|
||||
|
||||
static char *get_the_line(int fd, char *buffer)
|
||||
{
|
||||
char *line;
|
||||
size_t i;
|
||||
ssize_t nb_read;
|
||||
static char *get_the_line(int fd, char *buffer) {
|
||||
char *line;
|
||||
size_t i;
|
||||
ssize_t nb_read;
|
||||
|
||||
i = 0;
|
||||
nb_read = 0;
|
||||
line = NULL;
|
||||
if (buffer[0] != '\0')
|
||||
{
|
||||
line = build_line(buffer, NULL, &i);
|
||||
if (!line)
|
||||
return (NULL);
|
||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||
}
|
||||
while (detect_newline(line) == 0)
|
||||
{
|
||||
read_file(fd, buffer, &nb_read);
|
||||
if (nb_read < 0)
|
||||
return (free(line), NULL);
|
||||
if (nb_read == 0)
|
||||
break ;
|
||||
line = build_line(buffer, line, &i);
|
||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||
}
|
||||
return (line);
|
||||
i = 0;
|
||||
nb_read = 0;
|
||||
line = NULL;
|
||||
if (buffer[0] != '\0') {
|
||||
line = build_line(buffer, NULL, &i);
|
||||
if (!line)
|
||||
return (NULL);
|
||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||
}
|
||||
while (detect_newline(line) == 0) {
|
||||
read_file(fd, buffer, &nb_read);
|
||||
if (nb_read < 0)
|
||||
return (free(line), NULL);
|
||||
if (nb_read == 0)
|
||||
break;
|
||||
line = build_line(buffer, line, &i);
|
||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char buffer[BUFFER_SIZE + 1] = "";
|
||||
char *line;
|
||||
char *get_next_line(int fd) {
|
||||
static char buffer[BUFFER_SIZE + 1] = "";
|
||||
char *line;
|
||||
|
||||
if (fd < 0 || BUFFER_SIZE <= 0)
|
||||
return (NULL);
|
||||
line = get_the_line(fd, buffer);
|
||||
if (!line)
|
||||
return (NULL);
|
||||
return (line);
|
||||
if (fd < 0 || BUFFER_SIZE <= 0)
|
||||
return (NULL);
|
||||
line = get_the_line(fd, buffer);
|
||||
if (!line)
|
||||
return (NULL);
|
||||
return (line);
|
||||
}
|
||||
|
||||
+46
-43
@@ -16,51 +16,54 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int get_fd(int argc, char **argv)
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
return (open(argv[1], O_RDONLY));
|
||||
}
|
||||
else if (argc == 1)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
static int get_fd(int argc, char **argv) {
|
||||
if (argc == 2) {
|
||||
return (open(argv[1], O_RDONLY));
|
||||
} else if (argc == 1)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
int size;
|
||||
int* lines_int;
|
||||
VECTOR_INIT(lines);
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
fd = get_fd(argc, argv);
|
||||
lines_int = NULL;
|
||||
size = 0;
|
||||
if (fd < 0)
|
||||
{
|
||||
ft_putstr_fd("ERROR", 2);
|
||||
return (1);
|
||||
}
|
||||
fill_vector(&lines, fd);
|
||||
if (check_input(&lines) == false)
|
||||
{
|
||||
lines.pfVectorFree(&lines);
|
||||
ft_putstr_fd("ERROR", 2);
|
||||
return (1);
|
||||
int fd;
|
||||
int size;
|
||||
int *lines_int;
|
||||
t_vector lines;
|
||||
|
||||
}
|
||||
lines_int = fill_array(&lines, &size);
|
||||
if (!lines_int)
|
||||
{
|
||||
lines.pfVectorFree(&lines);
|
||||
ft_putstr_fd("ERROR", 2);
|
||||
return (1);
|
||||
}
|
||||
game(lines_int, size);
|
||||
close(fd);
|
||||
free(lines_int);
|
||||
lines.pfVectorFree(&lines);
|
||||
return (0);
|
||||
if (vector_init(&lines) == false) {
|
||||
ft_putstr_fd("ERROR\n", 2);
|
||||
return (1);
|
||||
}
|
||||
fd = get_fd(argc, argv);
|
||||
lines_int = NULL;
|
||||
size = 0;
|
||||
if (fd < 0 || fill_vector(&lines, fd) == false) {
|
||||
lines.pfVectorFree(&lines);
|
||||
ft_putstr_fd("ERROR\n", 2);
|
||||
return (1);
|
||||
}
|
||||
if (check_input(&lines) == false) {
|
||||
lines.pfVectorFree(&lines);
|
||||
ft_putstr_fd("ERROR\n", 2);
|
||||
return (1);
|
||||
}
|
||||
lines_int = fill_array(&lines, &size);
|
||||
lines.pfVectorFree(&lines);
|
||||
if (!lines_int) {
|
||||
lines.pfVectorFree(&lines);
|
||||
ft_putstr_fd("ERROR\n", 2);
|
||||
return (1);
|
||||
}
|
||||
close(fd);
|
||||
if (open("/dev/tty", O_RDONLY) < 0 || game(lines_int, size) == false) {
|
||||
free(lines_int);
|
||||
ft_putstr_fd("ERROR\n", 2);
|
||||
return (1);
|
||||
}
|
||||
if (fd != 0)
|
||||
close(fd);
|
||||
free(lines_int);
|
||||
return (0);
|
||||
}
|
||||
|
||||
+94
-116
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "vector.h"
|
||||
#include "libft.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -23,140 +24,117 @@ int vector_delete(t_vector *v, int index);
|
||||
int vector_free(t_vector *v);
|
||||
int vector_total(t_vector *v);
|
||||
|
||||
void vector_init(t_vector *v)
|
||||
{
|
||||
v->pfVectorTotal = vector_total;
|
||||
v->pfVectorResize = vector_resize;
|
||||
v->pfVectorAdd = vector_push_back;
|
||||
v->pfVectorSet = vector_set;
|
||||
v->pfVectorGet = vector_get;
|
||||
v->pfVectorFree = vector_free;
|
||||
v->pfVectorDelete = vector_delete;
|
||||
v->vector_list.capacity = VECTOR_INIT_CAPACITY;
|
||||
v->vector_list.total = 0;
|
||||
v->vector_list.items = malloc(sizeof(void *) * v->vector_list.capacity);
|
||||
if (!v->vector_list.items)
|
||||
{
|
||||
ft_putstr_fd("Memory allocation failed in vector_init\n", 2);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
bool vector_init(t_vector *v) {
|
||||
v->pfVectorTotal = vector_total;
|
||||
v->pfVectorResize = vector_resize;
|
||||
v->pfVectorAdd = vector_push_back;
|
||||
v->pfVectorSet = vector_set;
|
||||
v->pfVectorGet = vector_get;
|
||||
v->pfVectorFree = vector_free;
|
||||
v->pfVectorDelete = vector_delete;
|
||||
v->vector_list.capacity = VECTOR_INIT_CAPACITY;
|
||||
v->vector_list.total = 0;
|
||||
v->vector_list.items = malloc(sizeof(void *) * v->vector_list.capacity);
|
||||
if (!v->vector_list.items) {
|
||||
ft_putstr_fd("Memory allocation failed in vector_init\n", 2);
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
int vector_total(t_vector *v)
|
||||
{
|
||||
int totalCount = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
totalCount = v->vector_list.total;
|
||||
}
|
||||
return totalCount;
|
||||
int vector_total(t_vector *v) {
|
||||
int totalCount = UNDEFINE;
|
||||
if (v) {
|
||||
totalCount = v->vector_list.total;
|
||||
}
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
int vector_resize(t_vector *v, int capacity)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
void **items_copy = malloc(sizeof(void *) * capacity);
|
||||
if (!items_copy)
|
||||
return (status);
|
||||
ft_memcpy(items_copy, v->vector_list.items, sizeof(void *) * v->pfVectorTotal(v));
|
||||
if (items_copy)
|
||||
{
|
||||
free(v->vector_list.items);
|
||||
v->vector_list.items = items_copy;
|
||||
v->vector_list.capacity = capacity;
|
||||
status = SUCCESS;
|
||||
}
|
||||
int vector_resize(t_vector *v, int capacity) {
|
||||
int status = UNDEFINE;
|
||||
if (v) {
|
||||
void **items_copy = malloc(sizeof(void *) * capacity);
|
||||
if (!items_copy)
|
||||
return (status);
|
||||
ft_memcpy(items_copy, v->vector_list.items,
|
||||
sizeof(void *) * v->pfVectorTotal(v));
|
||||
if (items_copy) {
|
||||
free(v->vector_list.items);
|
||||
v->vector_list.items = items_copy;
|
||||
v->vector_list.capacity = capacity;
|
||||
status = SUCCESS;
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
int vector_push_back(t_vector *v, void *item)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
if (v->vector_list.capacity == v->vector_list.total)
|
||||
{
|
||||
status = vector_resize(v, v->vector_list.capacity * 2);
|
||||
if(status != UNDEFINE)
|
||||
{
|
||||
v->vector_list.items[v->vector_list.total++] = item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
v->vector_list.items[v->vector_list.total++] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
int vector_push_back(t_vector *v, void *item) {
|
||||
int status = UNDEFINE;
|
||||
if (v) {
|
||||
if (v->vector_list.capacity == v->vector_list.total) {
|
||||
status = vector_resize(v, v->vector_list.capacity * 2);
|
||||
if (status != UNDEFINE) {
|
||||
v->vector_list.items[v->vector_list.total++] = item;
|
||||
}
|
||||
} else {
|
||||
v->vector_list.items[v->vector_list.total++] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int vector_set(t_vector *v, int index, void *item)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
if ((index >= 0) && (index < v->vector_list.total))
|
||||
{
|
||||
v->vector_list.items[index] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
int vector_set(t_vector *v, int index, void *item) {
|
||||
int status = UNDEFINE;
|
||||
if (v) {
|
||||
if ((index >= 0) && (index < v->vector_list.total)) {
|
||||
v->vector_list.items[index] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void *vector_get(t_vector *v, int index)
|
||||
{
|
||||
void *readData = NULL;
|
||||
if(v)
|
||||
{
|
||||
if ((index >= 0) && (index < v->vector_list.total))
|
||||
{
|
||||
readData = v->vector_list.items[index];
|
||||
}
|
||||
void *vector_get(t_vector *v, int index) {
|
||||
void *readData = NULL;
|
||||
if (v) {
|
||||
if ((index >= 0) && (index < v->vector_list.total)) {
|
||||
readData = v->vector_list.items[index];
|
||||
}
|
||||
return readData;
|
||||
}
|
||||
return readData;
|
||||
}
|
||||
|
||||
int vector_delete(t_vector *v, int index)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
int i = 0;
|
||||
if(v)
|
||||
{
|
||||
if ((index < 0) || (index >= v->vector_list.total))
|
||||
return status;
|
||||
v->vector_list.items[index] = NULL;
|
||||
for (i = index; (i < v->vector_list.total - 1); ++i)
|
||||
{
|
||||
v->vector_list.items[i] = v->vector_list.items[i + 1];
|
||||
v->vector_list.items[i + 1] = NULL;
|
||||
}
|
||||
v->vector_list.total--;
|
||||
if ((v->vector_list.total > 0) && ((v->vector_list.total) == (v->vector_list.capacity / 4)))
|
||||
{
|
||||
vector_resize(v, v->vector_list.capacity / 2);
|
||||
}
|
||||
status = SUCCESS;
|
||||
int vector_delete(t_vector *v, int index) {
|
||||
int status = UNDEFINE;
|
||||
int i = 0;
|
||||
if (v) {
|
||||
if ((index < 0) || (index >= v->vector_list.total))
|
||||
return status;
|
||||
v->vector_list.items[index] = NULL;
|
||||
for (i = index; (i < v->vector_list.total - 1); ++i) {
|
||||
v->vector_list.items[i] = v->vector_list.items[i + 1];
|
||||
v->vector_list.items[i + 1] = NULL;
|
||||
}
|
||||
return status;
|
||||
v->vector_list.total--;
|
||||
if ((v->vector_list.total > 0) &&
|
||||
((v->vector_list.total) == (v->vector_list.capacity / 4))) {
|
||||
vector_resize(v, v->vector_list.capacity / 2);
|
||||
}
|
||||
status = SUCCESS;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int vector_free(t_vector *v)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
int total = v->pfVectorTotal(v);
|
||||
if(v)
|
||||
{
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
void * temp = v->pfVectorGet(v, i);
|
||||
free (temp);
|
||||
}
|
||||
free(v->vector_list.items);
|
||||
int vector_free(t_vector *v) {
|
||||
int status = UNDEFINE;
|
||||
int total = v->pfVectorTotal(v);
|
||||
if (v) {
|
||||
for (int i = 0; i < total; i++) {
|
||||
void *temp = v->pfVectorGet(v, i);
|
||||
free(temp);
|
||||
}
|
||||
return status;
|
||||
free(v->vector_list.items);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user