+inline void Position::put_piece(Piece pc, Square s) {
+
+ board[s] = pc;
+ byTypeBB[ALL_PIECES] |= s;
+ byTypeBB[type_of(pc)] |= s;
+ byColorBB[color_of(pc)] |= s;
+ index[s] = pieceCount[pc]++;
+ pieceList[pc][index[s]] = s;
+ pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
+}
+
+inline void Position::remove_piece(Piece pc, Square s) {
+
+ // WARNING: This is not a reversible operation. If we remove a piece in
+ // do_move() and then replace it in undo_move() we will put it at the end of
+ // the list and not in its original place, it means index[] and pieceList[]
+ // are not invariant to a do_move() + undo_move() sequence.
+ byTypeBB[ALL_PIECES] ^= s;
+ byTypeBB[type_of(pc)] ^= s;
+ byColorBB[color_of(pc)] ^= s;
+ /* board[s] = NO_PIECE; Not needed, overwritten by the capturing one */
+ Square lastSquare = pieceList[pc][--pieceCount[pc]];
+ index[lastSquare] = index[s];
+ pieceList[pc][index[lastSquare]] = lastSquare;
+ pieceList[pc][pieceCount[pc]] = SQ_NONE;
+ pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
+}
+
+inline void Position::move_piece(Piece pc, Square from, Square to) {
+
+ // index[from] is not updated and becomes stale. This works as long as index[]
+ // is accessed just by known occupied squares.
+ Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
+ byTypeBB[ALL_PIECES] ^= from_to_bb;
+ byTypeBB[type_of(pc)] ^= from_to_bb;
+ byColorBB[color_of(pc)] ^= from_to_bb;
+ board[from] = NO_PIECE;
+ board[to] = pc;
+ index[to] = index[from];
+ pieceList[pc][index[to]] = to;
+}
+
+inline void Position::do_move(Move m, StateInfo& newSt) {
+ do_move(m, newSt, gives_check(m));
+}
+
+#endif // #ifndef POSITION_H_INCLUDED