]> git.sesse.net Git - stockfish/blob - src/pawns.h
Drop not defended by pawn condition
[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-2014 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 #ifndef PAWNS_H_INCLUDED
21 #define PAWNS_H_INCLUDED
22
23 #include "misc.h"
24 #include "position.h"
25 #include "types.h"
26
27 namespace Pawns {
28
29 /// Pawns::Entry contains various information about a pawn structure. Currently,
30 /// it only includes a middlegame and endgame pawn structure evaluation, and a
31 /// bitboard of passed pawns. We may want to add further information in the future.
32 /// A lookup to the pawn hash table (performed by calling the probe function)
33 /// returns a pointer to an Entry object.
34
35 struct Entry {
36
37   Score pawns_value() const { return value; }
38   Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
39   Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
40   Bitboard candidate_pawns(Color c) const { return candidatePawns[c]; }
41   int pawns_on_same_color_squares(Color c, Square s) const { return pawnsOnSquares[c][!!(DarkSquares & s)]; }
42   int semiopen(Color c, File f) const { return semiopenFiles[c] & (1 << int(f)); }
43   int semiopen_on_side(Color c, File f, bool left) const {
44
45     return semiopenFiles[c] & (left ? ((1 << int(f)) - 1) : ~((1 << int(f+1)) - 1));
46   }
47
48   template<Color Us>
49   Score king_safety(const Position& pos, Square ksq)  {
50
51     return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
52          ? kingSafety[Us] : update_safety<Us>(pos, ksq);
53   }
54
55   template<Color Us>
56   Score update_safety(const Position& pos, Square ksq);
57
58   template<Color Us>
59   Value shelter_storm(const Position& pos, Square ksq);
60
61   Key key;
62   Bitboard passedPawns[COLOR_NB];
63   Bitboard candidatePawns[COLOR_NB];
64   Bitboard pawnAttacks[COLOR_NB];
65   Square kingSquares[COLOR_NB];
66   int minKPdistance[COLOR_NB];
67   int castlingRights[COLOR_NB];
68   Score value;
69   int semiopenFiles[COLOR_NB];
70   Score kingSafety[COLOR_NB];
71   int pawnsOnSquares[COLOR_NB][COLOR_NB];
72 };
73
74 typedef HashTable<Entry, 16384> Table;
75
76 void init();
77 Entry* probe(const Position& pos, Table& entries);
78
79 }
80
81 #endif // #ifndef PAWNS_H_INCLUDED