]> git.sesse.net Git - stockfish/blob - src/piece.cpp
Space inflate generate_evasions()
[stockfish] / src / piece.cpp
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
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.
9   
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.
14   
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/>.
17 */
18
19
20 ////
21 //// Includes
22 ////
23
24 #include <cstring>
25
26 #include "piece.h"
27
28
29 ////
30 //// Constants and variables
31 ////
32
33 const int SlidingArray[18] = {
34   0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0
35 };
36
37 const SquareDelta Directions[16][16] = {
38   {DELTA_ZERO},
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},
48   {DELTA_ZERO},
49   {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},
59 };   
60
61 const SquareDelta PawnPush[2] = {
62   DELTA_N, DELTA_S
63 };
64
65
66 ////
67 //// Functions
68 ////
69
70 /// Translating piece types to/from English piece letters:
71
72 static const char PieceChars[] = " pnbrqk";
73
74 char piece_type_to_char(PieceType pt, bool upcase = false) {
75   return upcase? toupper(PieceChars[pt]) : PieceChars[pt];
76 }
77
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;
81 }
82
83
84 /// piece_is_ok() and piece_type_is_ok(), for debugging:
85
86 bool piece_is_ok(Piece pc) {
87   return
88     piece_type_is_ok(type_of_piece(pc)) &&
89     color_is_ok(color_of_piece(pc));
90 }
91
92 bool piece_type_is_ok(PieceType pc) {
93   return pc >= PAWN && pc <= KING;
94 }