-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathknight.c
137 lines (130 loc) · 5.23 KB
/
knight.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "board.h"
#include "pieces.h"
#include "constants.h"
static const Pos2 knightOffsets[] = {
{ 2, 1 },
{ 2, -1 },
{ -2, 1 },
{ -2, -1 },
{ 1, 2 },
{ 1, -2 },
{ -1, 2 },
{ -1, -2 },
};
void knightLegalMove(u32 ourIndex, const u8* piecesActive, const Pos2* piecePositions, u8* legalSpots) {
const Pos2* ourPosition = &(piecePositions[ourIndex]);
for (int i = 0; i < 8; i++) {
int spotX = ourPosition->x + knightOffsets[i].x;
if (spotX < 0 || spotX >= BOARD_WIDTH) {
continue;
}
int spotY = ourPosition->y + knightOffsets[i].y;
if (spotY < 0 || spotY >= BOARD_HEIGHT) {
continue;
}
if (isSpaceOccupied(spotX, spotY) > -1) {
continue;
}
legalSpots[spotX + (BOARD_WIDTH * spotY)] = 1;
}
}
Vtx knight_verts[] = {
{ -61, 68, 0, 0, 0, 0, 194, 194, 194, 255 },
{ -46, -65, 0, 0, 0, 0, 160, 160, 160, 255 },
{ -38, -44, 50, 0, 0, 0, 127, 127, 127, 255 },
{ -54, 45, 50, 0, 0, 0, 74, 74, 74, 255 },
{ -86, -26, 0, 0, 0, 0, 196, 196, 196, 255 },
{ -54, -36, 261, 0, 0, 0, 74, 74, 74, 255 },
{ -66, -17, 50, 0, 0, 0, 74, 74, 74, 255 },
{ -34, -73, 100, 0, 0, 0, 163, 163, 163, 255 },
{ -61, 50, 118, 0, 0, 0, 198, 198, 198, 255 },
{ -83, -24, 107, 0, 0, 0, 156, 156, 156, 255 },
{ -51, -87, 361, 0, 0, 0, 147, 147, 147, 255 },
{ -63, -60, 345, 0, 0, 0, 149, 149, 149, 255 },
{ -42, 0, 344, 0, 0, 0, 199, 199, 199, 255 },
{ -51, 6, 313, 0, 0, 0, 210, 210, 210, 255 },
{ -29, 90, 288, 0, 0, 0, 129, 129, 129, 255 },
{ -76, -87, 393, 0, 0, 0, 255, 255, 255, 255 },
{ -78, -60, 370, 0, 0, 0, 100, 100, 100, 255 },
{ -87, -108, 385, 0, 0, 0, 95, 95, 95, 255 },
{ 66, 68, 0, 0, 0, 0, 194, 194, 194, 255 },
{ 2, 46, 213, 0, 0, 0, 95, 95, 95, 255 },
{ 50, -65, 0, 0, 0, 0, 160, 160, 160, 255 },
{ 2, -104, 267, 0, 0, 0, 157, 157, 157, 255 },
{ 2, -89, 0, 0, 0, 0, 150, 150, 150, 255 },
{ 2, 95, 0, 0, 0, 0, 255, 255, 255, 255 },
{ 42, -44, 50, 0, 0, 0, 127, 127, 127, 255 },
{ 58, 45, 50, 0, 0, 0, 74, 74, 74, 255 },
{ 2, 59, 50, 0, 0, 0, 74, 74, 74, 255 },
{ 2, -62, 50, 0, 0, 0, 150, 150, 150, 255 },
{ 90, -26, 0, 0, 0, 0, 196, 196, 196, 255 },
{ 58, -36, 261, 0, 0, 0, 74, 74, 74, 255 },
{ 71, -17, 50, 0, 0, 0, 74, 74, 74, 255 },
{ 39, -73, 100, 0, 0, 0, 163, 163, 163, 255 },
{ 66, 50, 118, 0, 0, 0, 198, 198, 198, 255 },
{ 2, 94, 123, 0, 0, 0, 199, 199, 199, 255 },
{ 2, -88, 95, 0, 0, 0, 187, 187, 187, 255 },
{ 87, -24, 107, 0, 0, 0, 156, 156, 156, 255 },
{ 55, -87, 361, 0, 0, 0, 147, 147, 147, 255 },
{ 2, -96, 373, 0, 0, 0, 255, 255, 255, 255 },
{ 2, -26, 254, 0, 0, 0, 38, 38, 38, 255 },
{ 67, -60, 345, 0, 0, 0, 149, 149, 149, 255 },
{ 47, 0, 344, 0, 0, 0, 199, 199, 199, 255 },
{ 2, -6, 357, 0, 0, 0, 255, 255, 255, 255 },
{ 36, 89, 287, 0, 0, 0, 130, 130, 130, 255 },
{ 2, 96, 302, 0, 0, 0, 150, 150, 150, 255 },
{ 2, 93, 267, 0, 0, 0, 128, 128, 128, 255 },
{ 80, -87, 393, 0, 0, 0, 255, 255, 255, 255 },
{ 82, -60, 370, 0, 0, 0, 100, 100, 100, 255 },
{ 91, -108, 385, 0, 0, 0, 95, 95, 95, 255 },
};
Gfx knight_commands[] = {
gsSPVertex(knight_verts, 48, 0),
gsSP2Triangles( 34, 21, 7, 0, 9, 5, 8, 0),
gsSP2Triangles( 8, 19, 33, 0, 0, 26, 23, 0),
gsSP2Triangles( 4, 3, 0, 0, 22, 2, 1, 0),
gsSP2Triangles( 1, 6, 4, 0, 7, 5, 9, 0),
gsSP2Triangles( 2, 9, 6, 0, 3, 33, 26, 0),
gsSP2Triangles( 6, 8, 3, 0, 27, 7, 2, 0),
gsSP2Triangles( 21, 37, 10, 0, 19, 5, 38, 0),
gsSP2Triangles( 5, 10, 11, 0, 10, 41, 12, 0),
gsSP2Triangles( 11, 12, 13, 0, 5, 11, 13, 0),
gsSP2Triangles( 5, 13, 14, 0, 38, 14, 44, 0),
gsSP2Triangles( 12, 43, 14, 0, 13, 12, 14, 0),
gsSP2Triangles( 15, 17, 10, 0, 10, 17, 11, 0),
gsSP2Triangles( 16, 17, 15, 0, 11, 17, 16, 0),
gsSP2Triangles( 10, 16, 15, 0, 43, 44, 14, 0),
gsSP2Triangles( 19, 8, 5, 0, 0, 3, 26, 0),
gsSP2Triangles( 4, 6, 3, 0, 22, 27, 2, 0),
gsSP2Triangles( 1, 2, 6, 0, 7, 21, 5, 0),
gsSP2Triangles( 2, 7, 9, 0, 3, 8, 33, 0),
gsSP2Triangles( 6, 9, 8, 0, 27, 34, 7, 0),
gsSP2Triangles( 5, 21, 10, 0, 10, 37, 41, 0),
gsSP2Triangles( 11, 10, 12, 0, 38, 5, 14, 0),
gsSP2Triangles( 12, 41, 43, 0, 10, 11, 16, 0),
gsSP2Triangles( 34, 31, 21, 0, 35, 32, 29, 0),
gsSP2Triangles( 32, 33, 19, 0, 18, 23, 26, 0),
gsSP2Triangles( 28, 18, 25, 0, 22, 20, 24, 0),
gsSP2Triangles( 20, 28, 30, 0, 31, 35, 29, 0),
gsSP2Triangles( 24, 30, 35, 0, 25, 26, 33, 0),
gsSP2Triangles( 30, 25, 32, 0, 27, 24, 31, 0),
gsSP2Triangles( 21, 36, 37, 0, 19, 38, 29, 0),
gsSP2Triangles( 29, 39, 36, 0, 36, 40, 41, 0),
gsSP2Triangles( 39, 42, 40, 0, 29, 42, 39, 0),
gsSP2Triangles( 38, 44, 42, 0, 40, 42, 43, 0),
gsSP2Triangles( 45, 36, 47, 0, 36, 39, 47, 0),
gsSP2Triangles( 46, 45, 47, 0, 39, 46, 47, 0),
gsSP2Triangles( 36, 45, 46, 0, 43, 42, 44, 0),
gsSP2Triangles( 19, 29, 32, 0, 43, 44, 41, 0),
gsSP2Triangles( 18, 26, 25, 0, 28, 25, 30, 0),
gsSP2Triangles( 22, 24, 27, 0, 20, 30, 24, 0),
gsSP2Triangles( 31, 29, 21, 0, 24, 35, 31, 0),
gsSP2Triangles( 25, 33, 32, 0, 30, 32, 35, 0),
gsSP2Triangles( 27, 31, 34, 0, 29, 36, 21, 0),
gsSP2Triangles( 36, 41, 37, 0, 39, 40, 36, 0),
gsSP2Triangles( 38, 42, 29, 0, 40, 43, 41, 0),
gsSP2Triangles( 36, 46, 39, 0, 1, 4, 22, 0),
gsSP2Triangles( 0, 23, 4, 0, 18, 28, 23, 0),
gsSP2Triangles( 20, 22, 28, 0, 18, 28, 23, 0),
gsSPEndDisplayList()
};