Sha256: 9530f94a6b8f60e8fa140c18aad0e8ba941d1bc87e40cc160638faf440bf6e7b

Contents?: true

Size: 801 Bytes

Versions: 6

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true
module Codebreaker
  class Core
    GUESSED_PLACE = '+'
    GUESSED_PRESENCE = '-'
    CB_ARRAY_SIZE = 4
    GAME_NUMBER_RANGE = (1..6).freeze

    def generate_secret_code
      CB_ARRAY_SIZE.times.map { rand(GAME_NUMBER_RANGE) }
    end

    def check(cb_numbers, guess_arr)
      result = ''
      code_guess_arr = cb_numbers.zip(guess_arr)
      code_after_each = []
      guess_after_each = []
      code_guess_arr.each do |unite_arr|
        if unite_arr.uniq.size == 1
          result += GUESSED_PLACE
        else
          code_after_each << unite_arr.first
          guess_after_each << unite_arr.last
        end
      end
      guess_after_each.each { |elem| result += GUESSED_PRESENCE if code_after_each.uniq.include?(elem) }
      result
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
codebreaker_kolyanjy-0.1.8 lib/entities/core.rb
codebreaker_kolyanjy-0.1.7 lib/entities/core.rb
codebreaker_kolyanjy-0.1.6 lib/entities/core.rb
codebreaker_kolyanjy-0.1.5 lib/entities/core.rb
codebreaker_kolyanjy-0.1.4 lib/entities/core.rb
codebreaker_kolyanjy-0.1.3 lib/entities/core.rb