/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-/// FEN string for the initial position:
-const std::string StartPosition =
- "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
+/// FEN string for the initial position
+const std::string StartPosition = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
/// Maximum number of plies per game (220 should be enough, because the
/// maximum search depth is 100, and during position setup we reset the
/// Maximum number of plies per game (220 should be enough, because the
/// maximum search depth is 100, and during position setup we reset the
///
/// * For each piece type, a bitboard representing the squares occupied
/// by pieces of that type.
///
/// * For each piece type, a bitboard representing the squares occupied
/// by pieces of that type.
/// pieces of that color.
/// * A bitboard of all occupied squares.
/// * A bitboard of all checking pieces.
/// * A 64-entry array of pieces, indexed by the squares of the board.
/// * The current side to move.
/// * Information about the castling rights for both sides.
/// pieces of that color.
/// * A bitboard of all occupied squares.
/// * A bitboard of all checking pieces.
/// * A 64-entry array of pieces, indexed by the squares of the board.
/// * The current side to move.
/// * Information about the castling rights for both sides.
/// used to implement the Chess960 castling rules.
/// * The en passant square (which is SQ_NONE if no en passant capture is
/// possible).
/// * The squares of the kings for both sides.
/// used to implement the Chess960 castling rules.
/// * The en passant square (which is SQ_NONE if no en passant capture is
/// possible).
/// * The squares of the kings for both sides.
/// * Hash keys for the position itself, the current pawn structure, and
/// the current material situation.
/// * Hash keys for the position itself, the current pawn structure, and
/// the current material situation.
// Information about pawns
bool pawn_is_passed(Color c, Square s) const;
// Information about pawns
bool pawn_is_passed(Color c, Square s) const;
- bool pawn_is_isolated(Color c, Square s) const;
- bool pawn_is_doubled(Color c, Square s) const;
-
- // Open and half-open files
- bool file_is_open(File f) const;
- bool file_is_half_open(Color c, File f) const;
+ static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
+ static bool pawn_is_isolated(Bitboard ourPawns, Square s);
+ static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
// Weak squares
bool square_is_weak(Square s, Color c) const;
// Doing and undoing moves
// Weak squares
bool square_is_weak(Square s, Color c) const;
// Doing and undoing moves
void do_move(Move m, StateInfo& st);
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
void undo_move(Move m);
void do_move(Move m, StateInfo& st);
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
void undo_move(Move m);
int see(Square from, Square to) const;
int see(Move m) const;
int see(Square to) const;
int see(Square from, Square to) const;
int see(Move m) const;
int see(Square to) const;
- void do_capture_move(PieceType capture, Color them, Square to);
+ void do_capture_move(PieceType capture, Color them, Square to, bool ep);
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
template<GamePhase> Value compute_value() const;
Value compute_non_pawn_material(Color c) const;
template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
template<GamePhase> Value compute_value() const;
Value compute_non_pawn_material(Color c) const;
inline int Position::piece_count(Color c, PieceType pt) const {
return pieceCount[c][pt];
}
inline int Position::piece_count(Color c, PieceType pt) const {
return pieceCount[c][pt];
}
-template<>
-inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
- return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
+template<PieceType Piece> // Knight and King
+inline Bitboard Position::piece_attacks(Square s) const {
+ return StepAttackBB[Piece][s];
-inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
- return StepAttackBB[KNIGHT][s];
+inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
+ return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
-inline bool Position::pawn_is_isolated(Color c, Square s) const {
- return !(pawns(c) & neighboring_files_bb(s));
-}
-
-inline bool Position::pawn_is_doubled(Color c, Square s) const {
- return pawns(c) & squares_behind(c, s);
+inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
+ return !(theirPawns & passed_pawn_mask(c, s));
-inline bool Position::file_is_open(File f) const {
- return !(pawns() & file_bb(f));
+inline bool Position::pawn_is_isolated(Bitboard ourPawns, Square s) {
+ return !(ourPawns & neighboring_files_bb(s));
-inline bool Position::file_is_half_open(Color c, File f) const {
- return !(pawns(c) & file_bb(f));
+inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
+ return ourPawns & squares_behind(c, s);
- return (Phase == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
- : EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
+ return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
+ : EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
-inline Value Position::mg_pst_delta(Move m) const {
- return MgPieceSquareTable[piece_on(move_from(m))][move_to(m)]
- -MgPieceSquareTable[piece_on(move_from(m))][move_from(m)];
+template<Position::GamePhase Ph>
+inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
+ return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
+ : EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);