]> git.sesse.net Git - stockfish/blob - src/piece.h
Retire color.h
[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 #if !defined(PIECE_H_INCLUDED)
21 #define PIECE_H_INCLUDED
22
23 #include "value.h"
24
25 enum PieceType {
26   PIECE_TYPE_NONE = 0,
27   PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
28 };
29
30 enum Piece {
31   PIECE_NONE_DARK_SQ = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
32   BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14, PIECE_NONE = 16
33 };
34
35 enum Color {
36   WHITE, BLACK, COLOR_NONE
37 };
38
39 ENABLE_OPERATORS_ON(PieceType)
40 ENABLE_OPERATORS_ON(Piece)
41 ENABLE_OPERATORS_ON(Color)
42
43 /// Important: If the material values are changed, one must also
44 /// adjust the piece square tables, and the method game_phase() in the
45 /// Position class!
46 ///
47 /// Values modified by Joona Kiiski
48
49 const Value PawnValueMidgame   = Value(0x0C6);
50 const Value PawnValueEndgame   = Value(0x102);
51 const Value KnightValueMidgame = Value(0x331);
52 const Value KnightValueEndgame = Value(0x34E);
53 const Value BishopValueMidgame = Value(0x344);
54 const Value BishopValueEndgame = Value(0x359);
55 const Value RookValueMidgame   = Value(0x4F6);
56 const Value RookValueEndgame   = Value(0x4FE);
57 const Value QueenValueMidgame  = Value(0x9D9);
58 const Value QueenValueEndgame  = Value(0x9FE);
59
60 inline Piece make_piece(Color c, PieceType pt) {
61   return Piece((int(c) << 3) | int(pt));
62 }
63
64 inline PieceType type_of_piece(Piece p)  {
65   return PieceType(int(p) & 7);
66 }
67
68 inline Color color_of_piece(Piece p) {
69   return Color(int(p) >> 3);
70 }
71
72 inline Color opposite_color(Color c) {
73   return Color(int(c) ^ 1);
74 }
75
76 inline bool color_is_ok(Color c) {
77   return c == WHITE || c == BLACK;
78 }
79
80 inline bool piece_type_is_ok(PieceType pt) {
81   return pt >= PAWN && pt <= KING;
82 }
83
84 inline bool piece_is_ok(Piece p) {
85   return piece_type_is_ok(type_of_piece(p)) && color_is_ok(color_of_piece(p));
86 }
87
88 inline char piece_type_to_char(PieceType pt) {
89   static const char ch[] = " PNBRQK";
90   return ch[pt];
91 }
92
93 #endif // !defined(PIECE_H_INCLUDED)