lib/chess/board.rb
# Sets a piece at the given square. An existing piece is replaced
Sets a piece at the given square. An existing piece is replaced
Sets a piece at the given square . An existing piece is replaced
def put(square, piece)
      remove(square)
      @pieces[square] = piece.piece_type
      mask = BB_SQUARES[square]
      if piece.piece_type == PAWN
        @pawns = @pawns | mask
      elsif piece.piece_type == KNIGHT
        @knights = @knights | mask
      elsif piece.piece_type == BISHOP
        @bishops = @bishops | mask
      elsif piece.piece_type == ROOK
        @rooks = @rooks | mask
      elsif piece.piece_type == QUEEN
        @queens = @queens | mask
      elsif piece.piece_type == KING
        @kings = @kings | mask
        @king_squares[piece.color] = square
      end
      @occupied                 = @occupied ^ mask
      @occupied_co[piece.color] = @occupied_co[piece.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 piece.color == BLACK
        piece_index = (piece.piece_type - 1) * 2
      else
        piece_index = (piece.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 put ( square , piece ) remove ( square ) @pieces [ square ] = piece . piece_type mask = BB_SQUARES [ square ] if piece . piece_type == PAWN @pawns = @pawns | mask elsif piece . piece_type == KNIGHT @knights = @knights | mask elsif piece . piece_type == BISHOP @bishops = @bishops | mask elsif piece . piece_type == ROOK @rooks = @rooks | mask elsif piece . piece_type == QUEEN @queens = @queens | mask elsif piece . piece_type == KING @kings = @kings | mask @king_squares [ piece . color ] = square end @occupied = @occupied ^ mask @occupied_co [ piece . color ] = @occupied_co [ piece . 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 piece . color == BLACK piece_index = ( piece . piece_type - 1 ) * 2 else piece_index = ( piece . 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
Sets a piece at the given square.
Sets a piece at the given square .
# Update incremental zorbist hash.
square
<not_specific>
piece
<not_specific>