codebreaker_kub 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1f87c8960638cc276a0e4696362cae4a24d49cd34cfc994bc75b1a50f6460a9
4
- data.tar.gz: 9156070ec7042aab41049a171a876d78ef55785d846d8c5d863771243480eadb
3
+ metadata.gz: 9b0615cbf8d40317a2e5352dab95e976cdd1e573520751ed35fcda4d231ce983
4
+ data.tar.gz: bbccf67ba8e10d137208430b08402099781b77ed0556230993b8d54393ed5628
5
5
  SHA512:
6
- metadata.gz: cb5a4a7bc9b7395e7fbd57b28410b66ad18bc465678f3d603611b7c7eeea5974496570b0aa3c6a0ce867a38aa232607a4fa25ff5f5129f0c39fea84da2bfda25
7
- data.tar.gz: d440bc81a3ceb655c4557bf6d7566f1f842e2a48519710937ac9576e1e9f923e1d580dc1d455b36f44fffa6a26513c3073cf5f18504d387161b96864119d47e8
6
+ metadata.gz: 4cd86ab7a4a57953649870cb06af1acd31981fe5f5969b376a30766a67fe1abf5286b228b4acc148ebbd2608e96f54f9c468fb40934ebcf5f990a116f43f9242
7
+ data.tar.gz: 6395a16dc75d491deb9bc770c12c074a1bb45a6b2070a3b2ee5c766e17c25359d42160a4527e7cbdb200e0c395de808bcfc337f9fbd4e18cf20c53c080fc19d9
@@ -5,7 +5,7 @@ module Codebreaker
5
5
  include Codebreaker::GuessChecker
6
6
 
7
7
  attr_accessor :input_code, :code, :name, :difficulties, :difficulty, :hints_left, :attempts_left
8
- attr_reader :minuse, :plus, :none, :hints_code
8
+ attr_reader :hints_code
9
9
 
10
10
  CODE_LENGTH = 4
11
11
  CODE_RANGE = (1..6).freeze
@@ -36,6 +36,7 @@ module Codebreaker
36
36
  end
37
37
 
38
38
  def input_operation(input_code)
39
+ @input_code = input_code
39
40
  return unless attempts_left?
40
41
 
41
42
  @attempts_left -= 1
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ module GuessChecker
5
+ MINUSE = '-'
6
+ PLUS = '+'
7
+ NONE = ''
8
+
9
+ def symbols(inexact = MINUSE, exact = PLUS, none = NONE)
10
+ @inexact = inexact
11
+ @exact = exact
12
+ @none = none
13
+ end
14
+
15
+ def check_input(code, input)
16
+ raw_result = inexact(code.chars, input.chars)
17
+ exact(code.chars, input.chars, raw_result)
18
+ end
19
+
20
+ def inexact(code, input)
21
+ inexact = (code & input).map { |element| [code.count(element), input.count(element)].min }.sum
22
+ @inexact * inexact
23
+ end
24
+
25
+ def exact(code, input, result)
26
+ input.each.with_index do |element, index|
27
+ result.sub!(@inexact, @exact) if element == code[index]
28
+ end
29
+ return result unless result.empty?
30
+
31
+ @none
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codebreaker
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - katia kub
@@ -120,6 +120,7 @@ files:
120
120
  - lib/codebreaker/data/difficulties.yml
121
121
  - lib/codebreaker/data/locales/en.yml
122
122
  - lib/codebreaker/game.rb
123
+ - lib/codebreaker/guess_checker.rb
123
124
  - lib/codebreaker/loader.rb
124
125
  - lib/codebreaker/output.rb
125
126
  - lib/codebreaker/validation.rb