codebreaker_diz 0.1.2 → 0.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: 5776f239b86da1fae9144099edf66640b13d65a4095d11839633ac3c1559c82d
4
- data.tar.gz: 8f7fce024e2706fad7396de4934f8178fe28299667c4e66018e1e39cf119dd82
3
+ metadata.gz: 482058e23ff46f61a8ef6fa05812096e7baf151d3482c11b543e5d0b788585ef
4
+ data.tar.gz: b851ab61b5934efbbee993d68532978d2e57f5ea0392670b05cf1ef4322c2d2e
5
5
  SHA512:
6
- metadata.gz: 35cb186d0fbabfefda9e1391d58bf2a733fc5410f3dbb55e56b2a72c19708c62454e1b8a5717fab8b913e6fcb49239cb5b0e13e12b43bbeeb61d2e05f500a05b
7
- data.tar.gz: 105bb6670197d51213bf51e449a5223383f4d0c948f50dc2b3c7c87bfda4dabf94de188d09c456ce7cfa3be2abf77ad581c7da5591ade4d73e27723948456539
6
+ metadata.gz: b4746b18fcb2b93c79c7f9811f8f0f060c3a7a2e7e3ff11ba15a14c70317d9a294f320303afab72ab74f9eea3f5a94640ac9bfc8c02532e4fa6e405980aefdf6
7
+ data.tar.gz: 36cbd04d2e67c8414e82ddae43765c1508b99105b32c0dce77a63329de6c5d5460231e53bd4bbdc406e14a8472f9c4c06bbb71849ab0487927136927fa3e015d
data/.rubocop.yml CHANGED
@@ -1,14 +1,39 @@
1
- AllCops:
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
5
+ RSpec/MessageChain:
6
+ Enabled: false
7
+
8
+ RSpec/NestedGroups:
9
+ Max: 5
10
+
11
+ RSpec/MultipleExpectations:
12
+ Max: 5
13
+
14
+ RSpec/ExampleLength:
15
+ Max: 10
16
+
17
+ RSpec/MessageSpies:
18
+ Enabled: false
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'Gemfile'
23
+ - 'spec/**/*.rb'
24
+
25
+ Metrics/ModuleLength:
2
26
  Exclude:
3
- - 'node_modules/**/*'
4
- - 'vendor/**/*'
5
- - '.git/**/*'
6
- - 'spec/**/*'
7
- - 'test/**/*'
8
- - 'bin/**/*'
9
- - 'codebreaker_diz.gemspec'
10
-
11
- Style/Documentation:
12
- Description: 'Document classes and non-namespace modules.'
27
+ - 'spec/**/*.rb'
28
+
29
+ Metrics/LineLength:
30
+ Max: 120
31
+
32
+ Documentation:
13
33
  Enabled: false
14
- VersionAdded: '0.9'
34
+
35
+ AllCops:
36
+ Exclude:
37
+ - 'bin/'
38
+ - '*.gemspec'
39
+ TargetRubyVersion: 2.5.5
data/Gemfile.lock CHANGED
@@ -1,21 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_diz (0.1.0)
4
+ codebreaker_diz (0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.0)
10
+ bundle-audit (0.1.0)
11
+ bundler-audit
12
+ bundler-audit (0.6.1)
13
+ bundler (>= 1.2.0, < 3)
14
+ thor (~> 0.18)
15
+ childprocess (0.9.0)
16
+ ffi (~> 1.0, >= 1.0.11)
17
+ coderay (1.1.2)
10
18
  colorize (0.8.1)
11
19
  diff-lcs (1.3)
20
+ docile (1.3.1)
12
21
  fasterer (0.5.1)
13
22
  colorize (~> 0.7)
14
23
  ruby_parser (>= 3.13.0)
24
+ ffi (1.11.1)
25
+ iniparse (1.4.4)
15
26
  jaro_winkler (1.5.2)
27
+ json (2.2.0)
28
+ method_source (0.9.2)
29
+ overcommit (0.48.0)
30
+ childprocess (~> 0.6, >= 0.6.3)
31
+ iniparse (~> 1.4)
16
32
  parallel (1.17.0)
17
33
  parser (2.6.3.0)
18
34
  ast (~> 2.4.0)
35
+ pry (0.12.2)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.9.0)
19
38
  rainbow (3.0.0)
20
39
  rake (10.5.0)
21
40
  rspec (3.8.0)
@@ -38,22 +57,38 @@ GEM
38
57
  rainbow (>= 2.2.2, < 4.0)
39
58
  ruby-progressbar (~> 1.7)
40
59
  unicode-display_width (>= 1.4.0, < 1.7)
41
- ruby-progressbar (1.10.0)
60
+ rubocop-performance (1.3.0)
61
+ rubocop (>= 0.68.0)
62
+ rubocop-rspec (1.33.0)
63
+ rubocop (>= 0.60.0)
64
+ ruby-progressbar (1.10.1)
42
65
  ruby_parser (3.13.1)
43
66
  sexp_processor (~> 4.9)
44
67
  sexp_processor (4.12.0)
68
+ simplecov (0.16.1)
69
+ docile (~> 1.1)
70
+ json (>= 1.8, < 3)
71
+ simplecov-html (~> 0.10.0)
72
+ simplecov-html (0.10.2)
73
+ thor (0.20.3)
45
74
  unicode-display_width (1.6.0)
46
75
 
47
76
  PLATFORMS
48
77
  ruby
49
78
 
50
79
  DEPENDENCIES
80
+ bundle-audit (~> 0.1.0)
51
81
  bundler (~> 2.0)
52
82
  codebreaker_diz!
53
83
  fasterer (~> 0.5.1)
84
+ overcommit (~> 0.48.0)
85
+ pry (~> 0.12.2)
54
86
  rake (~> 10.0)
55
87
  rspec (~> 3.8)
56
88
  rubocop (~> 0.69.0)
89
+ rubocop-performance (~> 1.3)
90
+ rubocop-rspec (~> 1.33)
91
+ simplecov (~> 0.16.1)
57
92
 
58
93
  BUNDLED WITH
59
94
  2.0.1
@@ -15,24 +15,10 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/bl0rch1d/codebreaker_diz'
16
16
  spec.license = 'MIT'
17
17
 
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
- if spec.respond_to?(:metadata)
21
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
-
23
- spec.metadata["homepage_uri"] = spec.homepage
24
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
25
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
26
- else
27
- raise "RubyGems 2.0 or newer is required to protect against " \
28
- "public gem pushes."
29
- end
30
-
31
- # Specify which files should be added to the gem when it is released.
32
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
18
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
34
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
20
  end
21
+
36
22
  spec.bindir = 'exe'
37
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
24
  spec.require_paths = ['lib']
@@ -42,5 +28,11 @@ Gem::Specification.new do |spec|
42
28
  spec.add_development_dependency 'rake', '~> 10.0'
43
29
  spec.add_development_dependency 'rspec', '~> 3.8'
44
30
  spec.add_development_dependency 'rubocop', '~> 0.69.0'
31
+ spec.add_development_dependency 'rubocop-performance', '~> 1.3'
32
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.33'
45
33
  spec.add_development_dependency 'fasterer', '~> 0.5.1'
34
+ spec.add_development_dependency 'overcommit', '~> 0.48.0'
35
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
36
+ spec.add_development_dependency 'pry', '~> 0.12.2'
37
+ spec.add_development_dependency 'bundle-audit', '~> 0.1.0'
46
38
  end
@@ -3,8 +3,11 @@
3
3
  module CodebreakerDiz
4
4
  CODE_LENGTH = 4
5
5
 
6
- MIN = 1
7
- MAX = 6
6
+ EXACT_MATCH_SIGN = '+'
7
+ NUMBER_MATCH_SIGN = '-'
8
+
9
+ MIN_CODE_NUMBER = 1
10
+ MAX_CODE_NUMBER = 6
8
11
 
9
12
  DIFFICULTIES = {
10
13
  kid: { tries: 15, hints: 2 },
@@ -1,129 +1,122 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'config'
4
+ require_relative 'matcher'
4
5
 
5
6
  module CodebreakerDiz
6
7
  class Game
7
- attr_reader :summary, :tries_count, :hints_count
8
+ attr_reader :tries_count, :hints_count
8
9
 
9
10
  def initialize
10
- set_default_difficulty
11
+ @difficulty = :kid
12
+
13
+ @secret = []
14
+
15
+ @tries_count = 0
16
+ @hints_count = 0
17
+
18
+ @tries_used = 0
19
+ @hints_used = 0
20
+
21
+ @guess_result = ''
22
+
23
+ @hint = nil
24
+ @hint_indexes = []
25
+
26
+ @game_iteration_count = 0
11
27
  end
12
28
 
13
29
  def difficulty(value)
14
30
  raise ArgumentError unless DIFFICULTIES.include? value.to_sym
15
31
 
16
32
  @difficulty = value.to_sym
17
- @difficulty_data = DIFFICULTIES[value.to_sym]
18
33
  end
19
34
 
20
35
  def prepare_data
21
- @hints = (0...CODE_LENGTH).to_a
22
- @code = Array.new(CODE_LENGTH) { rand(MIN..MAX) }
23
- @tries_count = @difficulty_data[:tries]
24
- @hints_count = @difficulty_data[:hints]
36
+ @hint_indexes = (0...CODE_LENGTH).to_a
25
37
 
26
- create_summary_container
27
- end
38
+ @secret = Array.new(CODE_LENGTH) { rand(MIN_CODE_NUMBER..MAX_CODE_NUMBER) }
28
39
 
29
- def jsonify
30
- @summary.to_json
40
+ @tries_count = DIFFICULTIES[@difficulty][:tries]
41
+ @hints_count = DIFFICULTIES[@difficulty][:hints]
42
+
43
+ @game_iteration_count += 1
44
+
45
+ clear_old_data if @game_iteration_count > 1
31
46
  end
32
47
 
33
48
  def check_guess(input)
34
49
  input = to_array(input)
35
50
 
36
- return update_summary(:guess_result, 'no tries left') if lose?
51
+ return @guess_result = 'no tries left' if lose?
37
52
 
38
- return update_summary(:guess_result, 'wrong format') unless valid? input
53
+ return @guess_result = 'wrong format' unless valid? input
39
54
 
40
- make_results calculate_matches(input)
55
+ make_results Matcher.calculate_matches(@secret, input)
41
56
  end
42
57
 
43
58
  def generate_hint
44
- return update_summary(:hint, 'no hints left') if @hints_count.zero?
59
+ return @hint = 'no hints left' if @hints_count.zero?
45
60
 
46
- index = @hints.sample
61
+ index = @hint_indexes.sample
47
62
 
48
- hint = @code[index]
63
+ @hint = @secret[index]
49
64
 
50
- @hints.delete index
65
+ @hint_indexes.delete index
51
66
 
52
67
  @hints_count -= 1
68
+ @hints_used += 1
53
69
 
54
- update_summary :hints_used, :increase
55
- update_summary :hint, hint
70
+ @hint
56
71
  end
57
72
 
58
73
  def win?
59
- @summary[:guess_result] == Array.new(CODE_LENGTH, '+').join
74
+ @guess_result == Array.new(CODE_LENGTH, EXACT_MATCH_SIGN).join
60
75
  end
61
76
 
62
77
  def lose?
63
78
  @tries_count.zero?
64
79
  end
65
80
 
66
- private
67
-
68
- def update_summary(key, value)
69
- return ArgumentError unless @summary.include? key
70
-
71
- case value
72
- when :increase
73
- @summary[key] += 1
74
- else
75
- @summary[key] = value
76
- end
81
+ def data
82
+ {
83
+ difficulty: DIFFICULTIES.keys.index(@difficulty),
84
+ secret: @secret,
85
+ tries_total: DIFFICULTIES[@difficulty][:tries],
86
+ hints_total: DIFFICULTIES[@difficulty][:hints],
87
+ tries_used: @tries_used,
88
+ hints_used: @hints_used,
89
+ guess_result: @guess_result,
90
+ hint: @hint
91
+ }
77
92
  end
78
93
 
79
- def set_default_difficulty
80
- @difficulty = :kid
81
- @difficulty_data = DIFFICULTIES[@difficulty]
94
+ def jsonify
95
+ data.to_json
82
96
  end
83
97
 
84
- def calculate_matches(user_code)
85
- delta = []
86
- result = []
87
-
88
- (0...CODE_LENGTH).each do |i|
89
- if @code[i] == user_code[i] then result << '+'
90
- elsif (@code - delta).include? user_code[i] then result << '-'
91
- end
92
-
93
- delta << user_code[i]
94
- end
98
+ private
95
99
 
96
- result.sort!.join
100
+ def clear_old_data
101
+ @tries_used = 0
102
+ @hints_used = 0
103
+ @guess_result = ''
104
+ @hint = nil
97
105
  end
98
106
 
99
107
  def make_results(guess_result)
100
108
  @tries_count -= 1
101
109
 
102
- update_summary :tries_used, :increase
103
- update_summary :guess_result, guess_result
110
+ @tries_used += 1
111
+ @guess_result = guess_result
104
112
  end
105
113
 
106
114
  def to_array(input)
107
115
  input.to_i.digits.reverse
108
116
  end
109
117
 
110
- def create_summary_container
111
- @summary = {
112
- secret: @code,
113
- difficulty: DIFFICULTIES.keys.index(@difficulty),
114
- tries_total: @tries_count,
115
- hints_total: @hints_count,
116
- tries_used: 0,
117
- hints_used: 0,
118
- guess_result: nil,
119
- hint: nil
120
- }
121
- end
122
-
123
118
  def valid?(input)
124
- input != 0 && input.size == CODE_LENGTH && input.all? do |number|
125
- number.between? MIN, MAX
126
- end
119
+ input.size == CODE_LENGTH && input.all? { |number| number.between? MIN_CODE_NUMBER, MAX_CODE_NUMBER }
127
120
  end
128
121
  end
129
122
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebreakerDiz
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_diz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - bl0rch1d
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-28 00:00:00.000000000 Z
11
+ date: 2019-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.69.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.33'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.33'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: fasterer
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,62 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: 0.5.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: overcommit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.48.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.48.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.16.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.16.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.12.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.12.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: bundle-audit
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.1.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.1.0
83
167
  description: "'Game for true Hackers'"
84
168
  email:
85
169
  - temaflash96@gmail.com
@@ -110,9 +194,7 @@ files:
110
194
  homepage: https://github.com/bl0rch1d/codebreaker_diz
111
195
  licenses:
112
196
  - MIT
113
- metadata:
114
- allowed_push_host: https://rubygems.org
115
- homepage_uri: https://github.com/bl0rch1d/codebreaker_diz
197
+ metadata: {}
116
198
  post_install_message:
117
199
  rdoc_options: []
118
200
  require_paths:
@@ -128,7 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
210
  - !ruby/object:Gem::Version
129
211
  version: '0'
130
212
  requirements: []
131
- rubygems_version: 3.0.3
213
+ rubyforge_project:
214
+ rubygems_version: 2.7.9
132
215
  signing_key:
133
216
  specification_version: 4
134
217
  summary: Codebreaker game.