-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_validity_check_rmlines.c
96 lines (87 loc) · 2.11 KB
/
ft_validity_check_rmlines.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_validity_check_rmlines.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: frahaing <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/16 15:05:06 by frahaing #+# #+# */
/* Updated: 2017/11/23 18:25:57 by rkrief ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static char *ft_replace_line_char(char *str, int i, int width)
{
while (width--)
str[i++] = 'x';
str[i] = 'x';
return (str);
}
static char *ft_replace_column_char(char *str, int i, int height)
{
while (height--)
{
str[i] = 'x';
i += 5;
}
return (str);
}
static int ft_column_empty(char *str, int height, int i)
{
int count;
int clone;
count = 0;
clone = height;
while (clone--)
{
if (str[i] == '.' || str[i] == 'x')
count++;
if (count == height)
return (1);
i += 5;
}
return (0);
}
static int ft_line_empty(char *str, int width)
{
int count;
int i;
count = 0;
i = 0;
while (str[i] != '\n')
{
if (str[i] == '.' || str[i] == 'x')
count++;
if (count == width)
return (1);
i++;
}
return (0);
}
char **ft_validity_check_rmlines(char **tetris)
{
int i;
int j;
i = -1;
while (tetris[++i])
{
j = 0;
while (tetris[i][j])
{
if (tetris[i][j] == '.' || tetris[i][j] == 'x')
{
if (ft_line_empty(&tetris[i][j], 4) == 1)
{
tetris[i] = ft_replace_line_char(tetris[i], j, 4);
j += 4;
}
if (ft_column_empty(tetris[i], 4, j % 5) == 1)
tetris[i] = ft_replace_column_char(tetris[i], j % 5, 4);
j++;
}
else
j++;
}
}
return (tetris);
}