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