]> git.sesse.net Git - stockfish/blob - src/piece.h
Rename ei.kingDanger in ei.margin
[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-2010 Marco Costalba, Joona Kiiski, Tord Romstad
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 #include "value.h"
31
32
33 ////
34 //// Types
35 ////
36
37 enum PieceType {
38   PIECE_TYPE_NONE = 0,
39   PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
40 };
41
42 enum Piece {
43   PIECE_NONE_DARK_SQ = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
44   BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14, PIECE_NONE = 16
45 };
46
47 ENABLE_OPERATORS_ON(PieceType);
48 ENABLE_OPERATORS_ON(Piece);
49
50
51 ////
52 //// Constants
53 ////
54
55 /// Important: If the material values are changed, one must also
56 /// adjust the piece square tables, and the method game_phase() in the
57 /// Position class!
58 ///
59 /// Values modified by Joona Kiiski
60
61 const Value PawnValueMidgame   = Value(0x0C6);
62 const Value PawnValueEndgame   = Value(0x102);
63 const Value KnightValueMidgame = Value(0x331);
64 const Value KnightValueEndgame = Value(0x34E);
65 const Value BishopValueMidgame = Value(0x344);
66 const Value BishopValueEndgame = Value(0x359);
67 const Value RookValueMidgame   = Value(0x4F6);
68 const Value RookValueEndgame   = Value(0x4FE);
69 const Value QueenValueMidgame  = Value(0x9D9);
70 const Value QueenValueEndgame  = Value(0x9FE);
71
72 extern const Value PieceValueMidgame[17];
73 extern const Value PieceValueEndgame[17];
74 extern const int SlidingArray[18];
75
76
77 ////
78 //// Inline functions
79 ////
80
81 inline PieceType type_of_piece(Piece p)  {
82   return PieceType(int(p) & 7);
83 }
84
85 inline Color color_of_piece(Piece p) {
86   return Color(int(p) >> 3);
87 }
88
89 inline Piece piece_of_color_and_type(Color c, PieceType pt) {
90   return Piece((int(c) << 3) | int(pt));
91 }
92
93 inline int piece_is_slider(Piece p) {
94   return SlidingArray[p];
95 }
96
97 inline SquareDelta pawn_push(Color c) {
98     return (c == WHITE ? DELTA_N : DELTA_S);
99 }
100
101 inline bool piece_type_is_ok(PieceType pc) {
102   return pc >= PAWN && pc <= KING;
103 }
104
105 inline bool piece_is_ok(Piece pc) {
106   return piece_type_is_ok(type_of_piece(pc)) && color_is_ok(color_of_piece(pc));
107 }
108
109
110 ////
111 //// Prototypes
112 ////
113
114 extern char piece_type_to_char(PieceType pt, bool upcase = false);
115 extern PieceType piece_type_from_char(char c);
116
117
118 #endif // !defined(PIECE_H_INCLUDED)