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