codebreaker_kirill 1.3.3 → 1.3.6
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/lib/codebreaker_kirill/code_generator.rb +1 -1
- data/lib/codebreaker_kirill/game.rb +2 -4
- data/lib/codebreaker_kirill/guess_handler.rb +3 -5
- data/lib/codebreaker_kirill/settings.rb +0 -2
- data/lib/codebreaker_kirill/stats.rb +0 -2
- data/lib/codebreaker_kirill/user.rb +3 -5
- data/lib/codebreaker_kirill/validations.rb +5 -7
- data/lib/codebreaker_kirill/version.rb +1 -3
- data/lib/codebreaker_kirill.rb +0 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a030fc2547d6561de965adc0b453f4efb415f6eeb5f697074aafd483e1193942
|
4
|
+
data.tar.gz: 63c40b50cdfeb0b15694dbeb69f65598eed9e741bfd96cf457910bc4cc78d8de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b2509312216af4fc7daebce395752d8ad782913207bd3759d5771e936c5945263d8e1154fff6e4f870ea24301b09c89d81165da30a12c85ee5c0056b77a880
|
7
|
+
data.tar.gz: 36cfaa36bd4c18b05eb44ea16176fbc3acb593003dccf25c86d96fbf56abc039c29372606550392f6dc90cd348725d411fd3400500b3111a792ea6cda92251b0
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'autoload'
|
4
|
-
|
5
3
|
module CodebreakerKirill
|
6
4
|
class Game
|
7
5
|
include CodeGenerator
|
@@ -9,7 +7,7 @@ module CodebreakerKirill
|
|
9
7
|
attr_reader :user
|
10
8
|
|
11
9
|
def initialize(user)
|
12
|
-
@secret_code =
|
10
|
+
@secret_code = CodeGenerator.call
|
13
11
|
@user = user
|
14
12
|
end
|
15
13
|
|
@@ -23,7 +21,7 @@ module CodebreakerKirill
|
|
23
21
|
def respond_to_guess(input)
|
24
22
|
@user.attempts_used += 1
|
25
23
|
status = status(input, @secret_code)
|
26
|
-
resolved_code =
|
24
|
+
resolved_code = GuessHandler.new(input, @secret_code).call
|
27
25
|
return { status: status, secret_code: @secret_code } if status == 'loss'
|
28
26
|
|
29
27
|
{ status: status, response: resolved_code, secret_code: @secret_code }
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'autoload'
|
4
|
-
|
5
3
|
module CodebreakerKirill
|
6
4
|
class GuessHandler
|
7
5
|
include Settings
|
8
6
|
|
9
7
|
def initialize(input, code)
|
10
|
-
|
8
|
+
Validations.validate_guess(input)
|
11
9
|
@input = input.each_char.map(&:to_i)
|
12
10
|
@code = code.clone
|
13
11
|
@result = []
|
@@ -23,7 +21,7 @@ module CodebreakerKirill
|
|
23
21
|
@input.each_index do |index|
|
24
22
|
next unless @input[index] == @code[index]
|
25
23
|
|
26
|
-
@result <<
|
24
|
+
@result << Settings::POSITIVE_RESPONSE
|
27
25
|
@input[index], @code[index] = nil
|
28
26
|
end
|
29
27
|
end
|
@@ -32,7 +30,7 @@ module CodebreakerKirill
|
|
32
30
|
@input.each_with_index do |value, _index|
|
33
31
|
next unless !value.nil? && @code.include?(value)
|
34
32
|
|
35
|
-
@result <<
|
33
|
+
@result << Settings::NEGATIVE_RESPONSE
|
36
34
|
@input[@input.find_index(value)], @code[@code.find_index(value)] = nil
|
37
35
|
end
|
38
36
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'autoload'
|
4
|
-
|
5
3
|
module CodebreakerKirill
|
6
4
|
class User
|
7
5
|
include Settings
|
@@ -13,14 +11,14 @@ module CodebreakerKirill
|
|
13
11
|
validation(name, difficulty)
|
14
12
|
@difficulty = difficulty
|
15
13
|
@name = name
|
16
|
-
@level =
|
14
|
+
@level = Settings::DIFFICULTY[@difficulty]
|
17
15
|
@attempts_used = 0
|
18
16
|
@hints_used = 0
|
19
17
|
end
|
20
18
|
|
21
19
|
def validation(name, difficulty)
|
22
|
-
|
23
|
-
|
20
|
+
Validations.validate_name(name)
|
21
|
+
Validations.validate_difficulty(difficulty)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'autoload'
|
4
|
-
|
5
3
|
module CodebreakerKirill
|
6
4
|
class Validations
|
7
5
|
include Settings
|
@@ -9,21 +7,21 @@ module CodebreakerKirill
|
|
9
7
|
def self.validate_name(name)
|
10
8
|
raise "Name shouldn't be empty" if name.empty?
|
11
9
|
raise 'Name should be string' if name.class != String
|
12
|
-
raise 'Name should be at least 3 characters long' if name.length <
|
10
|
+
raise 'Name should be at least 3 characters long' if name.length < Settings::NAME_MIN_LENGTH
|
13
11
|
raise "Name shouldn't be more than 20 characters long" if name.length > Settings::NAME_MAX_LENGTH
|
14
12
|
end
|
15
13
|
|
16
14
|
def self.validate_guess(guess)
|
17
15
|
raise "Guess shouldn't be empty" if guess.empty?
|
18
|
-
raise 'Guess should be 4 characters' if guess.length <
|
19
|
-
raise 'Guess shouldnt be more than 4 characters long' if guess.length >
|
16
|
+
raise 'Guess should be 4 characters' if guess.length < Settings::GUESS_LENGTH
|
17
|
+
raise 'Guess shouldnt be more than 4 characters long' if guess.length > Settings::GUESS_LENGTH
|
20
18
|
end
|
21
19
|
|
22
20
|
def self.validate_difficulty(difficulty)
|
23
21
|
raise "Input shouldn't be empty" if difficulty.empty?
|
24
|
-
return if
|
22
|
+
return if Settings::DIFFICULTY.keys.include?(difficulty)
|
25
23
|
|
26
|
-
raise "You should enter one of the following options: #{
|
24
|
+
raise "You should enter one of the following options: #{Settings::DIFFICULTY.keys.join(', ')}"
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
data/lib/codebreaker_kirill.rb
CHANGED