2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
2021-01-08 09:04:23 -07:00
|
|
|
Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2009-01-07 06:28:04 -07:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2009-01-07 06:28:04 -07:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-07-23 07:31:57 -06:00
|
|
|
#ifndef PAWNS_H_INCLUDED
|
2008-08-31 23:59:13 -06:00
|
|
|
#define PAWNS_H_INCLUDED
|
|
|
|
|
2012-03-31 05:15:57 -06:00
|
|
|
#include "misc.h"
|
2010-08-26 04:13:07 -06:00
|
|
|
#include "position.h"
|
2011-02-23 13:27:22 -07:00
|
|
|
#include "types.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
namespace Stockfish::Pawns {
|
2010-08-21 11:57:52 -06:00
|
|
|
|
2014-04-13 05:35:58 -06:00
|
|
|
/// Pawns::Entry contains various information about a pawn structure. A lookup
|
|
|
|
/// to the pawn hash table (performed by calling the probe function) returns a
|
|
|
|
/// pointer to an Entry object.
|
2011-04-11 01:54:41 -06:00
|
|
|
|
2012-12-22 03:21:06 -07:00
|
|
|
struct Entry {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2018-02-20 09:10:37 -07:00
|
|
|
Score pawn_score(Color c) const { return scores[c]; }
|
2012-12-22 03:21:06 -07:00
|
|
|
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
|
|
|
|
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
|
2015-11-14 07:30:50 -07:00
|
|
|
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
|
2019-03-31 04:02:19 -06:00
|
|
|
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
|
2020-04-29 09:39:25 -06:00
|
|
|
int blocked_count() const { return blockedCount; }
|
2013-05-11 01:29:02 -06:00
|
|
|
|
2010-08-26 04:13:07 -06:00
|
|
|
template<Color Us>
|
2018-11-10 20:49:13 -07:00
|
|
|
Score king_safety(const Position& pos) {
|
2018-12-11 05:47:56 -07:00
|
|
|
return kingSquares[Us] == pos.square<KING>(Us) && castlingRights[Us] == pos.castling_rights(Us)
|
2018-11-10 20:49:13 -07:00
|
|
|
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos));
|
2012-12-22 03:21:06 -07:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-08-26 04:13:07 -06:00
|
|
|
template<Color Us>
|
2018-11-10 20:49:13 -07:00
|
|
|
Score do_king_safety(const Position& pos);
|
2012-03-28 04:44:41 -06:00
|
|
|
|
|
|
|
template<Color Us>
|
2020-06-21 07:21:46 -06:00
|
|
|
Score evaluate_shelter(const Position& pos, Square ksq) const;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
Key key;
|
2018-02-20 09:10:37 -07:00
|
|
|
Score scores[COLOR_NB];
|
2012-10-21 02:41:23 -06:00
|
|
|
Bitboard passedPawns[COLOR_NB];
|
|
|
|
Bitboard pawnAttacks[COLOR_NB];
|
2015-11-14 07:30:50 -07:00
|
|
|
Bitboard pawnAttacksSpan[COLOR_NB];
|
2012-10-21 02:41:23 -06:00
|
|
|
Square kingSquares[COLOR_NB];
|
2014-04-13 05:35:58 -06:00
|
|
|
Score kingSafety[COLOR_NB];
|
2014-03-08 07:08:55 -07:00
|
|
|
int castlingRights[COLOR_NB];
|
2020-04-29 09:39:25 -06:00
|
|
|
int blockedCount;
|
2008-08-31 23:59:13 -06:00
|
|
|
};
|
|
|
|
|
2019-06-13 23:36:42 -06:00
|
|
|
typedef HashTable<Entry, 131072> Table;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-12-30 02:31:50 -07:00
|
|
|
Entry* probe(const Position& pos);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
} // namespace Stockfish::Pawns
|
2009-05-16 08:15:05 -06:00
|
|
|
|
2013-07-23 07:31:57 -06:00
|
|
|
#endif // #ifndef PAWNS_H_INCLUDED
|