-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbk.c
More file actions
76 lines (69 loc) · 2.1 KB
/
bk.c
File metadata and controls
76 lines (69 loc) · 2.1 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
/********** BK ***********/
/* Blocks for 1010 */
/*************************/
#define NBK 19
/* Blocks in row major 5x5 bitarrays in int */
int bk[NBK] = {1,3,7,15,31,33,
35,67,97,98,99,
1057,1063,4231,
7201,7300,7399,
33825,1082401};
/* Number of squares in each block (required for scoring) */
int bksquares[NBK] = {1,2,3,4,5,
2,3,3,3,3,
4,3,5,5,5,
5,9,4,5};
/* Read bk[n] */
int rbk(int n, int x, int y) {
int i = 5*y+x;
return bk[n] & (1<<i);
}
/* Print bk[n] at pos x, y */
void printbk(char n, char x, char y, char c) {
char i, j;
attron(COLOR_PAIR(c));
for (j=0; j<5; j++)
for (i=0; i<5; i++) {
if (rbk(n, i, j)) {
attron(A_UNDERLINE);
if (x < 10 && y < 10 /* Block on the game board */
&& rtt(x+i, y+j)) { /* And over existing tile */
mvaddstr((y+j), (x+i)*3, "xx");
} else { /* Hint board or valid tile */
mvaddstr((y+j), (x+i)*3, " ");
}
/* Print borders between tiles (rightwards) */
mvadd_wch((y+j), (x+i)*3+2, &vert_sep_right);
attroff(A_UNDERLINE);
// The downwards border is always present (with A_UNDERLINE)
}
}
attroff(COLOR_PAIR(c));
}
/* Does block n fit in tt at pos x, y ? */
int bkfits(int n, int x, int y) {
int i, j;
for (i=0; i<5; i++) /* For each sub block of bk */
for (j=0; j<5; j++) {
if (!rbk(n, i, j)) /* Is it an actual sub block ? */
continue;
if (x+i > 9
|| y+j > 9)
return -1; /* Out of bounds */
}
for (i=0; i<5; i++) /* For each sub block of bk */
for (j=0; j<5; j++) {
if (!rbk(n, i, j)) /* Is it an actual sub block ? */
continue;
if (rtt(x+i, y+j))
return 0; /* Does not fit */
}
return 1; /* Fits */
}
void bkinsert(int n, int x, int y) {
int i, j;
for (i=0; i<5; i++)
for (j=0; j<5; j++)
if (rbk(n, i, j))
wttt(x+i, y+j);
}