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