module AlexCodebreaker class Game include AlexCodebreaker::Modules::ArgumentsValidation attr_reader :secret_code, :session def initialize @secret_code = AlexCodebreaker::SecretCodeGenerator.new.secret_code @secret_code_for_hint = @secret_code.clone.uniq @session = Session.new end def hint return unless @session.check_hints process_hint end def guess(user_input) return unless guess_validation(user_input) && @session.check_attempts compare_codes(user_input) end private def process_hint return @secret_code_for_hint.first if @secret_code_for_hint.one? @secret_code_for_hint.delete(@secret_code_for_hint.sample) end def compare_codes(user_input) user_input = format_user_input(user_input) comparison = Comparison.new(user_input, @secret_code.clone) comparison.response end def format_user_input(user_input) user_input.chars.map(&:to_i) end end end