-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_shiftsave.c
68 lines (63 loc) · 1.91 KB
/
ft_shiftsave.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_shiftsave.c :+: :+: */
/* +:+ */
/* By: dsaripap <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/06/10 22:48:53 by dsaripap #+# #+# */
/* Updated: 2019/06/11 15:19:49 by dsaripap ######## odam.nl */
/* */
/* ************************************************************************** */
#include "fillit.h"
void save_tolist(t_list **tetr_lst, uint64_t num)
{
t_list *tetrm;
printf("Save tetrimino to the Linked List \n");
tetrm = ft_lstnew(&num, 64);
ft_lstaddend(tetr_lst, tetrm);
}
/*
-- function "shift_to_topleft" --
Reading the 64-bit number/tetrimino
and shifting it to the top left
*/
uint64_t shift_to_topleft(uint64_t num)
{
size_t i;
size_t x;
size_t y;
uint64_t temp;
//printf("Tet before shifting\n");
//print_binary(num, 4);
//printf("\n");
i = 0;
x = 16;
y = 16;
while (i < 64)
{
temp = num & ((uint64_t)1 << i);
if (temp != 0)
{
//printf("temp = %llu, pos = %lu \n", temp, i);
if (i / 4 < y)
{
//printf("this is executed \n");
y = i / 4;
}
if ((i - (4 * (i / 4))) < x)
{
//printf("this is also executed \n");
x = i - (4 * (i / 4));
}
//printf("i = %lu, x = %lu, y = %lu \n", i, x, y);
//printf("\n");
}
//printf("i = %lu \n", i);
i++;
}
num >>= (x + (4 * y));
//printf("num = %llu \n", num);
//print_binary(num, 4);
return (num);
}