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
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.
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.
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/>.
21 #if !defined(PAWNS_H_INCLUDED)
22 #define PAWNS_H_INCLUDED
35 const int PawnTableSize = 16384;
37 /// PawnInfo is a class which contains various information about a pawn
38 /// structure. Currently, it only includes a middle game and an end game
39 /// pawn structure evaluation, and a bitboard of passed pawns. We may want
40 /// to add further information in the future. A lookup to the pawn hash table
41 /// (performed by calling the get_pawn_info method in a PawnInfoTable object)
42 /// returns a pointer to a PawnInfo object.
47 friend class PawnInfoTable;
50 Score pawns_value() const;
51 Value kingside_storm_value(Color c) const;
52 Value queenside_storm_value(Color c) const;
53 Bitboard pawn_attacks(Color c) const;
54 Bitboard passed_pawns(Color c) const;
55 int file_is_half_open(Color c, File f) const;
56 int has_open_file_to_left(Color c, File f) const;
57 int has_open_file_to_right(Color c, File f) const;
58 Score king_shelter(const Position& pos, Color c, Square ksq);
61 Score updateShelter(const Position& pos, Color c, Square ksq);
64 Bitboard passedPawns[2];
65 Bitboard pawnAttacks[2];
66 Square kingSquares[2];
71 Score kingShelters[2];
74 /// The PawnInfoTable class represents a pawn hash table. It is basically
75 /// just an array of PawnInfo objects and a few methods for accessing these
76 /// objects. The most important method is get_pawn_info, which looks up a
77 /// position in the table and returns a pointer to a PawnInfo object.
81 enum SideType { KingSide, QueenSide };
86 PawnInfo* get_pawn_info(const Position& pos) const;
87 void prefetch(Key key) const;
91 Score evaluate_pawns(const Position& pos, Bitboard ourPawns, Bitboard theirPawns, PawnInfo* pi) const;
93 template<Color Us, SideType Side>
94 int evaluate_pawn_storm(Square s, Rank r, File f, Bitboard theirPawns) const;
101 //// Inline functions
104 inline void PawnInfoTable::prefetch(Key key) const {
106 unsigned index = unsigned(key & (PawnTableSize - 1));
107 PawnInfo* pi = entries + index;
108 ::prefetch((char*) pi);
111 inline Score PawnInfo::pawns_value() const {
115 inline Bitboard PawnInfo::pawn_attacks(Color c) const {
116 return pawnAttacks[c];
119 inline Value PawnInfo::kingside_storm_value(Color c) const {
120 return Value(ksStormValue[c]);
123 inline Value PawnInfo::queenside_storm_value(Color c) const {
124 return Value(qsStormValue[c]);
127 inline Bitboard PawnInfo::passed_pawns(Color c) const {
128 return passedPawns[c];
131 inline int PawnInfo::file_is_half_open(Color c, File f) const {
132 return (halfOpenFiles[c] & (1 << int(f)));
135 inline int PawnInfo::has_open_file_to_left(Color c, File f) const {
136 return halfOpenFiles[c] & ((1 << int(f)) - 1);
139 inline int PawnInfo::has_open_file_to_right(Color c, File f) const {
140 return halfOpenFiles[c] & ~((1 << int(f+1)) - 1);
143 inline Score PawnInfo::king_shelter(const Position& pos, Color c, Square ksq) {
144 return kingSquares[c] == ksq ? kingShelters[c] : updateShelter(pos, c, ksq);
147 #endif // !defined(PAWNS_H_INCLUDED)