-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetriminos_utils_1.c
115 lines (102 loc) · 2.58 KB
/
tetriminos_utils_1.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
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tetriminos_utils_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nde-maes <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/11 14:38:04 by nde-maes #+# #+# */
/* Updated: 2019/01/05 12:52:36 by nde-maes ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** If no letter on the last column, tetriminos can move rightwards: return 1.
** If at least a letter on the last column but no letter on the last line,
** tetriminos can move downwards and to the left of the square: return 2.
** If stuff on the last column and on the last line, the tetriminos can't move
** anymore: return 0.
*/
int tetriminos_can_move(char **tet)
{
int line;
int col;
int dim;
line = -1;
col = -1;
dim = ft_strlen(tet[0]);
while (++line < dim)
{
if (tet[line][dim - 1] != '.')
{
while (++col < dim)
if (tet[dim - 1][col] != '.')
return (0);
return (2);
}
}
return (1);
}
/*
** Work from right to left (necessary), top to bottom (arbitrary).
*/
void move_tet_right(char **tet)
{
int line;
int col;
int dim;
line = -1;
dim = ft_strlen(tet[0]);
while (++line < dim)
{
col = dim;
while (--col > 0)
{
tet[line][col] = tet[line][col - 1];
tet[line][col - 1] = '.';
}
}
}
/*
** Work from top to bottom (arbitrary), and left to right (needed).
*/
int get_left_shift(char **tet)
{
int line;
int col;
int dim;
col = -1;
dim = ft_strlen(tet[0]);
while (++col < dim)
{
line = -1;
while (++line < dim)
if (tet[line][col] != '.')
return (col);
}
return (0);
}
/*
** Work form left to right and bottom to top (both are needed).
*/
void move_tet_down_left(char **tet)
{
int line;
int col;
int left_shift;
int dim;
left_shift = get_left_shift(tet);
dim = ft_strlen(tet[0]);
line = dim - 1;
while (line > 0)
{
col = 0;
while (col < dim - left_shift)
{
tet[line][col] = tet[line - 1][col + left_shift];
tet[line - 1][col + left_shift] = '.';
col++;
}
line--;
}
}