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
|
|
|
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2016-01-02 02:43:25 -07:00
|
|
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
2018-01-01 02:33:07 -07:00
|
|
|
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
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
|
|
|
|
2012-12-22 03:21:06 -07:00
|
|
|
namespace 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]; }
|
2017-09-16 06:07:41 -06:00
|
|
|
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
|
2015-10-15 22:27:52 -06:00
|
|
|
int pawn_asymmetry() const { return asymmetry; }
|
2016-09-02 16:04:20 -06:00
|
|
|
int open_files() const { return openFiles; }
|
2013-05-11 01:29:02 -06:00
|
|
|
|
2014-04-13 05:35:58 -06:00
|
|
|
int semiopen_file(Color c, File f) const {
|
|
|
|
return semiopenFiles[c] & (1 << f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pawns_on_same_color_squares(Color c, Square s) const {
|
2017-12-03 10:29:55 -07:00
|
|
|
return pawnsOnSquares[c][bool(DarkSquares & s)];
|
2013-05-04 03:42:34 -06:00
|
|
|
}
|
2010-08-26 04:13:07 -06:00
|
|
|
|
|
|
|
template<Color Us>
|
2016-03-13 01:35:03 -07:00
|
|
|
Score king_safety(const Position& pos, Square ksq) {
|
2014-04-13 05:35:58 -06:00
|
|
|
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
|
|
|
|
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
|
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>
|
2014-04-13 05:35:58 -06:00
|
|
|
Score do_king_safety(const Position& pos, Square ksq);
|
2012-03-28 04:44:41 -06:00
|
|
|
|
|
|
|
template<Color Us>
|
2018-04-23 01:48:53 -06:00
|
|
|
Value evaluate_shelter(const Position& pos, Square ksq);
|
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];
|
2017-09-16 06:07:41 -06:00
|
|
|
int weakUnopposed[COLOR_NB];
|
2014-03-08 07:08:55 -07:00
|
|
|
int castlingRights[COLOR_NB];
|
2013-06-01 03:48:38 -06:00
|
|
|
int semiopenFiles[COLOR_NB];
|
2014-04-13 05:35:58 -06:00
|
|
|
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
2015-10-15 22:27:52 -06:00
|
|
|
int asymmetry;
|
2016-09-02 16:04:20 -06:00
|
|
|
int openFiles;
|
2008-08-31 23:59:13 -06:00
|
|
|
};
|
|
|
|
|
2012-12-22 03:21:06 -07:00
|
|
|
typedef HashTable<Entry, 16384> Table;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-10-12 13:03:49 -06:00
|
|
|
void init();
|
2014-12-30 02:31:50 -07:00
|
|
|
Entry* probe(const Position& pos);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-04-13 05:35:58 -06:00
|
|
|
} // namespace Pawns
|
2009-05-16 08:15:05 -06:00
|
|
|
|
2013-07-23 07:31:57 -06:00
|
|
|
#endif // #ifndef PAWNS_H_INCLUDED
|