lib/chess/board.rb
# Removes a piece from the given square if present
Removes a piece from the given square if present
Removes a piece from the given square if present
def remove(square)
      piece_type = pieces[square]
      return nil unless piece_type
      mask = BB_SQUARES[square]
      if piece_type == PAWN
        @pawns = @pawns ^ mask
      elsif piece_type == KNIGHT
        @knights = @knights ^ mask
      elsif piece_type == BISHOP
        @bishops = @bishops ^ mask
      elsif piece_type == ROOK
        @rooks = @rooks ^ mask
      elsif piece_type == QUEEN
        @queens = @queens ^ mask
      else
        @kings = @kings ^ mask
      end
      color = ((@occupied_co[BLACK] & mask).to_boolean).to_i
      @pieces[square]     = nil
      @occupied           = @occupied ^ mask
      @occupied_co[color] = @occupied_co[color] ^ mask
      @occupied_l90       = @occupied_l90 ^ BB_SQUARES[SQUARES_L90[square]]
      @occupied_r45       = @occupied_r45 ^ BB_SQUARES[SQUARES_R45[square]]
      @occupied_l45       = @occupied_l45 ^ BB_SQUARES[SQUARES_L45[square]]
      if color == BLACK
        piece_index = (piece_type - 1) * 2
      else
        piece_index = (piece_type - 1) * 2 + 1
      end
      @incremental_zobrist_hash = @incremental_zobrist_hash ^ Zobrist::POLYGLOT_RANDOM_ARRAY[64 * piece_index + 8 * rank_index(square) + file_index(square)]
    end
def remove ( square ) piece_type = pieces [ square ] return nil unless piece_type mask = BB_SQUARES [ square ] if piece_type == PAWN @pawns = @pawns ^ mask elsif piece_type == KNIGHT @knights = @knights ^ mask elsif piece_type == BISHOP @bishops = @bishops ^ mask elsif piece_type == ROOK @rooks = @rooks ^ mask elsif piece_type == QUEEN @queens = @queens ^ mask else @kings = @kings ^ mask end color = ( ( @occupied_co [ BLACK ] & mask ) . to_boolean ) . to_i @pieces [ square ] = nil @occupied = @occupied ^ mask @occupied_co [ color ] = @occupied_co [ color ] ^ mask @occupied_l90 = @occupied_l90 ^ BB_SQUARES [ SQUARES_L90 [ square ] ] @occupied_r45 = @occupied_r45 ^ BB_SQUARES [ SQUARES_R45 [ square ] ] @occupied_l45 = @occupied_l45 ^ BB_SQUARES [ SQUARES_L45 [ square ] ] if color == BLACK piece_index = ( piece_type - 1 ) * 2 else piece_index = ( piece_type - 1 ) * 2 + 1 end @incremental_zobrist_hash = @incremental_zobrist_hash ^ Zobrist :: POLYGLOT_RANDOM_ARRAY [ 64 * piece_index + 8 * rank_index ( square ) + file_index ( square ) ] end
Removes a piece from the given square if present
Removes a piece from the given square if present
# Update incremental zobrist hash.
square
<not_specific>