mirror of
https://github.com/LucasCodeur/alcu.git
synced 2026-04-28 17:44:34 +02:00
Compare commits
6 Commits
004b073669
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f18659cbf1 | |||
| 660614738c | |||
| 6d0a02da92 | |||
| 3e599160d8 | |||
| 4150e95378 | |||
| bf668cf5e6 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
# By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ #
|
# By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2025/07/18 12:51:21 by lud-adam #+# #+# #
|
# Created: 2025/07/18 12:51:21 by lud-adam #+# #+# #
|
||||||
# Updated: 2026/03/28 15:07:38 by lud-adam ### ########.fr #
|
# Updated: 2026/03/29 14:43:31 by lud-adam ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@@ -22,12 +22,15 @@ P_OBJ = .obj/
|
|||||||
P_INC = inc/
|
P_INC = inc/
|
||||||
P_LIBFT = libft/
|
P_LIBFT = libft/
|
||||||
|
|
||||||
SRC = main.c \
|
SRC = \
|
||||||
get_next_line.c \
|
main.c \
|
||||||
fill_array.c \
|
get_next_line.c \
|
||||||
check_input.c \
|
fill_vector.c \
|
||||||
print_board.c \
|
check_input.c \
|
||||||
ai.c
|
print_board.c \
|
||||||
|
ai.c \
|
||||||
|
game.c \
|
||||||
|
vector.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(P_SRC), $(SRC))
|
SRCS = $(addprefix $(P_SRC), $(SRC))
|
||||||
OBJS = $(patsubst $(P_SRC)%.c,$(P_OBJ)%.o,$(SRCS))
|
OBJS = $(patsubst $(P_SRC)%.c,$(P_OBJ)%.o,$(SRCS))
|
||||||
@@ -49,9 +52,11 @@ $(LIBFT):
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(P_OBJ)
|
rm -rf $(P_OBJ)
|
||||||
|
$(MAKE) -C $(P_LIBFT) clean
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
rm -f $(NAME)
|
rm -f $(NAME)
|
||||||
|
$(MAKE) -C $(P_LIBFT) fclean
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"directory": "/home/lud-adam/Documents/rush",
|
|
||||||
"arguments": [
|
|
||||||
"cc",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Werror",
|
|
||||||
"-MMD",
|
|
||||||
"-I",
|
|
||||||
"inc/",
|
|
||||||
"-c",
|
|
||||||
"src/main.c",
|
|
||||||
"-o",
|
|
||||||
".obj/main.o"
|
|
||||||
],
|
|
||||||
"file": "src/main.c"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"directory": "/home/lud-adam/Documents/rush",
|
|
||||||
"arguments": [
|
|
||||||
"cc",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Werror",
|
|
||||||
"-MMD",
|
|
||||||
"-I",
|
|
||||||
"inc/",
|
|
||||||
"-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",
|
|
||||||
"-I",
|
|
||||||
"inc/",
|
|
||||||
"-c",
|
|
||||||
"src/check_input.c",
|
|
||||||
"-o",
|
|
||||||
".obj/check_input.o"
|
|
||||||
],
|
|
||||||
"file": "src/check_input.c"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
+8
-3
@@ -6,19 +6,24 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:27:29 by lud-adam #+# #+# */
|
/* Created: 2026/03/28 13:27:29 by lud-adam #+# #+# */
|
||||||
/* Updated: 2026/03/28 15:26:01 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/29 14:58:00 by lud-adam ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef ALCU_H
|
#ifndef ALCU_H
|
||||||
#define ALCU_H
|
#define ALCU_H
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
char *read_file(int fd);
|
char *read_file(int fd);
|
||||||
int check_input(int fd);
|
bool check_input(t_vector *lines);
|
||||||
void print_board(int *game_state, size_t nb_line);
|
void print_board(int *game_state, size_t nb_line);
|
||||||
int *fill_array(int fd, int size);
|
bool fill_vector(t_vector *lines, int fd);
|
||||||
int ai(int *gamestate, int nb_line);
|
int ai(int *gamestate, int nb_line);
|
||||||
|
bool game(int *lines, int size);
|
||||||
|
int *fill_array(t_vector *lines, int *size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* vector.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/29 14:24:01 by lud-adam #+# #+# */
|
||||||
|
/* Updated: 2026/03/29 14:40:21 by lud-adam ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef VECTOR_H
|
||||||
|
#define VECTOR_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#define VECTOR_INIT_CAPACITY 6
|
||||||
|
#define UNDEFINE -1
|
||||||
|
#define SUCCESS 0
|
||||||
|
|
||||||
|
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 */
|
||||||
|
};
|
||||||
|
|
||||||
|
bool vector_init(t_vector *v);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lltoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/11/07 13:06:35 by dgaillet #+# #+# */
|
|
||||||
/* Updated: 2025/12/07 12:29:25 by dgaillet ### ########lyon.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t count_digits(long long n)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
if (n <= 0)
|
|
||||||
size++;
|
|
||||||
while (n)
|
|
||||||
{
|
|
||||||
n /= 10;
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insert_char(char *str, unsigned long long nbr, size_t index)
|
|
||||||
{
|
|
||||||
while (nbr)
|
|
||||||
{
|
|
||||||
str[index--] = nbr % 10 + '0';
|
|
||||||
nbr /= 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_lltoa(long long n)
|
|
||||||
{
|
|
||||||
unsigned long long nbr;
|
|
||||||
char *str;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
nbr = n;
|
|
||||||
if (n < 0)
|
|
||||||
nbr = n * -1;
|
|
||||||
size = count_digits(n);
|
|
||||||
str = malloc(sizeof(char) * (size + 1));
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
str[size] = '\0';
|
|
||||||
if (nbr == 0)
|
|
||||||
str[0] = '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
str[0] = '-';
|
|
||||||
insert_char(str, nbr, size - 1);
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
+6
-9
@@ -12,14 +12,11 @@
|
|||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
size_t ft_strlen(char *str, char c)
|
size_t ft_strlen(const char *s) {
|
||||||
{
|
size_t i;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!str)
|
while (s[i])
|
||||||
return (0);
|
i++;
|
||||||
while (str[i] && str[i] != c)
|
return (i);
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
}
|
||||||
|
|||||||
-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
|
|
||||||
|
|
||||||
@@ -6,57 +6,68 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 17:22:33 by dgaillet #+# #+# */
|
/* Created: 2026/03/28 17:22:33 by dgaillet #+# #+# */
|
||||||
/* Updated: 2026/03/28 17:22:35 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/03/28 20:51:49 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "alcu.h"
|
#include "alcu.h"
|
||||||
|
|
||||||
static int best_to_take(int prev_should_start, int line) {
|
static int best_to_take(int prev_should_start, int line)
|
||||||
int best;
|
{
|
||||||
|
int best;
|
||||||
|
|
||||||
if (prev_should_start)
|
if (prev_should_start)
|
||||||
best = 2;
|
best = 2;
|
||||||
else
|
else
|
||||||
best = 1;
|
best = 1;
|
||||||
while (best <= line - 4) {
|
while (best <= line - 4)
|
||||||
best += 4;
|
{
|
||||||
}
|
best += 4;
|
||||||
return (best);
|
}
|
||||||
|
return (best);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_play(int prev_should_start, int line) {
|
static int to_play(int prev_should_start, int line)
|
||||||
int goal;
|
{
|
||||||
goal = best_to_take(prev_should_start, line);
|
int goal;
|
||||||
if (line - goal < 3) {
|
|
||||||
return (line - goal) + 1;
|
goal = best_to_take(prev_should_start, line);
|
||||||
} else {
|
if (line - goal < 3)
|
||||||
return (1);
|
{
|
||||||
}
|
return ((line - goal) + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int should_start(int prev_should_start, int line) {
|
static int should_start(int prev_should_start, int line)
|
||||||
if (prev_should_start && line == 1)
|
{
|
||||||
return (!prev_should_start);
|
if (prev_should_start && line == 1)
|
||||||
if (prev_should_start)
|
return (!prev_should_start);
|
||||||
return (line % 4 != 1);
|
if (prev_should_start)
|
||||||
else
|
return (line % 4 != 1);
|
||||||
return (line % 4 != 0);
|
else
|
||||||
|
return (line % 4 != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ai(int *gamestate, int nb_line) {
|
int ai(int *gamestate, int nb_line)
|
||||||
int prev_should_start;
|
{
|
||||||
int i;
|
int prev_should_start;
|
||||||
|
int i;
|
||||||
|
|
||||||
prev_should_start = 0;
|
prev_should_start = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (++i < nb_line && gamestate[i] != 0) {
|
while (++i < nb_line && gamestate[i] != 0)
|
||||||
if (i == nb_line - 1 || gamestate[i + 1] == 0) {
|
{
|
||||||
if (gamestate[i] == 1)
|
if (i == nb_line - 1 || gamestate[i + 1] == 0)
|
||||||
return (1);
|
{
|
||||||
return (to_play(prev_should_start, gamestate[i]));
|
if (gamestate[i] == 1)
|
||||||
}
|
return (1);
|
||||||
prev_should_start = should_start(prev_should_start, gamestate[i]);
|
return (to_play(prev_should_start, gamestate[i]));
|
||||||
}
|
}
|
||||||
return (1);
|
prev_should_start = should_start(prev_should_start, gamestate[i]);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-22
@@ -6,34 +6,37 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:01:37 by dgaillet #+# #+# */
|
/* Created: 2026/03/28 13:01:37 by dgaillet #+# #+# */
|
||||||
/* Updated: 2026/03/28 16:05:37 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/28 20:52:29 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../libft/libft.h"
|
||||||
|
#include "get_next_line.h"
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "../inc/get_next_line.h"
|
bool check_input(t_vector* lines)
|
||||||
#include "../libft/libft.h"
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
char* line;
|
||||||
|
|
||||||
int check_input(int fd) {
|
j = 0;
|
||||||
int i;
|
line = NULL;
|
||||||
int j;
|
while (j < lines->pfVectorTotal(lines))
|
||||||
char *line = NULL;
|
{
|
||||||
|
line = (char*)lines->pfVectorGet(lines, j);
|
||||||
line = get_next_line(fd);
|
i = -1;
|
||||||
j = 0;
|
while (line[++i])
|
||||||
while (line != NULL) {
|
if ((!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n') || i > 5)
|
||||||
i = -1;
|
return (false);
|
||||||
while (line[++i])
|
if (ft_atoi(line) < 1 || ft_atoi(line) > 10000)
|
||||||
if (!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n')
|
return (false);
|
||||||
return (free(line), -1);
|
j++;
|
||||||
if (ft_atoi(line) < 1 || ft_atoi(line) > 10000)
|
}
|
||||||
return (free(line), -1);
|
return (true);
|
||||||
free(line);
|
|
||||||
j++;
|
|
||||||
line = get_next_line(fd);
|
|
||||||
}
|
|
||||||
return (j);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* fill_array.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
|
|
||||||
/* Updated: 2026/03/28 16:05:46 by lud-adam ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "../libft/libft.h"
|
|
||||||
#include "get_next_line.h"
|
|
||||||
|
|
||||||
int* fill_array(int fd, int size)
|
|
||||||
{
|
|
||||||
int* res = malloc(sizeof(int) * size);
|
|
||||||
if (res == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
char* line = get_next_line(fd);
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while (line != NULL)
|
|
||||||
{
|
|
||||||
res[i] = ft_atoi(line);
|
|
||||||
i++;
|
|
||||||
free(line);
|
|
||||||
line = get_next_line(fd);
|
|
||||||
}
|
|
||||||
return (res);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* fill_vector.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
|
||||||
|
/* Updated: 2026/03/29 16:31:19 by lud-adam ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../libft/libft.h"
|
||||||
|
|
||||||
|
#include "get_next_line.h"
|
||||||
|
|
||||||
|
#include "alcu.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool fill_vector(t_vector *lines, int fd) {
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* game.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/28 21:14:00 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2026/03/28 21:41:04 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../libft/libft.h"
|
||||||
|
#include "alcu.h"
|
||||||
|
#include "get_next_line.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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)
|
||||||
|
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 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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool game(int *lines, int size) {
|
||||||
|
int ai_turn;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
+15
-18
@@ -6,12 +6,11 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 15:07:17 by lud-adam #+# #+# */
|
/* Created: 2026/03/28 15:07:17 by lud-adam #+# #+# */
|
||||||
/* Updated: 2026/03/28 16:04:59 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/28 20:53:31 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "get_next_line.h"
|
#include "get_next_line.h"
|
||||||
|
|
||||||
#include "../libft/libft.h"
|
#include "../libft/libft.h"
|
||||||
|
|
||||||
size_t ft_strlen_with_c(char *str, char c) {
|
size_t ft_strlen_with_c(char *str, char c) {
|
||||||
@@ -95,24 +94,22 @@ static char *get_the_line(int fd, char *buffer) {
|
|||||||
i = 0;
|
i = 0;
|
||||||
nb_read = 0;
|
nb_read = 0;
|
||||||
line = NULL;
|
line = NULL;
|
||||||
if (buffer[0] != '\0')
|
if (buffer[0] != '\0') {
|
||||||
{
|
line = build_line(buffer, NULL, &i);
|
||||||
line = build_line(buffer, NULL, &i);
|
if (!line)
|
||||||
if (!line)
|
return (NULL);
|
||||||
return (NULL);
|
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
|
||||||
}
|
}
|
||||||
while (detect_newline(line) == 0)
|
while (detect_newline(line) == 0) {
|
||||||
{
|
read_file(fd, buffer, &nb_read);
|
||||||
read_file(fd, buffer, &nb_read);
|
if (nb_read < 0)
|
||||||
if (nb_read < 0)
|
return (free(line), NULL);
|
||||||
return (free(line), NULL);
|
if (nb_read == 0)
|
||||||
if (nb_read == 0)
|
break;
|
||||||
break ;
|
line = build_line(buffer, line, &i);
|
||||||
line = build_line(buffer, line, &i);
|
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
|
||||||
}
|
}
|
||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_next_line(int fd) {
|
char *get_next_line(int fd) {
|
||||||
|
|||||||
+40
-96
@@ -6,120 +6,64 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
|
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
|
||||||
/* Updated: 2026/03/28 16:06:09 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/29 16:31:17 by lud-adam ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "../libft/libft.h"
|
#include "../libft/libft.h"
|
||||||
#include "alcu.h"
|
#include "alcu.h"
|
||||||
#include "get_next_line.h"
|
|
||||||
|
|
||||||
int check_char_int(char *str) {
|
#include <fcntl.h>
|
||||||
int i;
|
#include <unistd.h>
|
||||||
|
|
||||||
i = -1;
|
static int get_fd(int argc, char **argv) {
|
||||||
while (str[++i] && i < 100)
|
if (argc == 2) {
|
||||||
if (!(str[i] >= '0' && str[i] <= '9') && str[i] != '\n')
|
return (open(argv[1], O_RDONLY));
|
||||||
return (0);
|
} else if (argc == 1)
|
||||||
|
return (0);
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void 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);
|
|
||||||
free(temp);
|
|
||||||
if (choice > 0 && choice < 4) {
|
|
||||||
if (choice > *line) {
|
|
||||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*line -= choice;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
ft_putstr_fd("-\nInvalid choice\n", 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void game(int *lines, int size) {
|
|
||||||
int ai_turn = 1;
|
|
||||||
int choice;
|
|
||||||
|
|
||||||
for (int i = size - 1; i >= 0; i--) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ai_turn)
|
|
||||||
ft_putstr_fd("AI win ! It will replace you\n", 1);
|
|
||||||
else
|
else
|
||||||
ft_putstr_fd("You win ! Well done\n", 1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 2) {
|
|
||||||
ft_putstr_fd("ERROR", 2);
|
int fd;
|
||||||
|
int size;
|
||||||
|
int *lines_int;
|
||||||
|
t_vector lines;
|
||||||
|
|
||||||
|
if (vector_init(&lines) == false) {
|
||||||
|
ft_putstr_fd("ERROR\n", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
fd = get_fd(argc, argv);
|
||||||
int fd = open(argv[1], O_RDONLY);
|
lines_int = NULL;
|
||||||
|
size = 0;
|
||||||
if (fd == -1) {
|
if (fd < 0 || fill_vector(&lines, fd) == false) {
|
||||||
ft_putstr_fd("ERROR", 2);
|
lines.pfVectorFree(&lines);
|
||||||
|
ft_putstr_fd("ERROR\n", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
if (check_input(&lines) == false) {
|
||||||
int size = check_input(fd);
|
lines.pfVectorFree(&lines);
|
||||||
if (size < 0) {
|
ft_putstr_fd("ERROR\n", 2);
|
||||||
ft_putstr_fd("ERROR", 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);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = open(argv[1], O_RDONLY);
|
if (open("/dev/tty", O_RDONLY) < 0 || game(lines_int, size) == false) {
|
||||||
int *lines = fill_array(fd, size);
|
free(lines_int);
|
||||||
if (!lines)
|
ft_putstr_fd("ERROR\n", 2);
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
// for (int i = 0; i < size; i++)
|
if (fd != 0)
|
||||||
// {
|
close(fd);
|
||||||
// printf("lines[i] : %d\n", lines[i]);
|
free(lines_int);
|
||||||
// }
|
|
||||||
|
|
||||||
// int player = 1;
|
|
||||||
game(lines, size);
|
|
||||||
close(fd);
|
|
||||||
free(lines);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-32
@@ -6,7 +6,7 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 16:06:30 by dgaillet #+# #+# */
|
/* Created: 2026/03/28 16:06:30 by dgaillet #+# #+# */
|
||||||
/* Updated: 2026/03/28 16:06:32 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/03/28 20:54:31 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,39 +14,45 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static int get_biggest_line(int *game_state, size_t nb_line) {
|
static int get_biggest_line(int *game_state, size_t nb_line)
|
||||||
size_t i;
|
{
|
||||||
int biggest = 0;
|
size_t i;
|
||||||
|
int biggest;
|
||||||
|
|
||||||
i = 0;
|
biggest = 0;
|
||||||
while (i < nb_line) {
|
i = 0;
|
||||||
if (game_state[i] > biggest)
|
while (i < nb_line)
|
||||||
biggest = game_state[i];
|
{
|
||||||
i++;
|
if (game_state[i] > biggest)
|
||||||
}
|
biggest = game_state[i];
|
||||||
return (biggest);
|
i++;
|
||||||
|
}
|
||||||
|
return (biggest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_board(int *game_state, size_t nb_line) {
|
void print_board(int *game_state, size_t nb_line)
|
||||||
int biggest_line;
|
{
|
||||||
size_t i;
|
int biggest_line;
|
||||||
int j;
|
size_t i;
|
||||||
|
int j;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
biggest_line = get_biggest_line(game_state, nb_line);
|
biggest_line = get_biggest_line(game_state, nb_line);
|
||||||
while (++i < nb_line && game_state[i] != 0) {
|
while (++i < nb_line && game_state[i] != 0)
|
||||||
j = -1;
|
{
|
||||||
while (++j < biggest_line - game_state[i])
|
j = -1;
|
||||||
write(1, " ", 1);
|
while (++j < biggest_line - game_state[i])
|
||||||
j = -1;
|
write(1, " ", 1);
|
||||||
while (++j < game_state[i]) {
|
j = -1;
|
||||||
write(1, "|", 1);
|
while (++j < game_state[i])
|
||||||
if (j < game_state[i] - 1)
|
{
|
||||||
write(1, " ", 1);
|
write(1, "|", 1);
|
||||||
}
|
if (j < game_state[i] - 1)
|
||||||
j = -1;
|
write(1, " ", 1);
|
||||||
while (++j < biggest_line - game_state[i])
|
}
|
||||||
write(1, " ", 1);
|
j = -1;
|
||||||
write(1, "\n", 1);
|
while (++j < biggest_line - game_state[i])
|
||||||
}
|
write(1, " ", 1);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* vector.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/29 14:23:01 by lud-adam #+# #+# */
|
||||||
|
/* Updated: 2026/03/29 14:50:19 by lud-adam ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
#include "libft.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int vector_resize(t_vector *v, int capacity);
|
||||||
|
int vector_push_back(t_vector *v, void *item);
|
||||||
|
int vector_set(t_vector *v, int index, void *item);
|
||||||
|
void *vector_get(t_vector *v, int index);
|
||||||
|
int vector_delete(t_vector *v, int index);
|
||||||
|
int vector_free(t_vector *v);
|
||||||
|
int vector_total(t_vector *v);
|
||||||
|
|
||||||
|
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_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user