-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplace_tet.c
More file actions
69 lines (63 loc) · 2.47 KB
/
place_tet.c
File metadata and controls
69 lines (63 loc) · 2.47 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* place_tet.c :+: :+: */
/* +:+ */
/* By: aholster <aholster@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/03/22 16:51:36 by lgutter #+# #+# */
/* Updated: 2019/03/31 19:09:10 by aholster ######## odam.nl */
/* */
/* ************************************************************************** */
#include "fillit.h"
static void place_final(unsigned int tet, unsigned short *map)
{
unsigned char y;
unsigned char x;
y = (((tet >> 16) & 255) + ((tet >> 0) & 3));
x = ((tet >> 24) + ((tet >> ((0) + 2)) & 3));
map[y] = map[y] | (1 << x);
y = (((tet >> 16) & 255) + ((tet >> 4) & 3));
x = ((tet >> 24) + ((tet >> ((4) + 2)) & 3));
map[y] = map[y] | (1 << x);
y = (((tet >> 16) & 255) + ((tet >> 8) & 3));
x = ((tet >> 24) + ((tet >> ((8) + 2)) & 3));
map[y] = map[y] | (1 << x);
y = (((tet >> 16) & 255) + ((tet >> 12) & 3));
x = ((tet >> 24) + ((tet >> ((12) + 2)) & 3));
map[y] = map[y] | (1 << x);
}
static int check_hash(unsigned int tet, unsigned short *map,\
unsigned short di)
{
unsigned char y;
unsigned char x;
y = (((tet >> 16) & 255) + ((tet >> (0) & 3)));
x = ((tet >> 24) + ((tet >> ((0) + 2)) & 3));
if (x >= di || y >= di || ((map[y] >> x) & 1) != 0)
return (-1);
y = (((tet >> 16) & 255) + ((tet >> (12) & 3)));
x = ((tet >> 24) + ((tet >> ((12) + 2)) & 3));
if (x >= di || y >= di || ((map[y] >> x) & 1) != 0)
return (-1);
y = (((tet >> 16) & 255) + ((tet >> (8) & 3)));
x = ((tet >> 24) + ((tet >> ((8) + 2)) & 3));
if (x >= di || y >= di || ((map[y] >> x) & 1) != 0)
return (-1);
y = (((tet >> 16) & 255) + ((tet >> (4) & 3)));
x = ((tet >> 24) + ((tet >> ((4) + 2)) & 3));
if (x >= di || y >= di || ((map[y] >> x) & 1) != 0)
return (-1);
return (1);
}
int place_tet(unsigned int *tet, unsigned short *map,\
unsigned short di)
{
while (check_hash(*tet, map, di) != 1)
{
if (increment_offset(tet, di) == -1)
return (-1);
}
place_final(*tet, map);
return (1);
}