class RockPaperScissorsGame
  CHOICES = %w[rock paper scissors quit]
  BEATS = {
    'rock'     => 'paper',
    'paper'    => 'scissors',
    'scissors' => 'rock',
  }

  def initialize()
    @plays = {
      'rock'     => 1,
      'paper'    => 1,
      'scissors' => 1,
    }
    @score = [0, 0, 0]          

    play
  end

  def humanPlay
    loop do
      print 
      answer = STDIN.gets.strip.downcase
      next if answer.empty?
      idx = CHOICES.find_index {|choice| choice.match(/^
      return CHOICES[idx] if idx
      puts 
    end
  end

  def computerPlay
    total = @plays.values.reduce(:+)
    r = rand(total) + 1
    sum = 0
    CHOICES.each do |choice|
      sum += @plays[choice]
      return BEATS[choice] if r <= sum
    end
  end

  def play
    loop do
      h = humanPlay
      break if h == 
      c = computerPlay
      print 

      
      @plays[h] += 1

      if h == c
        puts 
        @score[2] += 1
      elsif h == BEATS[c]
        puts 
        @score[0] += 1
      else
        puts 
        @score[1] += 1
      end
      puts  % [*@score]
    end
    @plays.each_key{|k| @plays[k] -= 1}
    puts 
  end
end

RockPaperScissorsGame.new