Skip to content

Commit

Permalink
remove function exit, add pdf of the subject
Browse files Browse the repository at this point in the history
  • Loading branch information
mdubus committed Oct 6, 2017
1 parent 66f2c83 commit 63b8f20
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 64 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

brew install SDL2
brew install SDL2_ttf

Ajouter les sujets en fr et en en
16 changes: 8 additions & 8 deletions includes/filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/07 16:51:53 by mdubus #+# #+# */
/* Updated: 2017/10/06 11:08:39 by mdubus ### ########.fr */
/* Updated: 2017/10/06 12:02:49 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -53,25 +53,25 @@ typedef struct s_filler

void init_struct_filler(t_filler *f);
void free_tab_char(char ***tab);
void get_player_info(t_filler *f, char *line);
void compare_return_error(char *s1, char *s2, char **tab);
int get_player_info(t_filler *f, char *line);
int compare_return_error(char *s1, char *s2, char **tab);
void print_map(t_filler *f);
void stock_current_map(t_filler *f);
void get_map_info(t_filler *f);
int stock_current_map(t_filler *f);
int get_map_info(t_filler *f);
void print_heat_map(t_filler *f);
void create_heat_map(t_filler *f);
void init_heat_map(t_filler *f);
void do_heat_map(t_filler *f);
void get_piece(t_filler *f);
int get_piece(t_filler *f);
void print_piece(t_filler *f);
void stock_piece(t_filler *f);
int stock_piece(t_filler *f);
int search_next_star(t_filler *f, int *i, int *j);
int count_score(t_filler *f, int i, int j, int *score);
int count_before(t_filler *f, int j, int i, int *score);
int count_after(t_filler *f, int j, int i, int *score);
void free_all(t_filler *f);
void free_tab_char(char ***tab);
void resolve(t_filler *f);
void free_maps(t_filler *f);
int free_maps(t_filler *f);

#endif
6 changes: 3 additions & 3 deletions srcs/algorithm/free.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/23 15:39:52 by mdubus #+# #+# */
/* Updated: 2017/10/05 20:30:25 by mdubus ### ########.fr */
/* Updated: 2017/10/06 12:05:54 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,7 +49,7 @@ void free_all(t_filler *f)
free_piece(f);
}

void free_maps(t_filler *f)
int free_maps(t_filler *f)
{
int i;

Expand All @@ -62,5 +62,5 @@ void free_maps(t_filler *f)
}
free(f->map);
free(f->hmap);
exit(1);
return (1);
}
35 changes: 21 additions & 14 deletions srcs/algorithm/get_map_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/09 12:15:21 by mdubus #+# #+# */
/* Updated: 2017/10/05 20:43:03 by mdubus ### ########.fr */
/* Updated: 2017/10/06 12:09:26 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/filler.h"

static void parse_line(t_filler *f, int i)
static int parse_line(t_filler *f, int i)
{
if (ft_nb_occur_char_in_str(f->line, " ") != 1)
{
while (i > 0)
free(f->map[i--]);
free(f->line);
exit(1);
return (1);
}
if (ft_strlen(f->line) != (size_t)f->w_board + 5)
{
while (i > 0)
free(f->map[i--]);
free(f->line);
exit(1);
return (1);
}
return (0);
}

void stock_current_map(t_filler *f)
int stock_current_map(t_filler *f)
{
int i;
int ret;
Expand All @@ -45,17 +46,19 @@ void stock_current_map(t_filler *f)
free(f->line);
while (i > 0)
free(f->map[i--]);
exit(1);
return (1);
}
parse_line(f, i);
if (parse_line(f, i) == 1)
return (1);
f->map[i] = ft_strsub(f->line, 4, (size_t)f->w_board);
i++;
free(f->line);
}
f->map[i] = NULL;
return (0);
}

static void get_map_line(t_filler *f)
static int get_map_line(t_filler *f)
{
int ret;

Expand All @@ -64,30 +67,34 @@ static void get_map_line(t_filler *f)
if (ret == 0)
{
free(f->line);
exit(0);
return (1);
}
if (ret != 1 && ret != 0)
{
free(f->line);
exit(1);
return (1);
}
return (0);
}

void get_map_info(t_filler *f)
int get_map_info(t_filler *f)
{
get_map_line(f);
if (get_map_line(f) == 1)
return (1);
f->tab = ft_strsplit(f->line, ' ');
free(f->line);
compare_return_error("Plateau", f->tab[0], f->tab);
if (compare_return_error("Plateau", f->tab[0], f->tab) == 1)
return (1);
f->h_board = ft_atoi(f->tab[1]);
f->w_board = ft_atoi(f->tab[2]);
f->map = (char **)malloc(sizeof(char*) * ((unsigned long)f->h_board + 1));
if (get_next_line_backslash(STDIN_FILENO, &f->line) != 1)
{
free(f->line);
ft_free_tab_char(&f->tab);
exit(1);
return (1);
}
free(f->line);
ft_free_tab_char(&f->tab);
return (0);
}
21 changes: 13 additions & 8 deletions srcs/algorithm/get_piece.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/10 11:38:31 by mdubus #+# #+# */
/* Updated: 2017/10/05 20:30:29 by mdubus ### ########.fr */
/* Updated: 2017/10/06 11:50:44 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/filler.h"

static void get_w_h_piece(t_filler *f)
static int get_w_h_piece(t_filler *f)
{
char **tab;

Expand All @@ -21,16 +21,17 @@ static void get_w_h_piece(t_filler *f)
free(f->line);
if (ft_strcmp("Piece", tab[0]) != 0)
{
free_maps(f);
ft_free_tab_char(&tab);
exit(1);
if (free_maps(f) == 1)
return (1);
}
f->h_piece = ft_atoi(tab[1]);
f->w_piece = ft_atoi(tab[2]);
ft_free_tab_char(&tab);
return (0);
}

void get_piece(t_filler *f)
int get_piece(t_filler *f)
{
int ret;

Expand All @@ -39,12 +40,16 @@ void get_piece(t_filler *f)
{
if (ret == 0)
free(f->line);
free_maps(f);
if (free_maps(f) == 1)
return (1);
}
if (ft_nb_occur_char_in_str(f->line, " ") != 2)
{
free(f->line);
free_maps(f);
if (free_maps(f) == 1)
return (1);
}
get_w_h_piece(f);
if (get_w_h_piece(f) == 1)
return (1);
return (0);
}
36 changes: 25 additions & 11 deletions srcs/algorithm/get_player_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/08 15:26:44 by mdubus #+# #+# */
/* Updated: 2017/10/05 19:17:12 by mdubus ### ########.fr */
/* Updated: 2017/10/06 12:07:02 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/filler.h"

static void get_player_line(char **line)
static int get_player_line(char **line)
{
int ret;

Expand All @@ -21,24 +21,37 @@ static void get_player_line(char **line)
{
if (ret == 0)
free(*line);
exit(1);
return (1);
}
if (ft_nb_occur_char_in_str(*line, " ") != 4)
{
free(*line);
exit(1);
return (1);
}
return (0);
}

void get_player_info(t_filler *f, char *line)
static int parse_line_player(t_filler *f)
{
get_player_line(&line);
if (compare_return_error("$$$", f->tab[0], f->tab) == 1)
return (1);
if (compare_return_error("exec", f->tab[1], f->tab) == 1)
return (1);
if (compare_return_error(":", f->tab[3], f->tab) == 1)
return (1);
if (compare_return_error("[./mdubus.filler]\n", f->tab[4], f->tab) == 1)
return (1);
return (0);
}

int get_player_info(t_filler *f, char *line)
{
if (get_player_line(&line) == 1)
return (1);
f->tab = ft_strsplit(line, ' ');
free(line);
compare_return_error("$$$", f->tab[0], f->tab);
compare_return_error("exec", f->tab[1], f->tab);
compare_return_error(":", f->tab[3], f->tab);
compare_return_error("[./mdubus.filler]\n", f->tab[4], f->tab);
if (parse_line_player(f) == 1)
return (1);
if (ft_strcmp(f->tab[2], "p1") == 0)
{
f->letter_me = 'O';
Expand All @@ -52,7 +65,8 @@ void get_player_info(t_filler *f, char *line)
else
{
ft_free_tab_char(&f->tab);
exit(1);
return (1);
}
ft_free_tab_char(&f->tab);
return (0);
}
32 changes: 21 additions & 11 deletions srcs/algorithm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,42 @@
/* By: mdubus <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/07 16:39:10 by mdubus #+# #+# */
/* Updated: 2017/10/05 19:01:43 by mdubus ### ########.fr */
/* Updated: 2017/10/06 12:10:24 by mdubus ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/filler.h"

int main(void)
static void print_coor(t_filler *f)
{
ft_putnbr(f->tempy);
ft_putchar(' ');
ft_putnbr(f->tempx);
ft_putchar('\n');
}

int main(void)
{
t_filler f;

init_struct_filler(&f);
get_player_info(&f, f.line);
if (get_player_info(&f, f.line) == 1)
return (1);
while (1)
{
get_map_info(&f);
stock_current_map(&f);
if (get_map_info(&f) == 1)
return (1);
if (stock_current_map(&f) == 1)
return (1);
create_heat_map(&f);
init_heat_map(&f);
do_heat_map(&f);
get_piece(&f);
stock_piece(&f);
if (get_piece(&f) == 1)
return (1);
if (stock_piece(&f) == 1)
return (1);
resolve(&f);
ft_putnbr(f.tempy);
ft_putchar(' ');
ft_putnbr(f.tempx);
ft_putchar('\n');
print_coor(&f);
free_all(&f);
}
return (0);
Expand Down
Loading

0 comments on commit 63b8f20

Please sign in to comment.