/*
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
#include "types.h"
/// The checkInfo struct is initialized at c'tor time and keeps info used
/// to detect if a move gives check.
#include "types.h"
/// The checkInfo struct is initialized at c'tor time and keeps info used
/// to detect if a move gives check.
/// object to its previous state when we retract a move. Whenever a move
/// is made on the board (by calling Position::do_move), an StateInfo object
/// must be passed as a parameter.
/// object to its previous state when we retract a move. Whenever a move
/// is made on the board (by calling Position::do_move), an StateInfo object
/// must be passed as a parameter.
- Position(const Position& pos, int threadID);
- Position(const std::string& fen, bool isChess960, int threadID);
+ Position() {}
+ Position(const Position& pos, int th) { copy(pos, th); }
+ Position(const std::string& fen, bool isChess960, int th);
void from_fen(const std::string& fen, bool isChess960);
const std::string to_fen() const;
void print(Move m = MOVE_NONE) const;
// The piece on a given square
Piece piece_on(Square s) const;
void from_fen(const std::string& fen, bool isChess960);
const std::string to_fen() const;
void print(Move m = MOVE_NONE) const;
// The piece on a given square
Piece piece_on(Square s) const;
bool square_is_empty(Square s) const;
// Side to move
Color side_to_move() const;
// Bitboard representation of the position
bool square_is_empty(Square s) const;
// Side to move
Color side_to_move() const;
// Bitboard representation of the position
Bitboard pieces(Color c) const;
Bitboard pieces(PieceType pt) const;
Bitboard pieces(PieceType pt, Color c) const;
Bitboard pieces(Color c) const;
Bitboard pieces(PieceType pt) const;
Bitboard pieces(PieceType pt, Color c) const;
Square castle_rook_square(CastleRight f) const;
// Bitboards for pinned pieces and discovered check candidates
Square castle_rook_square(CastleRight f) const;
// Bitboards for pinned pieces and discovered check candidates
- Key get_key() const;
- Key get_exclusion_key() const;
- Key get_pawn_key() const;
- Key get_material_key() const;
+ Key key() const;
+ Key exclusion_key() const;
+ Key pawn_key() const;
+ Key material_key() const;
// Incremental evaluation
Score value() const;
Value non_pawn_material(Color c) const;
Score pst_delta(Piece piece, Square from, Square to) const;
// Incremental evaluation
Score value() const;
Value non_pawn_material(Color c) const;
Score pst_delta(Piece piece, Square from, Square to) const;
// Initialization helper functions (used while setting up a position)
void clear();
void put_piece(Piece p, Square s);
// Initialization helper functions (used while setting up a position)
void clear();
void put_piece(Piece p, Square s);
// Static variables
static Score pieceSquareTable[16][64]; // [piece][square]
static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count]
// Static variables
static Score pieceSquareTable[16][64]; // [piece][square]
static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count]
-inline Square Position::castle_rook_square(CastleRight f) const {
- return castleRookSquare[f];
+inline bool Position::castle_impeded(CastleRight f) const {
+ return byTypeBB[ALL_PIECES] & castlePath[f];
-template<>
-inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
- return StepAttacksBB[make_piece(c, PAWN)][s];
+inline Square Position::castle_rook_square(CastleRight f) const {
+ return castleRookSquare[f];
- return StepAttacksBB[Piece][s];
-}
-
-template<>
-inline Bitboard Position::attacks_from<BISHOP>(Square s) const {
- return bishop_attacks_bb(s, occupied_squares());
+ return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
+ : Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
+ : StepAttacksBB[Pt][s];
-inline Bitboard Position::attacks_from<ROOK>(Square s) const {
- return rook_attacks_bb(s, occupied_squares());
-}
-
-template<>
-inline Bitboard Position::attacks_from<QUEEN>(Square s) const {
- return attacks_from<ROOK>(s) | attacks_from<BISHOP>(s);
+inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
+ return StepAttacksBB[make_piece(c, PAWN)][s];
- return board[move_from(m)] == make_piece(sideToMove, PAWN)
- && pawn_is_passed(sideToMove, move_to(m));
+ return board[from_sq(m)] == make_piece(sideToMove, PAWN)
+ && pawn_is_passed(sideToMove, to_sq(m));
+inline bool Position::both_color_bishops(Color c) const {
+ // Assumes that there are only two bishops
+ return pieceCount[c][BISHOP] >= 2 &&
+ opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]);
+}
+
inline bool Position::has_pawn_on_7th(Color c) const {
return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7));
}
inline bool Position::has_pawn_on_7th(Color c) const {
return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7));
}
}
inline bool Position::is_capture(Move m) const {
// Note that castle is coded as "king captures the rook"
assert(is_ok(m));
}
inline bool Position::is_capture(Move m) const {
// Note that castle is coded as "king captures the rook"
assert(is_ok(m));