]> git.sesse.net Git - stockfish/blob - src/pawns.h
bd6b54abb3ddfc75f3d2e87c2247aeb9648d74c3
[stockfish] / src / pawns.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(PAWNS_H_INCLUDED)
22 #define PAWNS_H_INCLUDED
23
24 ////
25 //// Includes
26 ////
27
28 #include "bitboard.h"
29 #include "value.h"
30
31 ////
32 //// Types
33 ////
34
35 /// PawnInfo is a class which contains various information about a pawn
36 /// structure.  Currently, it only includes a middle game and an end game
37 /// pawn structure evaluation, and a bitboard of passed pawns.  We may want
38 /// to add further information in the future.  A lookup to the pawn hash table
39 /// (performed by calling the get_pawn_info method in a PawnInfoTable object)
40 /// returns a pointer to a PawnInfo object.
41 class Position;
42
43 class PawnInfo {
44
45   friend class PawnInfoTable;
46
47 public:
48   Value mg_value() const;
49   Value eg_value() const;
50   Value kingside_storm_value(Color c) const;
51   Value queenside_storm_value(Color c) const;
52   Bitboard passed_pawns() const;
53   int file_is_half_open(Color c, File f) const;
54   int has_open_file_to_left(Color c, File f) const;
55   int has_open_file_to_right(Color c, File f) const;
56
57 private:
58   void clear();
59
60   Key key;
61   Bitboard passedPawns;
62   int16_t mgValue, egValue;
63   int16_t ksStormValue[2], qsStormValue[2];
64   uint8_t halfOpenFiles[2];
65 };
66
67
68 /// The PawnInfoTable class represents a pawn hash table.  It is basically
69 /// just an array of PawnInfo objects and a few methods for accessing these
70 /// objects.  The most important method is get_pawn_info, which looks up a
71 /// position in the table and returns a pointer to a PawnInfo object.
72
73 class PawnInfoTable {
74
75 public:
76   PawnInfoTable(unsigned numOfEntries);
77   ~PawnInfoTable();
78   void clear();
79   PawnInfo* get_pawn_info(const Position& pos);
80
81 private:
82   unsigned size;
83   PawnInfo* entries;
84 };
85
86
87 ////
88 //// Inline functions
89 ////
90
91 inline Value PawnInfo::mg_value() const {
92   return Value(mgValue);
93 }
94
95 inline Value PawnInfo::eg_value() const {
96   return Value(egValue);
97 }
98
99 inline Bitboard PawnInfo::passed_pawns() const {
100   return passedPawns;
101 }
102
103 inline Value PawnInfo::kingside_storm_value(Color c) const {
104   return Value(ksStormValue[c]);
105 }
106
107 inline Value PawnInfo::queenside_storm_value(Color c) const {
108   return Value(qsStormValue[c]);
109 }
110
111 inline int PawnInfo::file_is_half_open(Color c, File f) const {
112   return (halfOpenFiles[c] & (1 << int(f)));
113 }
114
115 inline int PawnInfo::has_open_file_to_left(Color c, File f) const {
116   return halfOpenFiles[c] & ((1 << int(f)) - 1);
117 }
118
119 inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
120   return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
121 }
122
123 inline void PawnInfo::clear() {
124
125   passedPawns = EmptyBoardBB;
126   mgValue = egValue = 0;
127   ksStormValue[WHITE] = ksStormValue[BLACK] = 0;
128   qsStormValue[WHITE] = qsStormValue[BLACK] = 0;
129   halfOpenFiles[WHITE] = halfOpenFiles[BLACK] = 0xFF;
130 }
131
132
133 #endif // !defined(PAWNS_H_INCLUDED)