codebreaker_diz 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 +4 -4
- data/.circleci/config.yml +1 -1
- data/Gemfile.lock +4 -0
- data/bin/setup +0 -2
- data/codebreaker_diz.gemspec +3 -2
- data/lib/codebreaker_diz.rb +6 -0
- data/lib/codebreaker_diz/game.rb +19 -59
- data/lib/codebreaker_diz/matcher.rb +6 -6
- data/lib/codebreaker_diz/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c89596979f6833a5b2135c6f94652c3091a6aaccad295e0e7da4c65027129571
|
4
|
+
data.tar.gz: f2a64d90dc823dd19c1c5f29424505a6aa66941e247afa11d64697dfb757a1d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9267c4dfd527f60de74b5729a258c454c612562ecd06eda60220f7564afd56be7f6064fb45c54ed5a6b7426de376d56d8e1c6fc0eced06644a09f05c414bc63
|
7
|
+
data.tar.gz: da49219764603fd7c7ad39420a99cf2ec071cec9e0e720bb32cec28422476f587b9250b4d4515db41d8456f8bfe0ada7e3531ef38a2d8634a30097d978dc4315
|
data/.circleci/config.yml
CHANGED
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
data/codebreaker_diz.gemspec
CHANGED
@@ -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 = "
|
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
|
data/lib/codebreaker_diz.rb
CHANGED
@@ -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
|
data/lib/codebreaker_diz/game.rb
CHANGED
@@ -6,71 +6,51 @@ module CodebreakerDiz
|
|
6
6
|
class Game
|
7
7
|
attr_reader :tries_count, :hints_count
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
|
9
|
+
def initialize(difficulty: :kid)
|
10
|
+
validate_difficulty(difficulty)
|
11
11
|
|
12
|
-
@
|
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
|
16
|
+
@secret = Array.new(CODE_LENGTH) { rand(MIN_CODE_NUMBER..MAX_CODE_NUMBER) }
|
38
17
|
|
39
|
-
@tries_count
|
40
|
-
@hints_count
|
18
|
+
@tries_count = DIFFICULTIES[@difficulty][:tries]
|
19
|
+
@hints_count = DIFFICULTIES[@difficulty][:hints]
|
41
20
|
|
42
|
-
@
|
21
|
+
@matches = ''
|
22
|
+
end
|
43
23
|
|
44
|
-
|
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
|
31
|
+
return I18n.t(:WRONG_FORMAT) unless valid? input
|
51
32
|
|
52
|
-
|
33
|
+
@tries_count -= 1
|
53
34
|
|
54
|
-
|
35
|
+
@matches = Matcher.new(@secret, input).matches
|
55
36
|
end
|
56
37
|
|
57
38
|
def generate_hint
|
58
|
-
return
|
39
|
+
return I18n.t(:NO_HINTS_LEFT) if @hints_count.zero?
|
59
40
|
|
60
41
|
index = @hint_indexes.sample
|
61
42
|
|
62
|
-
|
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
|
-
|
49
|
+
hint
|
70
50
|
end
|
71
51
|
|
72
52
|
def win?
|
73
|
-
@
|
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: @
|
87
|
-
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
|
-
|
28
|
-
|
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
|
-
|
31
|
+
@secret_code.delete_at(@secret_code.index(user_code_number))
|
32
32
|
end
|
33
33
|
end
|
34
34
|
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.
|
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-
|
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
|
-
|
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: []
|