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)
|
2014-01-01 17:48:07 -07:00
|
|
|
Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, 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
|
|
|
|
2014-12-27 02:47:21 -07:00
|
|
|
Score pawns_score() const { return score; }
|
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]; }
|
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 semiopen_side(Color c, File f, bool leftSide) const {
|
|
|
|
return semiopenFiles[c] & (leftSide ? (1 << f) - 1 : ~((1 << (f + 1)) - 1));
|
|
|
|
}
|
|
|
|
|
2014-06-25 14:01:00 -06:00
|
|
|
int pawn_span(Color c) const {
|
|
|
|
return pawnSpan[c];
|
|
|
|
}
|
|
|
|
|
2014-04-13 05:35:58 -06:00
|
|
|
int pawns_on_same_color_squares(Color c, Square s) const {
|
|
|
|
return pawnsOnSquares[c][!!(DarkSquares & s)];
|
2013-05-04 03:42:34 -06:00
|
|
|
}
|
2010-08-26 04:13:07 -06:00
|
|
|
|
|
|
|
template<Color Us>
|
2012-12-22 03:21:06 -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>
|
2012-03-28 23:04:44 -06:00
|
|
|
Value shelter_storm(const Position& pos, Square ksq);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
Key key;
|
2014-12-27 02:47:21 -07:00
|
|
|
Score score;
|
2012-10-21 02:41:23 -06:00
|
|
|
Bitboard passedPawns[COLOR_NB];
|
|
|
|
Bitboard pawnAttacks[COLOR_NB];
|
|
|
|
Square kingSquares[COLOR_NB];
|
2014-04-13 05:35:58 -06:00
|
|
|
Score kingSafety[COLOR_NB];
|
2014-12-07 16:53:33 -07:00
|
|
|
int minKingPawnDistance[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-06-25 14:01:00 -06:00
|
|
|
int pawnSpan[COLOR_NB];
|
2014-04-13 05:35:58 -06:00
|
|
|
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
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();
|
2012-12-22 03:21:06 -07:00
|
|
|
Entry* probe(const Position& pos, Table& entries);
|
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
|