Skip to content

Commit

Permalink
filler
Browse files Browse the repository at this point in the history
  • Loading branch information
o4eredko committed Dec 27, 2018
1 parent d9c55d5 commit ddabfc6
Show file tree
Hide file tree
Showing 90 changed files with 233,301 additions and 10,758 deletions.
37 changes: 16 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,38 @@
# **************************************************************************** #

NAME = yochered.filler
LIBFT = libft.a
VISUAL = visu_filler

SRC = $(addprefix $(SRCDIR), main.c additional_funcs.c algorithm.c fill_map_layout.c get_description.c)
SRC = main.c additional_funcs.c algorithm.c fill_map_layout.c get_description.c
VISUAL_SRC = visu.c windows_funcs.c parse.c print.c

VISUAL_SRC = $(addprefix $(VISUAL_DIR), visu.c windows_funcs.c parse.c print.c)
VISUAL_OBJ = $(VISUAL_SRC:.c=.o)
OBJ = $(SRC:.c=.o)

VISUAL_DIR = ./visu/

VISUAL_OBJ = $(VISUAL_SRC:.c =.o)

OBJ_DIR = ./obj/
SRCDIR = ./src/

OBJ = $(SRC:.c=.o)

LIBFT = libft.a

VISUAL = show_filler

all: $(NAME)

$(NAME): $(OBJ) $(LIBFT)
gcc -o $(NAME) $(SRC) -L ./libft/ -lft -I ./includes/
$(NAME): $(LIBFT) $(addprefix $(OBJ_DIR), $(OBJ))
gcc -o $(NAME) $(addprefix $(OBJ_DIR), $(OBJ)) -L ./libft/ -lft -I ./includes/

filler: $(VISUAL_OBJ) $(LIBFT)
gcc -o visu_filler $(VISUAL_OBJ) -L ./libft/ -lft -I /usr/local/include -lmlx -framework OpenGL -framework AppKit
filler: $(LIBFT) $(addprefix $(OBJ_DIR), $(VISUAL_OBJ))
gcc -o $(VISUAL) $(addprefix $(OBJ_DIR), $(VISUAL_OBJ)) -L ./libft/ -lft -I /usr/local/include -lmlx -framework OpenGL -framework AppKit

$(addprefix $(SRCDIR), %.o): $(addprefix $(SRCDIR), %.c)
$(addprefix $(OBJ_DIR), %.o): $(addprefix $(SRCDIR), %.c)
gcc -Wall -W -Werror -c -o $@ $< -I ./includes/

$(addprefix $(VISUAL_DIR), %.o): $(addprefix $(VISUAL_DIR), %.c)
gcc -Wall -W -Werror -c -o $@ $<
$(addprefix $(OBJ_DIR), %.o): $(addprefix $(VISUAL_DIR), %.c)
gcc -Wall -W -Werror -c -o $@ $< -I ./includes/

$(LIBFT):
@make -C ./libft/ --silent
make -C ./libft/ --silent

clean:
/bin/rm -f $(OBJ)
/bin/rm -f visu/*.o
/bin/rm -f $(addprefix $(OBJ_DIR), $(OBJ) $(VISUAL_OBJ))
make -C ./libft/ clean --silent

fclean: clean
Expand Down
4 changes: 2 additions & 2 deletions filler.trace
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
seed = 9889
seed = 8293
./yochered.filler won
Score:
157AGAINST197
2AGAINST2039
2 changes: 0 additions & 2 deletions includes/filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# define MANHATTAN(x1, x2, y1, y2) ((ABS(x2 - x1)) + ABS((y2 - y1)))
# define X 0
# define Y 1
//Delete
# include <fcntl.h>

typedef struct s_shape
{
Expand Down
Binary file removed libft/ft_atoi.o
Binary file not shown.
Binary file removed libft/ft_bzero.o
Binary file not shown.
Binary file removed libft/ft_count_digits.o
Binary file not shown.
Binary file removed libft/ft_cycle_detector.o
Binary file not shown.
Binary file removed libft/ft_isalnum.o
Binary file not shown.
Binary file removed libft/ft_isalpha.o
Binary file not shown.
Binary file removed libft/ft_isascii.o
Binary file not shown.
Binary file removed libft/ft_isdigit.o
Binary file not shown.
Binary file removed libft/ft_isprint.o
Binary file not shown.
Binary file removed libft/ft_itoa.o
Binary file not shown.
Binary file removed libft/ft_itoa_base.o
Binary file not shown.
Binary file removed libft/ft_lstadd.o
Binary file not shown.
Binary file removed libft/ft_lstdel.o
Binary file not shown.
Binary file removed libft/ft_lstdelone.o
Binary file not shown.
Binary file removed libft/ft_lstiter.o
Binary file not shown.
Binary file removed libft/ft_lstmap.o
Binary file not shown.
Binary file removed libft/ft_lstnew.o
Binary file not shown.
Binary file removed libft/ft_lstrev.o
Binary file not shown.
Binary file removed libft/ft_memalloc.o
Binary file not shown.
Binary file removed libft/ft_memccpy.o
Binary file not shown.
Binary file removed libft/ft_memchr.o
Binary file not shown.
Binary file removed libft/ft_memcmp.o
Binary file not shown.
Binary file removed libft/ft_memcpy.o
Binary file not shown.
Binary file removed libft/ft_memdel.o
Binary file not shown.
Binary file removed libft/ft_memmove.o
Binary file not shown.
Binary file removed libft/ft_memset.o
Binary file not shown.
Binary file removed libft/ft_print_memory.o
Binary file not shown.
Binary file removed libft/ft_printf.o
Binary file not shown.
Binary file removed libft/ft_putchar.o
Binary file not shown.
Binary file removed libft/ft_putchar_fd.o
Binary file not shown.
Binary file removed libft/ft_putendl.o
Binary file not shown.
Binary file removed libft/ft_putendl_fd.o
Binary file not shown.
Binary file removed libft/ft_putnbr.o
Binary file not shown.
Binary file removed libft/ft_putnbr_fd.o
Binary file not shown.
Binary file removed libft/ft_putstr.o
Binary file not shown.
Binary file removed libft/ft_putstr_fd.o
Binary file not shown.
Binary file removed libft/ft_strcat.o
Binary file not shown.
Binary file removed libft/ft_strchr.o
Binary file not shown.
Binary file removed libft/ft_strclr.o
Binary file not shown.
Binary file removed libft/ft_strcmp.o
Binary file not shown.
Binary file removed libft/ft_strcpy.o
Binary file not shown.
Binary file removed libft/ft_strdel.o
Binary file not shown.
Binary file removed libft/ft_strdup.o
Binary file not shown.
Binary file removed libft/ft_strequ.o
Binary file not shown.
Binary file removed libft/ft_striter.o
Binary file not shown.
Binary file removed libft/ft_striteri.o
Binary file not shown.
Binary file removed libft/ft_strjoin.o
Binary file not shown.
Binary file removed libft/ft_strlcat.o
Binary file not shown.
Binary file removed libft/ft_strlen.o
Binary file not shown.
Binary file removed libft/ft_strmap.o
Binary file not shown.
Binary file removed libft/ft_strmapi.o
Binary file not shown.
Binary file removed libft/ft_strncat.o
Binary file not shown.
Binary file removed libft/ft_strncmp.o
Binary file not shown.
Binary file removed libft/ft_strncpy.o
Binary file not shown.
Binary file removed libft/ft_strnequ.o
Binary file not shown.
Binary file removed libft/ft_strnew.o
Binary file not shown.
Binary file removed libft/ft_strnstr.o
Binary file not shown.
Binary file removed libft/ft_strrchr.o
Binary file not shown.
Binary file removed libft/ft_strsplit.o
Binary file not shown.
Binary file removed libft/ft_strstr.o
Binary file not shown.
Binary file removed libft/ft_strsub.o
Binary file not shown.
Binary file removed libft/ft_strtrim.o
Binary file not shown.
Binary file removed libft/ft_tolower.o
Binary file not shown.
Binary file removed libft/ft_toupper.o
Binary file not shown.
Binary file removed libft/get_next_line.o
Binary file not shown.
Binary file modified libft/libft.a
Binary file not shown.
Binary file removed libft/printf_src/allowed_symbols.o
Binary file not shown.
Binary file removed libft/printf_src/bonus_types.o
Binary file not shown.
Binary file removed libft/printf_src/convert_to_str.o
Binary file not shown.
Binary file removed libft/printf_src/function_array.o
Binary file not shown.
Binary file removed libft/printf_src/handlers.o
Binary file not shown.
Binary file removed libft/printf_src/mem_funcs.o
Binary file not shown.
Binary file removed libft/printf_src/print_float.o
Binary file not shown.
Binary file removed libft/printf_src/print_funcs.o
Binary file not shown.
Binary file removed libft/printf_src/print_int.o
Binary file not shown.
Binary file removed libft/printf_src/print_pointer.o
Binary file not shown.
Binary file removed libft/printf_src/print_str.o
Binary file not shown.
Binary file removed libft/printf_src/print_uint.o
Binary file not shown.
Binary file removed libft/printf_src/str_functions.o
Binary file not shown.
243,820 changes: 233,122 additions & 10,698 deletions res.txt

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions visu/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ t_frames *parse_file(t_desc *d, int fd)
head = NULL;
while (get_next_line(fd, &line) > 0)
{
if (ft_strstr(line, "yochered.filler"))
if (ft_strstr(line, "[./yochered.filler]"))
{
d->m_c = *(line + 10) == 1 ? 'O' : 'X';
d->e_c = d->m_c = 'O' ? 'X' : 'O';
d->e_c = (d->m_c == 'O') ? 'X' : 'O';
}
if (ft_strnequ(line, "Plateau", 7))
insert_to_list(&head, fd, line, d);
if (ft_strnequ(line, "launched", 8) && !ft_strstr(line, "yochered.filler"))
d->enemy = ft_strdup(line + 17);
if (CHAR(*(line + 3), d->e_c) && ft_strstr(line, "fin:"))
d->e_score = ft_atoi(line + 10);
else if (CHAR(*(line + 3), d->m_c) && ft_strstr(line, "fin:"))
d->my_score = ft_atoi(line + 10);
}
if (d->m_c == 'O')
d->i = 0;
return (head);
}
68 changes: 49 additions & 19 deletions visu/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,42 @@ t_img *new_image(t_desc *d)

if (!(img = (t_img*)malloc(sizeof(t_img))))
return (NULL);
img->img = mlx_new_image(d->mlx, MAP_W, MAP_H);
img->sq_size = MIN((WIDTH - 400) / d->map_w, (HEIGHT - 200) / d->map_h);
img->height = d->map_h * img->sq_size;
img->width = d->map_w * img->sq_size;
img->bor = img->sq_size < 20 ? 1 : 2;
img->img = mlx_new_image(d->mlx, img->width, img->height);
img->ptr = mlx_get_data_addr(img->img, &img->bpp, &img->s_l, &img->endian);
img->bpp /= 8;
return (img);
}

void img_putpixel(t_img *img, int x, int y, int color)
{
if (x < 0 || y < 0 || x > MAP_W || y > MAP_H)
if (x < 0 || y < 0 || x >= img->width || y >= img->height)
return ;
*(int*)(img->ptr + ((x + y * MAP_W) * img->bpp)) = color;
*(int*)(img->ptr + ((x + y * img->width) * img->bpp)) = color;
}

void putsquare(t_img *img, int x, int y, int color)
{
int w;
int h;

w = x * SIZE;
h = y * SIZE;
while (y <= h)
w = x + img->sq_size;
h = y + img->sq_size;
while (y < h)
{
x = w / SIZE - 1;
while (++x <= w)
img_putpixel(img, x, y, color);
x = w - img->sq_size;
while (x < w)
{
if (x < w - img->sq_size + img->bor || x >= w - img->bor
|| y < h - img->sq_size + img->bor || y >= h - img->bor)
img_putpixel(img, x, y, B_COL);
else
img_putpixel(img, x, y, color);
x++;
}
y++;
}
}
Expand All @@ -52,27 +63,46 @@ void print_map(t_img *img, t_desc *d, t_frames *frame)
int i;
int j;

i = -1;
i = 0;
while (++i < d->map_h)
{
j = -1;
while (++j < d->map_w)
{
if (frame->map[i][j] == '.')
putsquare(img, j, i, 0xFFFFFF);
putsquare(img, j * img->sq_size, i * img->sq_size, 0xecebec);
else if (CHAR(frame->map[i][j], d->m_c))
putsquare(img, j * img->sq_size, i * img->sq_size, d->my_col);
else if (CHAR(frame->map[i][j], d->e_c))
putsquare(img, j * img->sq_size, i * img->sq_size, d->enem_col);
}
}
mlx_put_image_to_window(d->mlx, d->win, img->img,(WIDTH - MAP_W) / 2, (HEIGHT - MAP_H) / 2);
mlx_put_image_to_window(d->mlx, d->win, img->img, (WIDTH - img->width) / 2, (HEIGHT - img->height) / 2);
}

void fill_window(t_desc *d, t_frames *head)
int fill_window(t_desc *d, t_frames *head, int flag)
{
t_img *img;
static t_frames *cur;
t_img *img;

img = new_image(d);
// while (head)
// {
print_map(img, d, head);
// head = head->next;
// }
cur = cur ? cur : head;
if (!cur)
return (0);
if (d->i && g_my_score < d->my_score)
g_my_score += (flag == 1 ? 1 : -1);
else if (!d->i && g_e_score < d->e_score)
g_e_score += (flag == 1 ? 1 : -1);
d->i += (flag == 1 ? 1 : -1);
if (cur->prev && flag == -1)
cur = cur->prev;
else if (cur->next && flag == 1)
cur = cur->next;
print_map(img, d, cur);
if (!cur->next)
{
print_score(d);
return (0);
}
return (1);
}
18 changes: 8 additions & 10 deletions visu/visu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* ************************************************************************** */

#include "visu.h"
#include <pthread.h>

void put_error(char *str)
{
Expand All @@ -25,6 +26,10 @@ void init_description(t_desc *d)
{
d->map_h = 0;
d->map_w = 0;
d->my_col = 0x0ad7e7;
d->enem_col = 0xea0f0f;
g_my_score = 1;
g_e_score = 1;
}

int main(int ac, char **av)
Expand All @@ -40,17 +45,10 @@ int main(int ac, char **av)
{
if ((fd = open(av[1], 0)) == -1)
put_error(NULL);
create_window(&d);
head = parse_file(&d, fd);
fill_window(&d, head);
// while (head)
// {
// for(int i = 0; i < d.map_h; i++)
// ft_printf(CYAN("%s\n"), head->map[i]);
// ft_printf("\n\n");
// head = head->next;
// }
mlx_hook(d.win, 2, 5, key_hook, &d);
create_window(&d);
d.head = head;
mlx_hook(d.win, 2, 3, key_hook, &d);
mlx_loop(d.mlx);
if ((close(fd) == -1))
put_error(NULL);
Expand Down
26 changes: 22 additions & 4 deletions visu/visu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,32 @@
# include <unistd.h>
# include <stdio.h>
# include <fcntl.h>
# define MIN(x, y) (x) < (y) ? (x) : (y)
# define WIDTH 1920
# define HEIGHT 1280
# define MAP_H 1000
# define MAP_W 1000
# define SIZE 30
# define CHAR(x, c) ((x) == (c) || (x) == (c + 32) ? 1 : 0)
# define B_COL 0x2a472a
# define TIME 1000

int g_my_score;
int g_e_score;

typedef struct s_desc
{
void *mlx;
void *win;
char m_c;
char e_c;
int my_col;
int enem_col;
int map_h;
int map_w;
char *enemy;
int my_score;
int e_score;
struct s_img *scale;
struct s_frames *head;
int i;
} t_desc;

typedef struct s_frames
Expand All @@ -45,15 +57,21 @@ typedef struct s_img
{
void *img;
void *ptr;
int sq_size;
int bpp;
int s_l;
int endian;
int height;
int width;
int bor;
} t_img;

t_frames *parse_file(t_desc *d, int fd);
void create_window(t_desc *d);
int key_hook(int key, void *param);
void fill_window(t_desc *d, t_frames *head);
int fill_window(t_desc *d, t_frames *head, int flag);
void img_putpixel(t_img *img, int x, int y, int color);
void print_score(t_desc *d);
t_img *create_scale(t_desc *d);

#endif
Loading

0 comments on commit ddabfc6

Please sign in to comment.