]> git.sesse.net Git - stockfish/blob - src/piece.h
Dynamic aspiration search without research.
[stockfish] / src / piece.h
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 #if !defined(PIECE_H_INCLUDED)
22 #define PIECE_H_INCLUDED
23
24 ////
25 //// Includes
26 ////
27
28 #include "color.h"
29 #include "square.h"
30
31
32 ////
33 //// Types
34 ////
35
36 enum PieceType {
37   NO_PIECE_TYPE = 0,
38   PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
39 };
40
41 enum Piece {
42   NO_PIECE = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
43   BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14,
44   EMPTY = 16, OUTSIDE = 17
45 };
46
47
48 ////
49 //// Constants
50 ////
51
52 const int SlidingArray[18] = {
53   0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0
54 };
55
56
57 ////
58 //// Inline functions
59 ////
60
61 inline Piece operator+ (Piece p, int i) { return Piece(int(p) + i); }
62 inline void operator++ (Piece &p, int) { p = Piece(int(p) + 1); }
63 inline Piece operator- (Piece p, int i) { return Piece(int(p) - i); }
64 inline void operator-- (Piece &p, int) { p = Piece(int(p) - 1); }
65 inline PieceType operator+ (PieceType p, int i) {return PieceType(int(p) + i);}
66 inline void operator++ (PieceType &p, int) { p = PieceType(int(p) + 1); }
67 inline PieceType operator- (PieceType p, int i) {return PieceType(int(p) - i);}
68 inline void operator-- (PieceType &p, int) { p = PieceType(int(p) - 1); }
69
70 inline PieceType type_of_piece(Piece p)  {
71   return PieceType(int(p) & 7);
72 }
73
74 inline Color color_of_piece(Piece p) {
75   return Color(int(p) >> 3);
76 }
77
78 inline Piece piece_of_color_and_type(Color c, PieceType pt) {
79   return Piece((int(c) << 3) | int(pt));
80 }
81
82 inline int piece_is_slider(Piece p) {
83   return SlidingArray[int(p)];
84 }
85
86 inline int piece_is_slider(PieceType pt) {
87   return SlidingArray[int(pt)];
88 }
89
90 inline SquareDelta pawn_push(Color c) {
91     return (c == WHITE ? DELTA_N : DELTA_S);
92 }
93
94 inline bool piece_type_is_ok(PieceType pc) {
95   return pc >= PAWN && pc <= KING;
96 }
97
98 inline bool piece_is_ok(Piece pc) {
99   return piece_type_is_ok(type_of_piece(pc)) && color_is_ok(color_of_piece(pc));
100 }
101
102
103 ////
104 //// Prototypes
105 ////
106
107 extern char piece_type_to_char(PieceType pt, bool upcase = false);
108 extern PieceType piece_type_from_char(char c);
109
110
111 #endif // !defined(PIECE_H_INCLUDED)