codebreaker_kirill 1.0.0 → 1.1.0
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/game.rb +21 -3
- data/lib/codebreaker_kirill/guess_handler.rb +23 -27
- data/lib/codebreaker_kirill/settings.rb +2 -0
- data/lib/codebreaker_kirill/stats.rb +1 -1
- data/lib/codebreaker_kirill/user.rb +5 -6
- data/lib/codebreaker_kirill/validations.rb +1 -1
- data/lib/codebreaker_kirill/version.rb +1 -1
- data/lib/codebreaker_kirill.rb +0 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea8d9499d3f3afaf3a663f2f5d2d393843be5bb29eef1cd4cc769fdbd08e5d4c
|
4
|
+
data.tar.gz: b465bcb3d9eefe5fc004a2c98cbc174979985b1d363d0150f445ce5a1343065c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c440ac19bd13a5678d0cdfa24e94b04d278cf770fae412e64d77e718004f17f6031b114cca8764439435015386b0a6a0337cd331c1abf0810ca64e03a1ed601b
|
7
|
+
data.tar.gz: '05239e74c1dacb9277e2e3a2ceb879938624e482c52757148f74346b59a9dab9f638d10aa3221a7a6e44ae8a6d3b236f5da7fd832a56bbc9292bfe2290a24087'
|
@@ -7,7 +7,7 @@ require_relative 'user'
|
|
7
7
|
class Game
|
8
8
|
include CodeGenerator
|
9
9
|
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :user
|
11
11
|
|
12
12
|
def initialize(user)
|
13
13
|
@secret_code = CodeGenerator.call
|
@@ -15,9 +15,27 @@ class Game
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def give_a_hint
|
18
|
-
return
|
18
|
+
return nil if @user.hints[:used] >= @user.hints[:all]
|
19
19
|
|
20
20
|
@user.hints[:used] += 1
|
21
|
-
@secret_code[@user.hints[:used]]
|
21
|
+
@secret_code.shuffle[@user.hints[:used]]
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to_guess(input, code)
|
25
|
+
@user.attempts[:used] += 1
|
26
|
+
status = status(input, code)
|
27
|
+
resolved_code = GuessHandler.new(input, code).call
|
28
|
+
{ status: status, response: resolved_code }
|
29
|
+
end
|
30
|
+
|
31
|
+
def attempts_handler
|
32
|
+
@user.attempts[:used] += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def status(input, code)
|
36
|
+
return 'loss' if @user.attempts[:used] >= @user.attempts[:all]
|
37
|
+
return 'win' if input.each_char.map(&:to_i) == code
|
38
|
+
|
39
|
+
'in_game'
|
22
40
|
end
|
23
41
|
end
|
@@ -1,44 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'autoload'
|
4
|
-
require_relative 'game'
|
5
4
|
|
6
5
|
class GuessHandler
|
7
|
-
def
|
6
|
+
def initialize(input, code)
|
8
7
|
validation(input)
|
9
|
-
|
10
|
-
|
8
|
+
@input = input.each_char.map(&:to_i)
|
9
|
+
@code = code.clone
|
11
10
|
@result = []
|
12
|
-
|
13
|
-
@numbers = input.split('').map(&:to_i)
|
14
|
-
return 'win' if @numbers == code
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
def call
|
14
|
+
add_pluses(@input, @code)
|
15
|
+
add_minuses(@input, @code)
|
16
|
+
@result
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
code[index] = '+'
|
24
|
-
input[@numbers.index(element)] = '' end
|
25
|
-
end
|
19
|
+
def add_pluses(input, code)
|
20
|
+
input.each_with_index do |element, index|
|
21
|
+
next unless element == code[index]
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
input.slice!(@numbers.index(el)) end
|
23
|
+
@result << Settings::POSITIVE
|
24
|
+
input[input.find_index(element)] = ''
|
25
|
+
code[index] = ''
|
31
26
|
end
|
27
|
+
input.delete('')
|
28
|
+
code.delete('')
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end.sort
|
31
|
+
def add_minuses(input, code)
|
32
|
+
input.each_with_index do |element, _index|
|
33
|
+
next unless code.include?(element)
|
34
|
+
|
35
|
+
@result << Settings::NEGATIVE
|
36
|
+
input[input.find_index(element)] = ''
|
37
|
+
code[code.find_index(element)] = ''
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
@@ -22,7 +22,7 @@ class Stats
|
|
22
22
|
def self.stats_format(user, index)
|
23
23
|
index += 1
|
24
24
|
puts "Rating: #{index}", "Name: #{user.name}",
|
25
|
-
"Difficulty: #{
|
25
|
+
"Difficulty: #{user.difficulty}",
|
26
26
|
"Available Attempts: #{user.attempts[:all]}",
|
27
27
|
"Used Attempts: #{user.attempts[:used]}",
|
28
28
|
"Available Hints: #{user.hints[:all]}",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'autoload'
|
3
4
|
require_relative 'settings'
|
4
5
|
|
5
6
|
class User
|
@@ -7,17 +8,15 @@ class User
|
|
7
8
|
|
8
9
|
def initialize(name, difficulty)
|
9
10
|
validation(name, difficulty)
|
11
|
+
@difficulty = difficulty
|
10
12
|
@name = name
|
11
|
-
@
|
12
|
-
@attempts = { all: @
|
13
|
-
@hints = { all: @
|
13
|
+
@level = Settings::DIFFICULTY[@difficulty]
|
14
|
+
@attempts = { all: @level[:attempts], used: 0 }
|
15
|
+
@hints = { all: @level[:hints], used: 0 }
|
14
16
|
end
|
15
17
|
|
16
18
|
def validation(name, difficulty)
|
17
19
|
Validations.validate_name(name)
|
18
20
|
Validations.validate_difficulty(difficulty)
|
19
|
-
rescue StandardError => e
|
20
|
-
puts e.message
|
21
|
-
nil
|
22
21
|
end
|
23
22
|
end
|
@@ -16,7 +16,7 @@ class Validations
|
|
16
16
|
|
17
17
|
def self.validate_difficulty(difficulty)
|
18
18
|
raise "Input shouldn't be empty" if difficulty.empty?
|
19
|
-
return if
|
19
|
+
return if Settings::DIFFICULTY.keys.include?(difficulty)
|
20
20
|
|
21
21
|
raise 'You should enter one of the following options: easy, medium, hell'
|
22
22
|
end
|
data/lib/codebreaker_kirill.rb
CHANGED
@@ -6,8 +6,3 @@ require_relative 'codebreaker_kirill/user'
|
|
6
6
|
require_relative 'codebreaker_kirill/guess_handler'
|
7
7
|
require_relative 'codebreaker_kirill/settings'
|
8
8
|
require_relative 'codebreaker_kirill/stats'
|
9
|
-
|
10
|
-
module CodebreakerKirill
|
11
|
-
class Error < StandardError; end
|
12
|
-
# Your code goes here...
|
13
|
-
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_kirill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Dudchenko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email:
|
15
15
|
- dudchenko.kirill.1995@gmail.com
|
16
16
|
executables: []
|
@@ -36,11 +36,11 @@ files:
|
|
36
36
|
- lib/codebreaker_kirill/validations.rb
|
37
37
|
- lib/codebreaker_kirill/version.rb
|
38
38
|
- sig/codebreaker_kirill.rbs
|
39
|
-
homepage:
|
39
|
+
homepage:
|
40
40
|
licenses:
|
41
41
|
- MIT
|
42
42
|
metadata: {}
|
43
|
-
post_install_message:
|
43
|
+
post_install_message:
|
44
44
|
rdoc_options: []
|
45
45
|
require_paths:
|
46
46
|
- lib
|
@@ -55,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
rubygems_version: 3.3
|
59
|
-
signing_key:
|
58
|
+
rubygems_version: 3.2.3
|
59
|
+
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Logic game
|
62
62
|
test_files: []
|