# frozen_string_literal: true require_relative 'autoload' module CodebreakerKirill class GuessHandler include Settings def initialize(input, code) CodebreakerKirill::Validations.validate_guess(input) @input = input.each_char.map(&:to_i) @code = code.clone @result = [] end def call check_same_indexes check_different_indexes @result end def check_same_indexes @input.each_index do |index| next unless @input[index] == @code[index] @result << CodebreakerKirill::Settings::POSITIVE_RESPONSE @input[index], @code[index] = nil end end def check_different_indexes @input.each_with_index do |value, _index| next unless !value.nil? && @code.include?(value) @result << CodebreakerKirill::Settings::NEGATIVE_RESPONSE @input[@input.find_index(value)], @code[@code.find_index(value)] = nil end end end end