codebracker_simb 0.9.1 → 0.9.2

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: 507c25bcdf25b4b0fb5681407f6988a624f08ee2af4edeca36059f184589c5c2
4
- data.tar.gz: 561816aac6a2a523f90a727e756801a1ac7c0ac343e54c5a9fefaaa4f889d960
3
+ metadata.gz: 5fb48922b8d9ad8dde56070931894b9999355fa3da6b03f964df7aacfb41578a
4
+ data.tar.gz: 8a3c6f2e00c2bedcb37f021ff4a86e4518ec3e9674eb96e16f39eb062b1bada8
5
5
  SHA512:
6
- metadata.gz: 66834bb9e38c34d12acb547733c77abede7f52fdcee0a827922a052a1355969d10eb7ed7bd3bf05606f0b4e6c982bd3323bc2844cf9f4c4136a8b3ab0e17151b
7
- data.tar.gz: a91977fef08f6802389bf5500ab40c747a94b7a4fa934716acffdce2fd02898ce57097d57a494b826dcf7d79a5850f0916e5a2bf060b762607bfbbde11b03057
6
+ metadata.gz: 68e47ec8fb79997e7be48e5c06425bdf484454fe1e2731fbbd0648976b16b58c4baae18d03996d56722ee09a79b3883382c20768bca389df3f3389314d335bdf
7
+ data.tar.gz: 7c446f5ec698df5c6c9483404ed6dbfde9e2fa0b0d7f4ed4fbb7857fb3b32a72734015202bf2688aa60c37ba9179742b8cafd80cc327110fa690bf67200b9b5c
@@ -2,12 +2,12 @@
2
2
 
3
3
  module CodebrackerSimb
4
4
  # builds table of equality for answer and code and gives string result
5
- class Checker < Array
6
- def initialize(code, ans)
7
- @ans = ans
5
+ class Checker
6
+ def initialize(code, answer)
7
+ @answer = answer
8
8
  @code = code
9
9
  @filled_column = []
10
- super([[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]])
10
+ @table = [[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]]
11
11
  end
12
12
 
13
13
  def compare
@@ -24,7 +24,7 @@ module CodebrackerSimb
24
24
 
25
25
  def output
26
26
  output = []
27
- each do |line|
27
+ @table.each do |line|
28
28
  output << '+' if line.include?(:plus)
29
29
  output << '-' if line.include?(:minus) && !line.include?(:plus)
30
30
  end
@@ -32,22 +32,22 @@ module CodebrackerSimb
32
32
  end
33
33
 
34
34
  def fill_with_plus
35
- each_with_index do |line, i|
36
- if @code[i] == @ans[i]
37
- line[i] = :plus
38
- @filled_column << i
35
+ @table.each_with_index do |line, index|
36
+ if @code[index] == @answer[index]
37
+ line[index] = :plus
38
+ @filled_column << index
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
43
  def fill_with_minus
44
- each_with_index do |line, i|
45
- line.each_with_index do |_el, j|
46
- next unless @code[i] == @ans[j] && !line[j] && !@filled_column.include?(j)
44
+ @table.each_with_index do |line, index|
45
+ line.each_with_index do |_, jndex|
46
+ next unless @code[index] == @answer[jndex] && !line[jndex] && !@filled_column.include?(jndex)
47
47
  next if line.include? :minus
48
48
 
49
- line[j] = :minus
50
- @filled_column << j
49
+ line[jndex] = :minus
50
+ @filled_column << jndex
51
51
  end
52
52
  end
53
53
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './code'
4
3
  require_relative './checker'
5
4
  require 'rspec'
6
5
  require 'pry'
@@ -36,10 +35,11 @@ module CodebrackerSimb
36
35
  end
37
36
 
38
37
  def input_answer(input)
39
- @answer = Code.new(input)
38
+ @answer = input.split('').map(&:to_i)
40
39
  end
41
40
 
42
41
  def check_answer
42
+ refresh_attempts_quantity
43
43
  Checker.new(@code, @answer).compare
44
44
  end
45
45
 
@@ -54,20 +54,19 @@ module CodebrackerSimb
54
54
  def refresh_attempts_quantity
55
55
  if @attempts.positive?
56
56
  @attempts -= 1
57
- "#{@attempts} left"
58
57
  end
59
58
  end
60
59
 
61
60
  def hint
62
- pos = nil
61
+ position = nil
63
62
  loop do
64
- pos = rand(0..3)
65
- break unless hint_positions.include? pos
63
+ position = rand(0..3)
64
+ break unless hint_positions.include? position
66
65
  end
67
66
  if @hints.positive?
68
- hint_positions << pos
67
+ hint_positions << position
69
68
  @hints -= 1
70
- code[pos]
69
+ code[position]
71
70
  else
72
71
  raise NoHintsError
73
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -12,5 +12,5 @@ require_relative 'codebracker_simb/text'
12
12
 
13
13
  # gem module
14
14
  module CodebrackerSimb
15
- YOLO = 'YOLO'
15
+
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebracker_simb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - max
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-01 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -91,7 +91,6 @@ files:
91
91
  - codebracker_simb.gemspec
92
92
  - lib/codebracker_simb.rb
93
93
  - lib/codebracker_simb/checker.rb
94
- - lib/codebracker_simb/code.rb
95
94
  - lib/codebracker_simb/errors/code_error.rb
96
95
  - lib/codebracker_simb/errors/complexity_error.rb
97
96
  - lib/codebracker_simb/errors/intro_error.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CodebrackerSimb
4
- # return array from users input
5
- class Code < Array
6
- def initialize(str)
7
- arr = str.split('').map(&:to_i)
8
- super(arr)
9
- end
10
- end
11
- end