]> git.sesse.net Git - stockfish/blob - src/piece.h
movegen: Introduce generate_pawn_captures()
[stockfish] / src / piece.h
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 #if !defined(PIECE_H_INCLUDED)
21 #define PIECE_H_INCLUDED
22
23 //// 
24 //// Includes
25 ////
26
27 #include "color.h"
28 #include "misc.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 and variables
50 ////
51
52 const PieceType PieceTypeMin = PAWN;
53 const PieceType PieceTypeMax = KING;
54
55 extern const int SlidingArray[18];
56 extern const SquareDelta Directions[16][16];   
57 extern const SquareDelta PawnPush[2];
58
59
60 //// 
61 //// Inline functions
62 ////
63
64 inline Piece operator+ (Piece p, int i) { return Piece(int(p) + i); }
65 inline void operator++ (Piece &p, int) { p = Piece(int(p) + 1); }
66 inline Piece operator- (Piece p, int i) { return Piece(int(p) - i); }
67 inline void operator-- (Piece &p, int) { p = Piece(int(p) - 1); }
68 inline PieceType operator+ (PieceType p, int i) {return PieceType(int(p) + i);}
69 inline void operator++ (PieceType &p, int) { p = PieceType(int(p) + 1); }
70 inline PieceType operator- (PieceType p, int i) {return PieceType(int(p) - i);}
71 inline void operator-- (PieceType &p, int) { p = PieceType(int(p) - 1); }
72
73 inline PieceType type_of_piece(Piece p)  {
74   return PieceType(int(p) & 7);
75 }
76
77 inline Color color_of_piece(Piece p) {
78   return Color(int(p) >> 3);
79 }
80
81 inline Piece piece_of_color_and_type(Color c, PieceType pt) {
82   return Piece((int(c) << 3) | int(pt));
83 }
84
85 inline Piece pawn_of_color(Color c) {
86   return piece_of_color_and_type(c, PAWN);
87 }
88
89 inline Piece knight_of_color(Color c) {
90   return piece_of_color_and_type(c, KNIGHT);
91 }
92
93 inline Piece bishop_of_color(Color c) {
94   return piece_of_color_and_type(c, BISHOP);
95 }
96
97 inline Piece rook_of_color(Color c) {
98   return piece_of_color_and_type(c, ROOK);
99 }
100
101 inline Piece queen_of_color(Color c) {
102   return piece_of_color_and_type(c, QUEEN);
103 }
104
105 inline Piece king_of_color(Color c) {
106   return piece_of_color_and_type(c, KING);
107 }
108
109 inline int piece_is_slider(Piece p) {
110   return SlidingArray[int(p)];
111 }
112
113 inline int piece_type_is_slider(PieceType pt) {
114   return SlidingArray[int(pt)];
115 }
116
117 inline SquareDelta pawn_push(Color c) {
118   return PawnPush[c];
119 }
120   
121
122 ////
123 //// Prototypes
124 ////
125
126 extern char piece_type_to_char(PieceType pt, bool upcase);
127 extern PieceType piece_type_from_char(char c);
128 extern bool piece_is_ok(Piece pc);
129 extern bool piece_type_is_ok(PieceType pt);
130
131
132 #endif // !defined(PIECE_H_INCLUDED)