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