-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetriminos_utils_2.c
102 lines (90 loc) · 2.18 KB
/
tetriminos_utils_2.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
97
98
99
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tetriminos_utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nde-maes <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/17 15:19:46 by nde-maes #+# #+# */
/* Updated: 2019/01/07 13:10:53 by nde-maes ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int get_top_shift(char **tet)
{
int line;
int col;
int dim;
line = -1;
dim = ft_strlen(tet[0]);
while (++line < dim)
{
col = -1;
while (++col < dim)
if (tet[line][col] != '.')
return (line);
}
return (0);
}
void move_tet_left(char **tet)
{
int line;
int col;
int dim;
line = -1;
dim = ft_strlen(tet[0]);
while (++line < dim)
{
col = -1;
while (++col < dim - 1)
{
tet[line][col] = tet[line][col + 1];
tet[line][col + 1] = '.';
}
}
}
void move_tet_up(char **tet)
{
int line;
int col;
int dim;
line = -1;
dim = ft_strlen(tet[0]);
while (++line < dim - 1)
{
col = -1;
while (++col < dim)
{
tet[line][col] = tet[line + 1][col];
tet[line + 1][col] = '.';
}
}
}
void move_tet_top_left(char **tet)
{
int s_left;
int s_top;
s_left = get_left_shift(tet);
s_top = get_top_shift(tet);
while (s_left--)
move_tet_left(tet);
while (s_top--)
move_tet_up(tet);
}
/*
** Remove the tetriminos `letter` from the double array `res` if instances
** of the letter can be found in it.
*/
void delete_tet_on_res(char **res, char tet_letter)
{
int line;
int col;
line = -1;
while (res[++line])
{
col = -1;
while (res[line][++col])
if (res[line][col] == tet_letter)
res[line][col] = '.';
}
}