# frozen_string_literal: true module GuessHandler def respond_to_guess(game, input, code) @result = [] @code_clone = code.clone @numbers = input.split('').map(&:to_i) return 'win' if @numbers == code assess_guess(@code_clone, @numbers) game.attempts[:used] += 1 game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort end def assess_guess(code, input) input.each_with_index { |element, index| @code_clone[index] = '+' if element == @code_clone[index] } @result = code.each_with_index do |el, index| if input.include?(el) @code_clone[index] = '-' input.slice!(@numbers.index(el)) end end end end