-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshift.c
More file actions
100 lines (92 loc) · 2 KB
/
Copy pathshift.c
File metadata and controls
100 lines (92 loc) · 2 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shift.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sescolas <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 16:56:26 by sescolas #+# #+# */
/* Updated: 2017/02/11 11:08:36 by sescolas ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int col_count(char *tet)
{
int i;
int j;
int ret;
i = 0;
ret = 0;
while (i < 5)
{
j = 0;
while (j < 4)
{
if (tet[(j * 5) + i] != PIECE_MARKER)
++ret;
else
{
i = 5;
break ;
}
++j;
}
++i;
}
return (ret / 4);
}
static char *shift_up(char *tet)
{
int i;
int j;
int offset;
i = 0;
while (tet[i])
{
if (tet[i] == EMPTY_MARKER && tet[i + 1] == EMPTY_MARKER &&
tet[i + 2] == EMPTY_MARKER && tet[i + 3] == EMPTY_MARKER)
i += 5;
else
break ;
}
j = 0;
offset = i;
while (tet[i])
tet[j++] = tet[i++];
while (offset--)
{
++j;
tet[j] = ((j + 1) % 5 == 0 ? '\n' : EMPTY_MARKER);
}
tet[j] = '\0';
return (tet);
}
static char *shift_left(char *tet)
{
int i;
int j;
int k;
int offset;
i = 0;
offset = col_count(tet);
i = -1;
k = 0;
while (tet[++i])
{
j = offset;
while (j--)
++i;
while (tet[i] && tet[i] != '\n')
tet[k++] = tet[i++];
j = offset;
while (j--)
tet[k++] = EMPTY_MARKER;
tet[k++] = '\n';
}
tet[k] = '\0';
return (tet);
}
char *shift_top_left(char *tet)
{
return (shift_left(shift_up(tet)));
}