-/// Position::clear() erases the position object to a pristine state, with an
-/// empty board, white to move, and no castling rights.
-
-void Position::clear() {
-
- std::memset(this, 0, sizeof(Position));
- startState.epSquare = SQ_NONE;
- st = &startState;
-
- for (int i = 0; i < PIECE_TYPE_NB; ++i)
- for (int j = 0; j < 16; ++j)
- pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE;
-}
-
-
-/// Position::compute_key() computes the hash key of the position. The hash
-/// key is usually updated incrementally as moves are made and unmade. The
-/// compute_key() function is only used when a new position is set up, and
-/// to verify the correctness of the hash key when running in debug mode.
-
-Key Position::compute_key() const {
-
- Key k = Zobrist::castling[st->castlingFlags];
-
- for (Bitboard b = pieces(); b; )
- {
- Square s = pop_lsb(&b);
- k ^= Zobrist::psq[color_of(piece_on(s))][type_of(piece_on(s))][s];
- }
-
- if (ep_square() != SQ_NONE)
- k ^= Zobrist::enpassant[file_of(ep_square())];
-
- if (sideToMove == BLACK)
- k ^= Zobrist::side;
-
- return k;
-}
-
-
-/// Position::compute_pawn_key() computes the hash key of the position. The
-/// hash key is usually updated incrementally as moves are made and unmade.
-/// The compute_pawn_key() function is only used when a new position is set
-/// up, and to verify the correctness of the pawn hash key when running in
-/// debug mode.
-
-Key Position::compute_pawn_key() const {
-
- Key k = 0;
-
- for (Bitboard b = pieces(PAWN); b; )
- {
- Square s = pop_lsb(&b);
- k ^= Zobrist::psq[color_of(piece_on(s))][PAWN][s];
- }
-
- return k;
-}
-
-
-/// Position::compute_material_key() computes the hash key of the position.
-/// The hash key is usually updated incrementally as moves are made and unmade.
-/// The compute_material_key() function is only used when a new position is set
-/// up, and to verify the correctness of the material hash key when running in
-/// debug mode.
-
-Key Position::compute_material_key() const {
-
- Key k = 0;
-
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = PAWN; pt <= QUEEN; ++pt)
- for (int cnt = 0; cnt < pieceCount[c][pt]; ++cnt)
- k ^= Zobrist::psq[c][pt][cnt];
-
- return k;
-}
-
-
-/// Position::compute_psq_score() computes the incremental scores for the middlegame
-/// and the endgame. These functions are used to initialize the incremental scores
-/// when a new position is set up, and to verify that the scores are correctly
-/// updated by do_move and undo_move when the program is running in debug mode.
-
-Score Position::compute_psq_score() const {
-
- Score score = SCORE_ZERO;
-
- for (Bitboard b = pieces(); b; )
- {
- Square s = pop_lsb(&b);
- Piece pc = piece_on(s);
- score += psq[color_of(pc)][type_of(pc)][s];
- }
-
- return score;
-}
-
-
-/// Position::compute_non_pawn_material() computes the total non-pawn middlegame
-/// material value for the given side. Material values are updated incrementally
-/// during the search. This function is only used when initializing a new Position
-/// object.
-
-Value Position::compute_non_pawn_material(Color c) const {
-
- Value value = VALUE_ZERO;
-
- for (PieceType pt = KNIGHT; pt <= QUEEN; ++pt)
- value += pieceCount[c][pt] * PieceValue[MG][pt];
-
- return value;
-}
-
-
-/// Position::is_draw() tests whether the position is drawn by material, 50 moves
-/// rule or repetition. It does not detect stalemates.