2 Glaurung, a UCI chess playing engine.
3 Copyright (C) 2004-2008 Tord Romstad
5 Glaurung is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 Glaurung is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 //// Constants and variables
33 const int SlidingArray[18] = {
34 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0
37 const SquareDelta Directions[16][16] = {
39 {DELTA_NW, DELTA_NE, DELTA_ZERO},
40 {DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE,
41 DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO},
42 {DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
43 {DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO},
44 {DELTA_S, DELTA_E, DELTA_W, DELTA_N,
45 DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
46 {DELTA_S, DELTA_E, DELTA_W, DELTA_N,
47 DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
50 {DELTA_SW, DELTA_SE, DELTA_ZERO},
51 {DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE,
52 DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO},
53 {DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
54 {DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO},
55 {DELTA_S, DELTA_E, DELTA_W, DELTA_N,
56 DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
57 {DELTA_S, DELTA_E, DELTA_W, DELTA_N,
58 DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO},
61 const SquareDelta PawnPush[2] = {
70 /// Translating piece types to/from English piece letters:
72 static const char PieceChars[] = " pnbrqk";
74 char piece_type_to_char(PieceType pt, bool upcase = false) {
75 return upcase? toupper(PieceChars[pt]) : PieceChars[pt];
78 PieceType piece_type_from_char(char c) {
79 const char *ch = strchr(PieceChars, tolower(c));
80 return ch? PieceType(ch - PieceChars) : NO_PIECE_TYPE;
84 /// piece_is_ok() and piece_type_is_ok(), for debugging:
86 bool piece_is_ok(Piece pc) {
88 piece_type_is_ok(type_of_piece(pc)) &&
89 color_is_ok(color_of_piece(pc));
92 bool piece_type_is_ok(PieceType pc) {
93 return pc >= PAWN && pc <= KING;