Sha256: 1c9d74c0af62e13336e6484d336a94d428d4a7d4908789b8cfdce7294278f6c6
Contents?: true
Size: 559 Bytes
Versions: 1
Compression:
Stored size: 559 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) game.attempts[:available] -= 1 game.attempts[:used] += 1 game.attempts[:available].zero ? 'loss' : result end def assess_guess(numbers) 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.4 | lib/codebreaker_kirill/guess_handler.rb |