Sha256: 97d6509fc0e1d97b0358bae36631543545e4b2b98d05a2cb40e2a18d083f4308

Contents?: true

Size: 571 Bytes

Versions: 1

Compression:

Stored size: 571 Bytes

Contents

# frozen_string_literal: true

module GuessHandler
  def respond_to_guess(game, input, code)
    result = []
    numbers = input.split('').map(&:to_i)
    return 'win' if numbers == code

    game.assess_guess(numbers, code)
    game.attempts[:available] -= 1
    game.attempts[:used] += 1
    game.attempts[:available].zero ? 'loss' : result
  end

  def assess_guess(numbers, code)
    numbers.each_with_index do |element, index|
      if element == code[index]
        result << '+'
      elsif code.include?(element)
        result << '-'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_kirill-0.2.5 lib/codebreaker_kirill/guess_handler.rb