codebracker_simb 1.0.0 → 1.0.3
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/codebracker_simb.gemspec +6 -4
- data/lib/codebracker_simb/checker.rb +8 -6
- data/lib/codebracker_simb/errors/code_error.rb +9 -0
- data/lib/codebracker_simb/errors/intro_error.rb +9 -0
- data/lib/codebracker_simb/errors/name_error.rb +9 -0
- data/lib/codebracker_simb/errors/no_hints_error.rb +9 -0
- data/lib/codebracker_simb/game.rb +17 -17
- data/lib/codebracker_simb/text.rb +10 -10
- data/lib/codebracker_simb/version.rb +1 -1
- data/lib/codebracker_simb.rb +4 -6
- metadata +23 -9
- data/lib/errors/code_error.rb +0 -7
- data/lib/errors/complexity_error.rb +0 -7
- data/lib/errors/intro_error.rb +0 -7
- data/lib/errors/name_error.rb +0 -7
- data/lib/errors/no_hints_error.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6239366809bf4ad9f74131de93429ca0a96de25ef1bef5f33a4a7a83ffa044d7
|
4
|
+
data.tar.gz: 7d226c7c4ec0843e27af70c5b888300eb1ba6e290ad52476874554fd9a0683bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96602cc013379eae102dbbfe8935e64180fa322e5934886652f824ec210d97c81c390e45f6a3b03a7162847213a529de556e2c132904df4a0211206e941e30de
|
7
|
+
data.tar.gz: eab9fb9ee9cfaa9b4263df55bbedea488757eb8e0acc13e499d190c15948973b9dd82e0313698d73089490c1bde67c520ad926e6af0dba864c3b3f9d22ebb954
|
data/codebracker_simb.gemspec
CHANGED
@@ -11,19 +11,21 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Write a short summary, because RubyGems requires one.'
|
12
12
|
spec.description = 'Write a longer description or delete this line.'
|
13
13
|
spec.license = 'MIT'
|
14
|
-
spec.required_ruby_version = '>= 3.0
|
14
|
+
spec.required_ruby_version = '>= 3.0'
|
15
15
|
|
16
16
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
-
spec.files = Dir['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/**/*.rb', 'lib/codebracker_simb.rb', 'lib/**/*.rake',
|
21
|
-
'codebracker_simb.gemspec', '.github/*.md', 'CHANGELOG.md']
|
20
|
+
spec.files = Dir['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/**/*.rb', 'lib/codebracker_simb.rb', 'lib/**/*.rake',
|
21
|
+
'Gemfile', 'Rakefile', 'codebracker_simb.gemspec', '.github/*.md', 'CHANGELOG.md']
|
22
22
|
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
25
|
spec.add_development_dependency 'fasterer'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'rubocop-performance'
|
27
28
|
spec.add_development_dependency 'rubocop-rspec'
|
28
29
|
spec.add_development_dependency 'simplecov'
|
30
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
29
31
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module CodebrackerSimb
|
4
4
|
class Checker
|
5
|
+
MINUS = :minus
|
6
|
+
PLUS = :plus
|
5
7
|
def initialize(code, answer)
|
6
8
|
@answer = answer
|
7
9
|
@code = code
|
@@ -24,16 +26,16 @@ module CodebrackerSimb
|
|
24
26
|
def output
|
25
27
|
output = []
|
26
28
|
@table.each do |line|
|
27
|
-
output << '+' if line.include?(
|
28
|
-
output << '-' if line.include?(
|
29
|
+
output << '+' if line.include?(PLUS)
|
30
|
+
output << '-' if line.include?(MINUS) && !line.include?(PLUS)
|
29
31
|
end
|
30
|
-
output.sort.join
|
32
|
+
output.sort.join
|
31
33
|
end
|
32
34
|
|
33
35
|
def fill_with_plus
|
34
36
|
@table.each_with_index do |line, index|
|
35
37
|
if @code[index] == @answer[index]
|
36
|
-
line[index] =
|
38
|
+
line[index] = PLUS
|
37
39
|
@filled_column << index
|
38
40
|
end
|
39
41
|
end
|
@@ -43,9 +45,9 @@ module CodebrackerSimb
|
|
43
45
|
@table.each_with_index do |line, index|
|
44
46
|
line.each_with_index do |_, jndex|
|
45
47
|
next unless @code[index] == @answer[jndex] && !line[jndex] && !@filled_column.include?(jndex)
|
46
|
-
next if line.include?
|
48
|
+
next if line.include? MINUS
|
47
49
|
|
48
|
-
line[jndex] =
|
50
|
+
line[jndex] = MINUS
|
49
51
|
@filled_column << jndex
|
50
52
|
end
|
51
53
|
end
|
@@ -7,7 +7,11 @@ module CodebrackerSimb
|
|
7
7
|
attr_reader :code, :attempts, :player, :complexity
|
8
8
|
attr_accessor :answer, :hint_positions, :hints
|
9
9
|
|
10
|
-
|
10
|
+
HARD = 'hard'
|
11
|
+
MEDIUM = 'medium'
|
12
|
+
EASY = 'easy'
|
13
|
+
|
14
|
+
def initialize(player, complexity)
|
11
15
|
@attempts = game_options(complexity)[:attempts]
|
12
16
|
@hints = game_options(complexity)[:hints]
|
13
17
|
@player = player
|
@@ -17,12 +21,12 @@ module CodebrackerSimb
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def input_answer(input)
|
20
|
-
@answer = input.
|
24
|
+
@answer = input.chars.map(&:to_i)
|
21
25
|
end
|
22
26
|
|
23
27
|
def check_answer
|
24
28
|
refresh_attempts_quantity
|
25
|
-
Checker.new(
|
29
|
+
Checker.new(code, answer).compare
|
26
30
|
end
|
27
31
|
|
28
32
|
def define_code
|
@@ -34,24 +38,20 @@ module CodebrackerSimb
|
|
34
38
|
end
|
35
39
|
|
36
40
|
def refresh_attempts_quantity
|
37
|
-
if
|
38
|
-
@attempts -= 1
|
39
|
-
end
|
41
|
+
@attempts -= 1 if attempts.positive?
|
40
42
|
end
|
41
43
|
|
42
|
-
def hint
|
44
|
+
def hint!
|
43
45
|
position = nil
|
44
46
|
loop do
|
45
47
|
position = rand(0..3)
|
46
48
|
break unless hint_positions.include? position
|
47
49
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
raise NoHintsError
|
54
|
-
end
|
50
|
+
raise NoHintsError unless hints.positive?
|
51
|
+
|
52
|
+
hint_positions << position
|
53
|
+
@hints -= 1
|
54
|
+
code[position]
|
55
55
|
end
|
56
56
|
|
57
57
|
def params
|
@@ -67,11 +67,11 @@ module CodebrackerSimb
|
|
67
67
|
|
68
68
|
def game_options(complexity)
|
69
69
|
case complexity
|
70
|
-
when
|
70
|
+
when EASY
|
71
71
|
{ attempts: 14, hints: 2 }
|
72
|
-
when
|
72
|
+
when MEDIUM
|
73
73
|
{ attempts: 10, hints: 1 }
|
74
|
-
when
|
74
|
+
when HARD
|
75
75
|
{ attempts: 5, hints: 1 }
|
76
76
|
end
|
77
77
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module CodebrackerSimb
|
4
|
-
RULES = '- Codebreaker is a logic game in which a
|
5
|
-
'The codemaker, which will be played by the application we’re going to write, creates a secret code of four'\
|
4
|
+
RULES = '- Codebreaker is a logic game in which a codebreaker tries to break a secret code created by a code-maker.' \
|
5
|
+
'The codemaker, which will be played by the application we’re going to write, creates a secret code of four' \
|
6
6
|
'numbers between 1 and 6.
|
7
|
-
- The codebreaker gets some number of chances to break the code (depends on chosen difficulty).'\
|
8
|
-
'In each turn, the codebreaker makes a guess of 4 numbers. The codemaker then marks the guess with'\
|
7
|
+
- The codebreaker gets some number of chances to break the code (depends on chosen difficulty).' \
|
8
|
+
'In each turn, the codebreaker makes a guess of 4 numbers. The codemaker then marks the guess with' \
|
9
9
|
'up to 4 signs - + or - or empty spaces.
|
10
|
-
-A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in the'\
|
11
|
-
'secret'\
|
12
|
-
'code and in the same position.'\
|
10
|
+
-A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in the' \
|
11
|
+
'secret' \
|
12
|
+
'code and in the same position.' \
|
13
13
|
'For example:
|
14
14
|
Secret number - 1234
|
15
15
|
Input number - 6264
|
16
16
|
Number of pluses - 2 (second and fourth position)
|
17
|
-
- A - indicates a number match: one of the numbers in the guess is the same as one of the numbers in the'\
|
17
|
+
- A - indicates a number match: one of the numbers in the guess is the same as one of the numbers in the' \
|
18
18
|
'secret code but in a different position. For example:
|
19
19
|
Secret number - 1234
|
20
20
|
Input number - 6462
|
21
21
|
Number of minuses - 2 (second and fourth position)
|
22
22
|
- An empty space indicates that there is not a current digit in a secret number.
|
23
|
-
- If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are'\
|
23
|
+
- If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are' \
|
24
24
|
'spent - codebreaker loses.
|
25
|
-
- Codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint'\
|
25
|
+
- Codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint' \
|
26
26
|
'- he receives back a separate digit of the secret code.'
|
27
27
|
|
28
28
|
INSTRUCTION = "Enter one of the following command:
|
data/lib/codebracker_simb.rb
CHANGED
@@ -3,13 +3,11 @@
|
|
3
3
|
require_relative 'codebracker_simb/version'
|
4
4
|
require_relative 'codebracker_simb/game'
|
5
5
|
require_relative 'codebracker_simb/validator'
|
6
|
-
require_relative 'errors/no_hints_error'
|
7
|
-
require_relative 'errors/code_error'
|
8
|
-
require_relative 'errors/name_error'
|
9
|
-
require_relative 'errors/
|
10
|
-
require_relative 'errors/intro_error'
|
6
|
+
require_relative 'codebracker_simb/errors/no_hints_error'
|
7
|
+
require_relative 'codebracker_simb/errors/code_error'
|
8
|
+
require_relative 'codebracker_simb/errors/name_error'
|
9
|
+
require_relative 'codebracker_simb/errors/intro_error'
|
11
10
|
require_relative 'codebracker_simb/text'
|
12
11
|
|
13
12
|
module CodebrackerSimb
|
14
|
-
|
15
13
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebracker_simb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- max
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fasterer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +39,7 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: rubocop-performance
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -77,20 +91,20 @@ files:
|
|
77
91
|
- codebracker_simb.gemspec
|
78
92
|
- lib/codebracker_simb.rb
|
79
93
|
- lib/codebracker_simb/checker.rb
|
94
|
+
- lib/codebracker_simb/errors/code_error.rb
|
95
|
+
- lib/codebracker_simb/errors/intro_error.rb
|
96
|
+
- lib/codebracker_simb/errors/name_error.rb
|
97
|
+
- lib/codebracker_simb/errors/no_hints_error.rb
|
80
98
|
- lib/codebracker_simb/game.rb
|
81
99
|
- lib/codebracker_simb/text.rb
|
82
100
|
- lib/codebracker_simb/validator.rb
|
83
101
|
- lib/codebracker_simb/version.rb
|
84
|
-
- lib/errors/code_error.rb
|
85
|
-
- lib/errors/complexity_error.rb
|
86
|
-
- lib/errors/intro_error.rb
|
87
|
-
- lib/errors/name_error.rb
|
88
|
-
- lib/errors/no_hints_error.rb
|
89
102
|
homepage:
|
90
103
|
licenses:
|
91
104
|
- MIT
|
92
105
|
metadata:
|
93
106
|
allowed_push_host: https://rubygems.org
|
107
|
+
rubygems_mfa_required: 'true'
|
94
108
|
post_install_message:
|
95
109
|
rdoc_options: []
|
96
110
|
require_paths:
|
@@ -99,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
113
|
requirements:
|
100
114
|
- - ">="
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: 3.0
|
116
|
+
version: '3.0'
|
103
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
118
|
requirements:
|
105
119
|
- - ">="
|
data/lib/errors/code_error.rb
DELETED
data/lib/errors/intro_error.rb
DELETED
data/lib/errors/name_error.rb
DELETED