-
Notifications
You must be signed in to change notification settings - Fork 0
/
consts.go
341 lines (309 loc) · 8.63 KB
/
consts.go
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package main
import "fmt"
type Color bool
const WHITE Color = true
const BLACK Color = false
type PieceType uint8
// it holds: WHITE_PIECE % 8 == PIECE == BLACK_PIECE % 8
const (
NO_PIECE PieceType = iota
KING // = 1
QUEEN
ROOK
BISHOP
KNIGHT
PAWN // = 6
_
_
WHITE_KING // = 9
WHITE_QUEEN
WHITE_ROOK
WHITE_BISHOP
WHITE_KNIGHT
WHITE_PAWN // = 14
_
_
BLACK_KING // = 17
BLACK_QUEEN
BLACK_ROOK
BLACK_BISHOP
BLACK_KNIGHT
BLACK_PAWN // = 22
)
// typeOf takes a some piece and checks for piece type
func (pieceType PieceType) is(otherType PieceType) bool {
return pieceType % 8 == otherType
}
func (pieceType PieceType) color() Color {
s := pieceType / 8
if s == 1 {
return WHITE
} else if s == 2 {
return BLACK
} else if pieceType == NO_PIECE {
panic("Need a piece to check color")
} else {
panic("Need a white or a black piece to check color")
}
}
var PIECES = []PieceType{
WHITE_KING, WHITE_QUEEN, WHITE_ROOK, WHITE_BISHOP, WHITE_KNIGHT, WHITE_PAWN,
BLACK_KING, BLACK_QUEEN, BLACK_ROOK, BLACK_BISHOP, BLACK_KNIGHT, BLACK_PAWN,
}
var WHITE_PIECES = []PieceType{
WHITE_KING, WHITE_QUEEN, WHITE_ROOK, WHITE_BISHOP, WHITE_KNIGHT, WHITE_PAWN,
}
var BLACK_PIECES = []PieceType{
BLACK_KING, BLACK_QUEEN, BLACK_ROOK, BLACK_BISHOP, BLACK_KNIGHT, BLACK_PAWN,
}
const FEN_WHITE_KING = "K"
const FEN_WHITE_QUEEN = "Q"
const FEN_WHITE_ROOK = "R"
const FEN_WHITE_BISHOP = "B"
const FEN_WHITE_KNIGHT = "N"
const FEN_WHITE_PAWN = "P"
const FEN_BLACK_KING = "k"
const FEN_BLACK_QUEEN = "q"
const FEN_BLACK_ROOK = "r"
const FEN_BLACK_BISHOP = "b"
const FEN_BLACK_KNIGHT = "n"
const FEN_BLACK_PAWN = "p"
const FEN_EMPTY = "x"
const ALGEBRAIC_WHITE_KING = "K"
const ALGEBRAIC_WHITE_QUEEN = "Q"
const ALGEBRAIC_WHITE_ROOK = "R"
const ALGEBRAIC_WHITE_BISHOP = "B"
const ALGEBRAIC_WHITE_KNIGHT = "N"
const ALGEBRAIC_WHITE_PAWN = ""
const ALGEBRAIC_BLACK_KING = "K"
const ALGEBRAIC_BLACK_QUEEN = "Q"
const ALGEBRAIC_BLACK_ROOK = "R"
const ALGEBRAIC_BLACK_BISHOP = "B"
const ALGEBRAIC_BLACK_KNIGHT = "N"
const ALGEBRAIC_BLACK_PAWN = ""
const HTML_WHITE_KING = "♔"
const HTML_WHITE_QUEEN = "♕"
const HTML_WHITE_ROOK = "♖"
const HTML_WHITE_BISHOP = "♗"
const HTML_WHITE_KNIGHT = "♘"
const HTML_WHITE_PAWN = "" //"♙"
const HTML_BLACK_KING = "♚"
const HTML_BLACK_QUEEN = "♛"
const HTML_BLACK_ROOK = "♜"
const HTML_BLACK_BISHOP = "♝"
const HTML_BLACK_KNIGHT = "♞"
const HTML_BLACK_PAWN = "" //"♟"
// U+2654
const UTF8_WHITE_KING = "♔"
const UTF8_WHITE_QUEEN = "♕"
const UTF8_WHITE_ROOK = "♖"
const UTF8_WHITE_BISHOP = "♗"
const UTF8_WHITE_KNIGHT = "♘"
const UTF8_WHITE_PAWN = "" //"♙"
const UTF8_BLACK_KING = "♚"
const UTF8_BLACK_QUEEN = "♛"
const UTF8_BLACK_ROOK = "♜"
const UTF8_BLACK_BISHOP = "♝"
const UTF8_BLACK_KNIGHT = "♞"
const UTF8_BLACK_PAWN = "" //"♟"
var FEN_TO_PIECE = map[string]PieceType{
FEN_WHITE_KING: WHITE_KING,
FEN_WHITE_QUEEN: WHITE_QUEEN,
FEN_WHITE_ROOK: WHITE_ROOK,
FEN_WHITE_BISHOP: WHITE_BISHOP,
FEN_WHITE_KNIGHT: WHITE_KNIGHT,
FEN_WHITE_PAWN: WHITE_PAWN,
FEN_BLACK_KING: BLACK_KING,
FEN_BLACK_QUEEN: BLACK_QUEEN,
FEN_BLACK_ROOK: BLACK_ROOK,
FEN_BLACK_BISHOP: BLACK_BISHOP,
FEN_BLACK_KNIGHT: BLACK_KNIGHT,
FEN_BLACK_PAWN: BLACK_PAWN,
FEN_EMPTY: 0,
}
var PIECE_TO_FEN = map[PieceType]string{
WHITE_KING: FEN_WHITE_KING,
WHITE_QUEEN: FEN_WHITE_QUEEN,
WHITE_ROOK: FEN_WHITE_ROOK,
WHITE_BISHOP: FEN_WHITE_BISHOP,
WHITE_KNIGHT: FEN_WHITE_KNIGHT,
WHITE_PAWN: FEN_WHITE_PAWN,
BLACK_KING: FEN_BLACK_KING,
BLACK_QUEEN: FEN_BLACK_QUEEN,
BLACK_ROOK: FEN_BLACK_ROOK,
BLACK_BISHOP: FEN_BLACK_BISHOP,
BLACK_KNIGHT: FEN_BLACK_KNIGHT,
BLACK_PAWN: FEN_BLACK_PAWN,
}
var PIECE_TO_HTML = map[PieceType]string{
WHITE_KING: HTML_WHITE_KING,
WHITE_QUEEN: HTML_WHITE_QUEEN,
WHITE_ROOK: HTML_WHITE_ROOK,
WHITE_BISHOP: HTML_WHITE_BISHOP,
WHITE_KNIGHT: HTML_WHITE_KNIGHT,
WHITE_PAWN: HTML_WHITE_PAWN,
BLACK_KING: HTML_BLACK_KING,
BLACK_QUEEN: HTML_BLACK_QUEEN,
BLACK_ROOK: HTML_BLACK_ROOK,
BLACK_BISHOP: HTML_BLACK_BISHOP,
BLACK_KNIGHT: HTML_BLACK_KNIGHT,
BLACK_PAWN: HTML_BLACK_PAWN,
}
var FEN_TO_HTML = map[string]string{
FEN_WHITE_KING: HTML_WHITE_KING,
FEN_WHITE_QUEEN: HTML_WHITE_QUEEN,
FEN_WHITE_ROOK: HTML_WHITE_ROOK,
FEN_WHITE_BISHOP: HTML_WHITE_BISHOP,
FEN_WHITE_KNIGHT: HTML_WHITE_KNIGHT,
FEN_WHITE_PAWN: HTML_WHITE_PAWN,
FEN_BLACK_KING: HTML_BLACK_KING,
FEN_BLACK_QUEEN: HTML_BLACK_QUEEN,
FEN_BLACK_ROOK: HTML_BLACK_ROOK,
FEN_BLACK_BISHOP: HTML_BLACK_BISHOP,
FEN_BLACK_KNIGHT: HTML_BLACK_KNIGHT,
FEN_BLACK_PAWN: HTML_BLACK_PAWN,
}
var FEN_TO_UTF8 = map[string]string{
FEN_WHITE_KING: UTF8_WHITE_KING,
FEN_WHITE_QUEEN: UTF8_WHITE_QUEEN,
FEN_WHITE_ROOK: UTF8_WHITE_ROOK,
FEN_WHITE_BISHOP: UTF8_WHITE_BISHOP,
FEN_WHITE_KNIGHT: UTF8_WHITE_KNIGHT,
FEN_WHITE_PAWN: UTF8_WHITE_PAWN,
FEN_BLACK_KING: UTF8_BLACK_KING,
FEN_BLACK_QUEEN: UTF8_BLACK_QUEEN,
FEN_BLACK_ROOK: UTF8_BLACK_ROOK,
FEN_BLACK_BISHOP: UTF8_BLACK_BISHOP,
FEN_BLACK_KNIGHT: UTF8_BLACK_KNIGHT,
FEN_BLACK_PAWN: UTF8_BLACK_PAWN,
}
var PIECE_TO_UTF8 = map[PieceType]string{
WHITE_KING: UTF8_WHITE_KING,
WHITE_QUEEN: UTF8_WHITE_QUEEN,
WHITE_ROOK: UTF8_WHITE_ROOK,
WHITE_BISHOP: UTF8_WHITE_BISHOP,
WHITE_KNIGHT: UTF8_WHITE_KNIGHT,
WHITE_PAWN: UTF8_WHITE_PAWN,
BLACK_KING: UTF8_BLACK_KING,
BLACK_QUEEN: UTF8_BLACK_QUEEN,
BLACK_ROOK: UTF8_BLACK_ROOK,
BLACK_BISHOP: UTF8_BLACK_BISHOP,
BLACK_KNIGHT: UTF8_BLACK_KNIGHT,
BLACK_PAWN: UTF8_BLACK_PAWN,
}
var PIECE_TO_ALGEBRAIC = map[PieceType]string{
WHITE_KING: ALGEBRAIC_WHITE_KING,
WHITE_QUEEN: ALGEBRAIC_WHITE_QUEEN,
WHITE_ROOK: ALGEBRAIC_WHITE_ROOK,
WHITE_BISHOP: ALGEBRAIC_WHITE_BISHOP,
WHITE_KNIGHT: ALGEBRAIC_WHITE_KNIGHT,
WHITE_PAWN: ALGEBRAIC_WHITE_PAWN,
BLACK_KING: ALGEBRAIC_BLACK_KING,
BLACK_QUEEN: ALGEBRAIC_BLACK_QUEEN,
BLACK_ROOK: ALGEBRAIC_BLACK_ROOK,
BLACK_BISHOP: ALGEBRAIC_BLACK_BISHOP,
BLACK_KNIGHT: ALGEBRAIC_BLACK_KNIGHT,
BLACK_PAWN: ALGEBRAIC_BLACK_PAWN,
}
type CastlingType uint8
func (c CastlingType) is(otherType CastlingType) bool {
return c == otherType
}
const (
NO_CASTLING CastlingType = iota
WHITE_CASTLING_SHORT
WHITE_CASTLING_LONG
BLACK_CASTLING_SHORT
BLACK_CASTLING_LONG
)
const WHITE_CASTLING_SHORT_STRING = "0-0"
const BLACK_CASTLING_SHORT_STRING = "0-0"
const WHITE_CASTLING_LONG_STRING = "0-0-0"
const BLACK_CASTLING_LONG_STRING = "0-0-0"
var CASTLING_TO_STRING = map[CastlingType]string{
WHITE_CASTLING_SHORT: WHITE_CASTLING_SHORT_STRING,
WHITE_CASTLING_LONG: WHITE_CASTLING_LONG_STRING,
BLACK_CASTLING_SHORT: BLACK_CASTLING_SHORT_STRING,
BLACK_CASTLING_LONG: BLACK_CASTLING_LONG_STRING,
}
func (c CastlingType) String() string {
return CASTLING_TO_STRING[c]
}
const A1 = 1 << 0
const B1 = 1 << 1
const C1 = 1 << 2
const D1 = 1 << 3
const E1 = 1 << 4
const F1 = 1 << 5
const G1 = 1 << 6
const H1 = 1 << 7
const A2 = 1 << 8
const B2 = 1 << 9
const C2 = 1 << 10
const D2 = 1 << 11
const E2 = 1 << 12
const F2 = 1 << 13
const G2 = 1 << 14
const H2 = 1 << 15
const A3 = 1 << 16
const B3 = 1 << 17
const C3 = 1 << 18
const D3 = 1 << 19
const E3 = 1 << 20
const F3 = 1 << 21
const G3 = 1 << 22
const H3 = 1 << 23
const A4 = 1 << 24
const B4 = 1 << 25
const C4 = 1 << 26
const D4 = 1 << 27
const E4 = 1 << 28
const F4 = 1 << 29
const G4 = 1 << 30
const H4 = 1 << 31
const A5 = 1 << 32
const B5 = 1 << 33
const C5 = 1 << 34
const D5 = 1 << 35
const E5 = 1 << 36
const F5 = 1 << 37
const G5 = 1 << 38
const H5 = 1 << 39
const A6 = 1 << 40
const B6 = 1 << 41
const C6 = 1 << 42
const D6 = 1 << 43
const E6 = 1 << 44
const F6 = 1 << 45
const G6 = 1 << 46
const H6 = 1 << 47
const A7 = 1 << 48
const B7 = 1 << 49
const C7 = 1 << 50
const D7 = 1 << 51
const E7 = 1 << 52
const F7 = 1 << 53
const G7 = 1 << 54
const H7 = 1 << 55
const A8 = 1 << 56
const B8 = 1 << 57
const C8 = 1 << 58
const D8 = 1 << 59
const E8 = 1 << 60
const F8 = 1 << 61
const G8 = 1 << 62
const H8 = 1 << 63
type PromotionKey struct {
color Color
uciPromotion string
}
var PROMOTION_TO_PIECE = map[PromotionKey]PieceType {
PromotionKey{WHITE, "q"} : WHITE_QUEEN,
PromotionKey{WHITE, "r"} : WHITE_ROOK,
PromotionKey{WHITE, "b"} : WHITE_BISHOP,
PromotionKey{WHITE, "n"} : WHITE_KNIGHT,
PromotionKey{BLACK, "q"} : BLACK_QUEEN,
PromotionKey{BLACK, "r"} : BLACK_ROOK,
PromotionKey{BLACK, "b"} : BLACK_BISHOP,
PromotionKey{BLACK, "n"} : BLACK_KNIGHT,
}