def castle(index)
      valid = []
      dangerous_tiles = attack_vectors

      # King may never have moved
      return valid unless [5, 61].include?(index) && Move.pieces[index][:moved] == false

      # Ensure empty space between a King and a Rook
      #if (1..3).all? { |i| unoccupied?(index - i) } && @pieces[index - 4][:moved] == false
      if unoccupied?(index - 1) && unoccupied?(index - 2) && unoccupied?(index - 3) && 
          Move.pieces[index - 4][:moved] == false
        # Ensure king does not move through check or into check, and then add its castle position
        valid << index - 2 if !dangerous_tiles.include?(index - 1) && !dangerous_tiles.include?(index - 2)
      end

      if unoccupied?(index + 1) && unoccupied?(index + 2) && Move.pieces[index + 3][:moved] == false
        valid << index + 2 if !dangerous_tiles.include?(index + 1) && !dangerous_tiles.include?(index + 2)
      end

      valid
    end
def castle(index)
      valid = []
      dangerous_tiles = attack_vectors

      # King may never have moved
      return valid unless [5, 61].include?(index) && Move.pieces[index][:moved] == false

      # Ensure empty space between a King and a Rook
      #if (1..3).all? { |i| unoccupied?(index - i) } && @pieces[index - 4][:moved] == false
      if unoccupied?(index - 1) && unoccupied?(index - 2) && unoccupied?(index - 3) && 
          Move.pieces[index - 4][:moved] == false
        # Ensure king does not move through check or into check, and then add its castle position
        valid << index - 2 if !dangerous_tiles.include?(index - 1) && !dangerous_tiles.include?(index - 2)
      end

      if unoccupied?(index + 1) && unoccupied?(index + 2) && Move.pieces[index + 3][:moved] == false
        valid << index + 2 if !dangerous_tiles.include?(index + 1) && !dangerous_tiles.include?(index + 2)
      end

      valid
    end
Castle: king cannot move into check, or through check