codebracker_simb 0.9.7 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc62634b6bd111914b6f7f499c48ec32d3f7c91f3b5e09a0cad99881a8f0ab9c
4
- data.tar.gz: 7759ff7e82994a4be2abc1e377fb7a0e27cd89e7511effa474ae515be3823d22
3
+ metadata.gz: 417607b3a6156d49301ccead8c607d67a73cd96bd9ff897fb40a3766b98e42ad
4
+ data.tar.gz: 3e05511446e9a3d2f2514916be6a753a33a21d03d57322f01757abee28b36326
5
5
  SHA512:
6
- metadata.gz: 84cc1bad60d70a52e300b0db9dff62f74fdc8abd66f68d256a88901762a9616691322fdfef98184bd808bc153021e5829f8bfbee0c47831f1c4771646f28c1df
7
- data.tar.gz: e0844696927f7101896bdf8f0a1143c2f68ad6c32928812ef12b7d00bb0f3be1fade74867c4e93b348c301343252dedb7e503d3fe53d58fd08fe043a4b767be4
6
+ metadata.gz: 1a0dfe667dcde0bbc52efaca333e4bd97c24c8f0bdae02b3a0985a30f98475274ca02fc8c0f0b438f1894ffd46db46c50e32c09724296ebf402ef6ab35f8054c
7
+ data.tar.gz: 6500e2f7e0ee1d3e04ab13ae44cdb453d7cb6b3189010ea02d3d6e7a7a218785c5d97eb9b525550f394f5261c6c42a0803df324a946cbe0ae8bc98f23402b50e
@@ -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.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', 'Gemfile', 'Rakefile',
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?(:plus)
28
- output << '-' if line.include?(:minus) && !line.include?(:plus)
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] = :plus
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? :minus
48
+ next if line.include? MINUS
47
49
 
48
- line[jndex] = :minus
50
+ line[jndex] = MINUS
49
51
  @filled_column << jndex
50
52
  end
51
53
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CodebrackerSimb
4
+ class CodeError < StandardError
5
+ def initialize(msg = 'Code must include only four digits from 1 to 6')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CodebrackerSimb
4
+ class IntroError < StandardError
5
+ def initialize(msg = 'It could be start, rules, stats or exit!')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CodebrackerSimb
4
+ class NameError < StandardError
5
+ def initialize(msg = 'Name should be longer than 3 chars and shorter than 20 chars!')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CodebrackerSimb
4
+ class NoHintsError < StandardError
5
+ def initialize(msg = 'You used all your hints!')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './checker'
4
- require 'rspec'
5
- require 'pry'
6
- require 'sqlite3'
7
4
 
8
5
  module CodebrackerSimb
9
6
  class Game
10
7
  attr_reader :code, :attempts, :player, :complexity
11
8
  attr_accessor :answer, :hint_positions, :hints
12
9
 
10
+ HARD = 'hard'
11
+ MEDIUM = 'medium'
12
+ EASY = 'easy'
13
+
13
14
  def initialize(complexity, player)
14
15
  @attempts = game_options(complexity)[:attempts]
15
16
  @hints = game_options(complexity)[:hints]
@@ -20,12 +21,12 @@ module CodebrackerSimb
20
21
  end
21
22
 
22
23
  def input_answer(input)
23
- @answer = input.split('').map(&:to_i)
24
+ @answer = input.chars.map(&:to_i)
24
25
  end
25
26
 
26
27
  def check_answer
27
28
  refresh_attempts_quantity
28
- Checker.new(@code, @answer).compare
29
+ Checker.new(code, answer).compare
29
30
  end
30
31
 
31
32
  def define_code
@@ -37,24 +38,20 @@ module CodebrackerSimb
37
38
  end
38
39
 
39
40
  def refresh_attempts_quantity
40
- if @attempts.positive?
41
- @attempts -= 1
42
- end
41
+ @attempts -= 1 if attempts.positive?
43
42
  end
44
43
 
45
- def hint
44
+ def hint!
46
45
  position = nil
47
46
  loop do
48
47
  position = rand(0..3)
49
48
  break unless hint_positions.include? position
50
49
  end
51
- if @hints.positive?
52
- hint_positions << position
53
- @hints -= 1
54
- code[position]
55
- else
56
- raise NoHintsError
57
- end
50
+ raise NoHintsError unless hints.positive?
51
+
52
+ hint_positions << position
53
+ @hints -= 1
54
+ code[position]
58
55
  end
59
56
 
60
57
  def params
@@ -70,11 +67,11 @@ module CodebrackerSimb
70
67
 
71
68
  def game_options(complexity)
72
69
  case complexity
73
- when 'easy'
70
+ when EASY
74
71
  { attempts: 14, hints: 2 }
75
- when 'medium'
72
+ when MEDIUM
76
73
  { attempts: 10, hints: 1 }
77
- when 'hard'
74
+ when HARD
78
75
  { attempts: 5, hints: 1 }
79
76
  end
80
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 code-breaker 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'\
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:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- VERSION = '0.9.7'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -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/complexity_error'
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: 0.9.7
4
+ version: 1.0.2
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-09 00:00:00.000000000 Z
11
+ date: 2022-09-19 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: fasterer
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.0
116
+ version: '3.0'
103
117
  required_rubygems_version: !ruby/object:Gem::Requirement
104
118
  requirements:
105
119
  - - ">="
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CodeError < StandardError
4
- def initialize(msg = "Code must include only four digits from 1 to 6")
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ComplexityError < StandardError
4
- def initialize(msg = "It could be easy, medium or hard!")
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class IntroError < StandardError
4
- def initialize(msg = "It could be start, rules, stats or exit!")
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class NameError < StandardError
4
- def initialize(msg = "Name should be longer than 3 chars and shorter than 20 chars!")
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class NoHintsError < StandardError
4
- def initialize(msg = "You used all your hints!")
5
- super
6
- end
7
- end