codebreaker_diz 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a21ab82c3f5b832aad928b647af362c29eba5715fd615d823bc1df0ce11eeef3
4
- data.tar.gz: 8b189eedb9ba6c9a805f66bb270e7173c52377bb1e24fe66b010336e6af8ca88
3
+ metadata.gz: c89596979f6833a5b2135c6f94652c3091a6aaccad295e0e7da4c65027129571
4
+ data.tar.gz: f2a64d90dc823dd19c1c5f29424505a6aa66941e247afa11d64697dfb757a1d1
5
5
  SHA512:
6
- metadata.gz: 5eafbb6891b3fe1dcd5536e7341ddba386ba7c50f549566e22da5f3d823a638662147e8a6680276d5972deb2a866c4fd1eacfed2e103f9eaebf05bdcf6178510
7
- data.tar.gz: 6e90151e036d5dcf847d5e8362b33e82fcb92ed881ca6ce7f466e81f3e3c64bc9f3e5facbd354382d740e299219b997265cb155dac7db702ddf650c03d6c1aba
6
+ metadata.gz: b9267c4dfd527f60de74b5729a258c454c612562ecd06eda60220f7564afd56be7f6064fb45c54ed5a6b7426de376d56d8e1c6fc0eced06644a09f05c414bc63
7
+ data.tar.gz: da49219764603fd7c7ad39420a99cf2ec071cec9e0e720bb32cec28422476f587b9250b4d4515db41d8456f8bfe0ada7e3531ef38a2d8634a30097d978dc4315
data/.circleci/config.yml CHANGED
@@ -13,7 +13,7 @@ jobs:
13
13
  bundle exec rspec
14
14
  workflows:
15
15
  version: 2
16
- build_and_test:
16
+ test:
17
17
  jobs:
18
18
  - test
19
19
 
data/Gemfile.lock CHANGED
@@ -16,12 +16,15 @@ GEM
16
16
  ffi (~> 1.0, >= 1.0.11)
17
17
  coderay (1.1.2)
18
18
  colorize (0.8.1)
19
+ concurrent-ruby (1.1.5)
19
20
  diff-lcs (1.3)
20
21
  docile (1.3.1)
21
22
  fasterer (0.5.1)
22
23
  colorize (~> 0.7)
23
24
  ruby_parser (>= 3.13.0)
24
25
  ffi (1.11.1)
26
+ i18n (1.6.0)
27
+ concurrent-ruby (~> 1.0)
25
28
  iniparse (1.4.4)
26
29
  jaro_winkler (1.5.2)
27
30
  json (2.2.0)
@@ -81,6 +84,7 @@ DEPENDENCIES
81
84
  bundler (~> 2.0)
82
85
  codebreaker_diz!
83
86
  fasterer (~> 0.5.1)
87
+ i18n (~> 1.6)
84
88
  overcommit (~> 0.48.0)
85
89
  pry (~> 0.12.2)
86
90
  rake (~> 10.0)
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['bl0rch1d']
11
11
  spec.email = ['temaflash96@gmail.com']
12
12
 
13
- spec.summary = 'Codebreaker game.'
14
- spec.description = "'Game for true Hackers'"
13
+ spec.summary = 'Codebreaker game'
14
+ spec.description = "Game for true Hackers"
15
15
  spec.homepage = 'https://github.com/bl0rch1d/codebreaker_diz'
16
16
  spec.license = 'MIT'
17
17
 
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
36
36
  spec.add_development_dependency 'pry', '~> 0.12.2'
37
37
  spec.add_development_dependency 'bundle-audit', '~> 0.1.0'
38
+ spec.add_development_dependency 'i18n', '~> 1.6'
38
39
  end
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'i18n'
4
+
3
5
  require_relative 'codebreaker_diz/game'
4
6
  require_relative 'codebreaker_diz/matcher'
5
7
  require_relative 'codebreaker_diz/version'
8
+
9
+ I18n.config.load_path << File.absolute_path('../gem/config/locales/en.yml')
10
+ I18n.config.available_locales = :en
11
+ I18n.default_locale = :en
@@ -6,71 +6,51 @@ module CodebreakerDiz
6
6
  class Game
7
7
  attr_reader :tries_count, :hints_count
8
8
 
9
- def initialize
10
- @difficulty = :kid
9
+ def initialize(difficulty: :kid)
10
+ validate_difficulty(difficulty)
11
11
 
12
- @secret = []
12
+ @difficulty = difficulty
13
13
 
14
- @tries_count = 0
15
- @hints_count = 0
16
-
17
- @tries_used = 0
18
- @hints_used = 0
19
-
20
- @guess_result = ''
21
-
22
- @hint = nil
23
- @hint_indexes = []
24
-
25
- @game_iteration_count = 0
26
- end
27
-
28
- def difficulty(value)
29
- raise ArgumentError unless DIFFICULTIES.include? value.to_sym
30
-
31
- @difficulty = value.to_sym
32
- end
33
-
34
- def prepare_data
35
14
  @hint_indexes = (0...CODE_LENGTH).to_a
36
15
 
37
- @secret = Array.new(CODE_LENGTH) { rand(MIN_CODE_NUMBER..MAX_CODE_NUMBER) }
16
+ @secret = Array.new(CODE_LENGTH) { rand(MIN_CODE_NUMBER..MAX_CODE_NUMBER) }
38
17
 
39
- @tries_count = DIFFICULTIES[@difficulty][:tries]
40
- @hints_count = DIFFICULTIES[@difficulty][:hints]
18
+ @tries_count = DIFFICULTIES[@difficulty][:tries]
19
+ @hints_count = DIFFICULTIES[@difficulty][:hints]
41
20
 
42
- @game_iteration_count += 1
21
+ @matches = ''
22
+ end
43
23
 
44
- clear_old_data if @game_iteration_count > 1
24
+ def validate_difficulty(difficulty)
25
+ raise ArgumentError, I18n.t(:INVALID_DIFFICULTY) unless DIFFICULTIES.include? difficulty.to_sym
45
26
  end
46
27
 
47
28
  def check_guess(input)
48
29
  input = to_array(input)
49
30
 
50
- return @guess_result = 'no tries left' if lose?
31
+ return I18n.t(:WRONG_FORMAT) unless valid? input
51
32
 
52
- return @guess_result = 'wrong format' unless valid? input
33
+ @tries_count -= 1
53
34
 
54
- make_results Matcher.new(@secret, input).matches
35
+ @matches = Matcher.new(@secret, input).matches
55
36
  end
56
37
 
57
38
  def generate_hint
58
- return @hint = 'no hints left' if @hints_count.zero?
39
+ return I18n.t(:NO_HINTS_LEFT) if @hints_count.zero?
59
40
 
60
41
  index = @hint_indexes.sample
61
42
 
62
- @hint = @secret[index]
43
+ hint = @secret[index]
63
44
 
64
45
  @hint_indexes.delete index
65
46
 
66
47
  @hints_count -= 1
67
- @hints_used += 1
68
48
 
69
- @hint
49
+ hint
70
50
  end
71
51
 
72
52
  def win?
73
- @guess_result == Array.new(CODE_LENGTH, EXACT_MATCH_SIGN).join
53
+ @matches == Array.new(CODE_LENGTH, EXACT_MATCH_SIGN).join
74
54
  end
75
55
 
76
56
  def lose?
@@ -83,33 +63,13 @@ module CodebreakerDiz
83
63
  secret: @secret,
84
64
  tries_total: DIFFICULTIES[@difficulty][:tries],
85
65
  hints_total: DIFFICULTIES[@difficulty][:hints],
86
- tries_used: @tries_used,
87
- hints_used: @hints_used,
88
- guess_result: @guess_result,
89
- hint: @hint
66
+ tries_used: DIFFICULTIES[@difficulty][:tries] - @tries_count,
67
+ hints_used: DIFFICULTIES[@difficulty][:hints] - @hints_count
90
68
  }
91
69
  end
92
70
 
93
- def jsonify
94
- data.to_json
95
- end
96
-
97
71
  private
98
72
 
99
- def clear_old_data
100
- @tries_used = 0
101
- @hints_used = 0
102
- @guess_result = ''
103
- @hint = nil
104
- end
105
-
106
- def make_results(guess_result)
107
- @tries_count -= 1
108
-
109
- @tries_used += 1
110
- @guess_result = guess_result
111
- end
112
-
113
73
  def to_array(input)
114
74
  input.to_i.digits.reverse
115
75
  end
@@ -5,7 +5,7 @@ require_relative 'config'
5
5
  module CodebreakerDiz
6
6
  class Matcher
7
7
  def initialize(secret_code, user_code)
8
- @secret_code = secret_code
8
+ @secret_code = secret_code.clone
9
9
  @user_code = user_code
10
10
 
11
11
  @exact_matches = 0
@@ -21,14 +21,14 @@ module CodebreakerDiz
21
21
  private
22
22
 
23
23
  def calculate_matches
24
- delta = []
25
-
26
24
  @secret_code.zip(@user_code).each do |secret_code_number, user_code_number|
27
- if secret_code_number == user_code_number then @exact_matches += 1
28
- elsif (@secret_code - delta).include? user_code_number then @number_matches += 1
25
+ next unless @secret_code.include? user_code_number
26
+
27
+ if secret_code_number == user_code_number then @exact_matches += 1
28
+ elsif @secret_code.include? user_code_number then @number_matches += 1
29
29
  end
30
30
 
31
- delta << user_code_number
31
+ @secret_code.delete_at(@secret_code.index(user_code_number))
32
32
  end
33
33
  end
34
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebreakerDiz
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bl0rch1d
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-02 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,7 +164,21 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.1.0
167
- description: "'Game for true Hackers'"
167
+ - !ruby/object:Gem::Dependency
168
+ name: i18n
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.6'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.6'
181
+ description: Game for true Hackers
168
182
  email:
169
183
  - temaflash96@gmail.com
170
184
  executables: []
@@ -217,5 +231,5 @@ rubyforge_project:
217
231
  rubygems_version: 2.7.9
218
232
  signing_key:
219
233
  specification_version: 4
220
- summary: Codebreaker game.
234
+ summary: Codebreaker game
221
235
  test_files: []