Skip to content

Commit 144e055

Browse files
author
Raphael KRIEF
committed
Everything is ok but miss the usage error and the error due to more than 26 tetris
0 parents  commit 144e055

24 files changed

+986
-0
lines changed

Makefile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: frahaing <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2017/11/02 13:02:11 by frahaing #+# #+# #
9+
# Updated: 2017/11/23 17:09:28 by rkrief ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = fillit
14+
15+
LIB = libft.a
16+
17+
SRC = main.c \
18+
ft_validity_check_four.c \
19+
ft_validity_check_rmlines.c \
20+
ft_validity_check_split.c \
21+
ft_validity_check_fresh.c \
22+
ft_check_placement.c \
23+
ft_deletetetris.c \
24+
ft_fillit.c \
25+
ft_fillstring.c \
26+
ft_isopper.c \
27+
ft_sqrtupper.c \
28+
ft_squaremin.c \
29+
ft_validity_check_alpha.c
30+
31+
LIB_SRC = ./libft/ft_putstr.c \
32+
./libft/ft_putchar.c \
33+
./libft/ft_strsplit.c\
34+
./libft/ft_strsub.c \
35+
./libft/ft_strlen.c \
36+
./libft/ft_strcpy.c \
37+
./libft/ft_memalloc.c \
38+
./libft/ft_bzero.c
39+
40+
HEADER = fillit.h
41+
42+
LIB_OBJ = ft_putstr.o \
43+
ft_putchar.o \
44+
ft_strsplit.o \
45+
ft_strsub.o \
46+
ft_strlen.o \
47+
ft_strcpy.o \
48+
ft_memalloc.o \
49+
ft_bzero.o
50+
51+
FLAG = -Wall -Werror -Wextra
52+
53+
all : $(NAME)
54+
55+
$(NAME) : $(LIB_SRC) $(HEADER)
56+
@gcc -c $(LIB_SRC)
57+
@ar rc $(LIB) $(LIB_OBJ)
58+
@ranlib $(LIB)
59+
@gcc $(SRC) -L. -lft $(FLAG) -o $(NAME)
60+
61+
clean :
62+
@/bin/rm -f $(LIB_OBJ)
63+
64+
fclean : clean
65+
@/bin/rm -rf $(NAME) $(LIB)
66+
67+
re : fclean $(NAME)
68+
69+
.PHONY: all clean fclean re

fillit

13.8 KB
Binary file not shown.

fillit.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fillit.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: rkrief <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/22 18:35:17 by rkrief #+# #+# */
9+
/* Updated: 2017/11/23 17:48:29 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef FILLIT_H
14+
# define FILLIT_H
15+
16+
# include <fcntl.h>
17+
# include <stdlib.h>
18+
# include <unistd.h>
19+
20+
void ft_bzero(void *s, size_t n);
21+
void *ft_memalloc(size_t size);
22+
void ft_putchar(char c);
23+
void ft_putstr(char const *s);
24+
char *ft_strcpy(char *dst, const char *src);
25+
char **ft_strsplit(char const *s, char c);
26+
char *ft_strsub(char const *s, unsigned int start, size_t len);
27+
size_t ft_strlen(const char *s);
28+
int ft_validity_check_four(char *str);
29+
char **ft_validity_check_rmlines(char **tetris);
30+
char **ft_validity_check_split(char *str);
31+
char **ft_validity_check_fresh(char **tetris);
32+
char **ft_validity_check_alpha(char **tetris);
33+
int ft_squaremin(char **tab);
34+
int ft_sqrtupper(int nb);
35+
char *ft_fill(int squarelen);
36+
int ft_deletetetris(int j, char *str, char *tetris);
37+
int ft_isopper(char c);
38+
char *ft_fillit(char **tab);
39+
int ft_check_placement(char *tetris);
40+
41+
#endif

ft_check_placement.c

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_check_placement.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: frahaing <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/23 10:52:06 by frahaing #+# #+# */
9+
/* Updated: 2017/11/23 18:11:12 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "fillit.h"
14+
15+
static void ft_count(char *str, int *i, int *j)
16+
{
17+
if (str[*i] == '#')
18+
{
19+
if (str[*i + 1] == '#')
20+
*j = *j + 1;
21+
if (str[*i - 1] == '#')
22+
*j = *j + 1;
23+
if (str[*i + 5] == '#')
24+
*j = *j + 1;
25+
if (str[*i - 5] == '#')
26+
*j = *j + 1;
27+
}
28+
}
29+
30+
int ft_check_placement(char *str)
31+
{
32+
int i;
33+
int j;
34+
size_t len;
35+
36+
i = 0;
37+
j = 0;
38+
len = ft_strlen(str);
39+
while (str[i])
40+
{
41+
while (str[i] == '.')
42+
i++;
43+
if ((str[i] == '\n' && str[i + 2] == '\0') && j < 6)
44+
return (0);
45+
ft_count(str, &i, &j);
46+
if ((str[i] == '\n' && (str[i + 1] == '\n' && (str[i + 1]))) && j < 6)
47+
return (0);
48+
if (((str[i] == '\n' && str[i + 1] == '\n') || i <= 18) && j >= 6)
49+
{
50+
j = 0;
51+
i = -1;
52+
str = str + 21;
53+
}
54+
i++;
55+
}
56+
return (1);
57+
}

ft_deletetetris.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_deletetetris.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: rkrief <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/21 13:50:23 by rkrief #+# #+# */
9+
/* Updated: 2017/11/22 18:38:30 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "fillit.h"
14+
15+
int ft_deletetetris(int j, char *str, char *tetris)
16+
{
17+
int check;
18+
int i;
19+
int z;
20+
char letter;
21+
22+
i = 0;
23+
z = 0;
24+
while (!(ft_isopper(tetris[i])))
25+
i++;
26+
letter = 'A' + j;
27+
while (str[z] != letter)
28+
z++;
29+
check = z - i;
30+
while (str[z])
31+
{
32+
if (str[z] == letter)
33+
str[z] = '.';
34+
z++;
35+
}
36+
return (check);
37+
}

ft_fillit.c

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_backtracking.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: rkrief <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/21 11:29:15 by rkrief #+# #+# */
9+
/* Updated: 2017/11/23 18:09:32 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "fillit.h"
14+
15+
static int ft_checkplace(char *tetris, char *str, int squarelen, size_t i)
16+
{
17+
int j;
18+
int checkpoint;
19+
20+
j = 0;
21+
checkpoint = i;
22+
while (str[i] && tetris[j])
23+
{
24+
if (str[i] == '\n' && tetris[j] != '\n')
25+
return (0);
26+
else if (tetris[j] == '\n' && tetris[j + 1])
27+
{
28+
i = checkpoint + squarelen + 1;
29+
checkpoint = i;
30+
j++;
31+
if (str[i] == '\0')
32+
return (0);
33+
}
34+
if (ft_isopper(str[i]) && ft_isopper(tetris[j]))
35+
return (0);
36+
j++;
37+
i++;
38+
}
39+
return (1);
40+
}
41+
42+
static char *ft_placetetris(char *str, char *tetris,
43+
int squarelen, size_t i)
44+
{
45+
int check;
46+
int j;
47+
48+
check = i;
49+
j = 0;
50+
while (tetris[j])
51+
{
52+
while (tetris[j] == '.')
53+
{
54+
j++;
55+
i++;
56+
}
57+
if (ft_isopper(tetris[j]))
58+
str[i++] = tetris[j++];
59+
else if (tetris[j] == '\n')
60+
{
61+
i = check + squarelen + 1;
62+
j++;
63+
check = i;
64+
}
65+
}
66+
return (str);
67+
}
68+
69+
static char *ft_bck(char **tab, int squarelen, char *str, size_t i)
70+
{
71+
int j;
72+
73+
j = 0;
74+
while (tab[j])
75+
{
76+
while (!(ft_checkplace(tab[j], str, squarelen, i)) && str[i] != '\0')
77+
i++;
78+
if (!str[i])
79+
{
80+
if (j == 0)
81+
return (ft_bck(tab, squarelen + 1, ft_fill(squarelen + 1), 0));
82+
if (j != 0)
83+
{
84+
i = ft_deletetetris(j - 1, str, tab[j - 1]) + 1;
85+
j--;
86+
}
87+
}
88+
else
89+
{
90+
str = ft_placetetris(str, tab[j++], squarelen, i);
91+
i = 0;
92+
}
93+
}
94+
return (str);
95+
}
96+
97+
char *ft_fillit(char **tab)
98+
{
99+
int squarelen;
100+
char *str;
101+
char *res;
102+
size_t i;
103+
104+
i = 0;
105+
squarelen = ft_squaremin(tab);
106+
str = ft_fill(squarelen);
107+
res = ft_bck(tab, squarelen, str, i);
108+
return (res);
109+
}

ft_fillstring.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_fillstring.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: rkrief <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/21 14:33:44 by rkrief #+# #+# */
9+
/* Updated: 2017/11/22 20:34:09 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "fillit.h"
14+
15+
char *ft_fill(int squarelen)
16+
{
17+
int i;
18+
char *stetris;
19+
int clone;
20+
int clone2;
21+
22+
i = 0;
23+
clone2 = squarelen;
24+
clone = squarelen;
25+
stetris = (char*)malloc(sizeof(char) * (((squarelen + 1) *
26+
(squarelen + 1) + 1)));
27+
stetris[(squarelen * (squarelen + 1)) + 1] = '\0';
28+
while (clone2--)
29+
{
30+
while (clone > 0)
31+
{
32+
stetris[i++] = '.';
33+
clone--;
34+
}
35+
stetris[i++] = '\n';
36+
clone = squarelen;
37+
}
38+
i = 1;
39+
while (i < squarelen + 2)
40+
stetris[squarelen * (squarelen + 1) + i++] = '\0';
41+
return (stetris);
42+
}

ft_isopper.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isupper.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: rkrief <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/11/07 16:37:15 by rkrief #+# #+# */
9+
/* Updated: 2017/11/22 18:39:04 by rkrief ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "fillit.h"
14+
15+
int ft_isopper(char c)
16+
{
17+
if (c >= 'A' && c <= 'Z')
18+
return (1);
19+
else
20+
return (0);
21+
}

0 commit comments

Comments
 (0)