codebreaker_vv 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 439337a744ac051b490564a2803a8cec810b92958d88dd4c20898ec7140d14a2
4
+ data.tar.gz: c8b47100bc0fbb692bbbf8bca0561c631aca4e2a78e952a148926e1c33d4e749
5
+ SHA512:
6
+ metadata.gz: 2015a698b93ff308c99c94e75b2b487c23f104a150176e00d077256a914011fbb6e616aea9fb41dd5a8d89680a1228e7cf5b3ce7a4cb8a5d44340991d7b01787
7
+ data.tar.gz: 2e727143f3435cc912c6cd0b6ffedce297d4ef8b4412e2360e0cbf9a1145c05f0bdf6b2ac9f82aafe7d2e70c1c9c66f97c3798a51796886b0b415f15081643eb
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.1.2) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.7, rbenv: 3.1.2) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, rbenv: 3.1.2) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, rbenv: 3.1.2) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.1.2) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="fasterer (v0.9.0, rbenv: 3.1.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, rbenv: 3.1.2) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, rbenv: 3.1.2) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, rbenv: 3.1.2) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, rbenv: 3.1.2) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="pry (v0.14.1, rbenv: 3.1.2) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.1.2) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.1.2) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rbs (v2.1.0, rbenv: 3.1.2) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, rbenv: 3.1.2) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.1.2) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, rbenv: 3.1.2) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.36.0, rbenv: 3.1.2) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.21.0, rbenv: 3.1.2) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, rbenv: 3.1.2) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="ruby_parser (v3.19.1, rbenv: 3.1.2) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="sexp_processor (v4.16.1, rbenv: 3.1.2) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.2.0, rbenv: 3.1.2) [gem]" level="application" />
41
+ </component>
42
+ </module>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codebreaker.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 13.0'
7
+
8
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codebreaker_vv (0.1.0)
5
+ fasterer (~> 0.9.0)
6
+ pry (~> 0.14.1)
7
+ rubocop (~> 1.21)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ coderay (1.1.3)
14
+ colorize (0.8.1)
15
+ diff-lcs (1.5.0)
16
+ fasterer (0.9.0)
17
+ colorize (~> 0.7)
18
+ ruby_parser (>= 3.14.1)
19
+ json (2.6.2)
20
+ method_source (1.0.0)
21
+ parallel (1.22.1)
22
+ parser (3.1.2.1)
23
+ ast (~> 2.4.1)
24
+ pry (0.14.1)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ regexp_parser (2.5.0)
30
+ rexml (3.2.5)
31
+ rspec (3.11.0)
32
+ rspec-core (~> 3.11.0)
33
+ rspec-expectations (~> 3.11.0)
34
+ rspec-mocks (~> 3.11.0)
35
+ rspec-core (3.11.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-expectations (3.11.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-mocks (3.11.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-support (3.11.0)
44
+ rubocop (1.36.0)
45
+ json (~> 2.3)
46
+ parallel (~> 1.10)
47
+ parser (>= 3.1.2.1)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.8, < 3.0)
50
+ rexml (>= 3.2.5, < 4.0)
51
+ rubocop-ast (>= 1.20.1, < 2.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 1.4.0, < 3.0)
54
+ rubocop-ast (1.21.0)
55
+ parser (>= 3.1.1.0)
56
+ ruby-progressbar (1.11.0)
57
+ ruby_parser (3.19.1)
58
+ sexp_processor (~> 4.16)
59
+ sexp_processor (4.16.1)
60
+ unicode-display_width (2.2.0)
61
+
62
+ PLATFORMS
63
+ x86_64-darwin-21
64
+
65
+ DEPENDENCIES
66
+ codebreaker_vv!
67
+ rake (~> 13.0)
68
+ rspec (~> 3.0)
69
+
70
+ BUNDLED WITH
71
+ 2.3.7
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Codebreaker
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codebreaker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'codebreaker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install codebreaker
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codebreaker.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,38 @@
1
+ require_relative 'lib/codebreaker/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'codebreaker_vv'
5
+ spec.version = Codebreaker::VERSION
6
+ spec.authors = ['Valerii']
7
+ spec.email = ['valerii.radzhabov@rubygarage.org']
8
+
9
+ spec.summary = 'Codebreaker game'
10
+ spec.description = 'This awesome gem can create a secret code and a lot of other beautyful things!'
11
+ spec.homepage = 'https://rubygems.org/gems/codebreaker_vv'
12
+ spec.required_ruby_version = '>= 3.1'
13
+
14
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency 'fasterer', '~> 0.9.0'
33
+ spec.add_dependency 'pry', '~> 0.14.1'
34
+ spec.add_dependency 'rubocop', '~> 1.21'
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,77 @@
1
+ require_relative 'codebreaker/version'
2
+ require_relative 'src/autoloader'
3
+
4
+ module Codebreaker
5
+ class Error < StandardError; end
6
+
7
+ class << self
8
+ attr_reader :secret_code, :attempts, :hints
9
+
10
+ def start_game(difficulty, player_name)
11
+ @total_attempts = 0
12
+ @total_hints = 1
13
+ @difficulty = difficulty
14
+ @player_name = player_name
15
+ init_difficulty_stats(difficulty)
16
+ @hints = @total_hints
17
+ @attempts = @total_attempts
18
+ generate_secret_code
19
+ end
20
+
21
+ def check_code_and_give_result(user_code)
22
+ answer = @verifier.verify_user_code(user_code)
23
+ @attempts -= 1
24
+
25
+ if answer == '++++'
26
+ "#{answer} #{Locale::PLAYER_WIN}"
27
+ elsif @attempts <= 0
28
+ "#{answer} #{Locale::PLAYER_LOSE}"
29
+ else
30
+ answer
31
+ end
32
+ end
33
+
34
+ def give_hint
35
+ if @hints <= 0
36
+ Locale::NO_MORE_HINTS_AVAILABLE
37
+ else
38
+ @hints -= 1
39
+ hint = @code_for_hints.sample
40
+ @code_for_hints.delete_at(@code_for_hints.index(hint))
41
+ hint
42
+ end
43
+ end
44
+
45
+ def save_game_result
46
+ attempts_used = @total_attempts - @attempts
47
+ hints_used = @total_hints - @hints
48
+ DataBaseManager.instance.save_game_results([@player_name, @difficulty,
49
+ @total_attempts, attempts_used,
50
+ @total_hints, hints_used])
51
+ end
52
+
53
+ def load_game_results
54
+ DataBaseManager.instance.load_game_results
55
+ end
56
+
57
+ private
58
+
59
+ def init_difficulty_stats(difficulty)
60
+ case difficulty
61
+ when 0
62
+ @total_attempts = 15
63
+ @total_hints = 2
64
+ when 1
65
+ @total_attempts = 10
66
+ else
67
+ @total_attempts = 5
68
+ end
69
+ end
70
+
71
+ def generate_secret_code
72
+ @secret_code = Factory.new.new_secret_code
73
+ @verifier = CodeVerifier.new(@secret_code)
74
+ @code_for_hints = @secret_code.clone
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'code_verifier'
2
+ require_relative 'factory'
3
+ require_relative 'config/locale'
4
+ require_relative 'data_base_manager'
5
+ require 'pry'
6
+ require 'yaml'
@@ -0,0 +1,40 @@
1
+ class CodeVerifier
2
+ def initialize(secret_code)
3
+ @secret_code = secret_code
4
+ @code = []
5
+ @user_code = []
6
+ end
7
+
8
+ def verify_user_code(user_code_)
9
+ @code = @secret_code.clone
10
+ @user_code = user_code_
11
+ "#{check_matches}#{check_includes}"
12
+ end
13
+
14
+ private
15
+
16
+ def check_matches
17
+ answer = ''
18
+ @user_code.to_enum.with_index.reverse_each do |_, index|
19
+ next unless @code[index] == @user_code[index]
20
+
21
+ answer += '+'
22
+ @user_code.delete_at(index)
23
+ @code.delete_at(index)
24
+ end
25
+ answer
26
+ end
27
+
28
+ def check_includes
29
+ answer = ''
30
+ @user_code.to_enum.with_index.reverse_each do |element, user_element_index|
31
+ next unless @code.include?(element)
32
+
33
+ answer += '-'
34
+ @user_code.delete_at(user_element_index)
35
+ code_element = @code.find { |new_element| new_element == element }
36
+ @code.delete_at(@code.index(code_element))
37
+ end
38
+ answer
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ class Locale
2
+ PLAYER_WIN = 'win'.freeze
3
+ PLAYER_LOSE = 'lose'.freeze
4
+ NO_MORE_HINTS_AVAILABLE = 'You have used all hints.'.freeze
5
+ end
@@ -0,0 +1,24 @@
1
+ class DataBaseManager
2
+ @instance = new
3
+ private_class_method :new
4
+ class << self
5
+ attr_reader :instance
6
+ end
7
+
8
+ def save_game_results(attributes)
9
+ data = { name: attributes[0], difficulty: attributes[1], attempts_total: attributes[2],
10
+ attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[4] }
11
+ Dir.mkdir('lib/db') unless Dir.exist?('lib/db')
12
+ File.open('lib/db/codebreaker_db.yml', 'a') { |file| file.puts(data.to_yaml) }
13
+ end
14
+
15
+ def load_game_results
16
+ game_results = []
17
+ File.open('lib/db/codebreaker_db.yml') do |yaml_file|
18
+ YAML.load_stream(yaml_file) do |document|
19
+ game_results << document
20
+ end
21
+ end
22
+ game_results
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ class Factory
2
+ def new_secret_code
3
+ secret_code = []
4
+
5
+ 4.times do
6
+ secret_code << rand(1..6)
7
+ end
8
+ secret_code
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Codebreaker
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker_vv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Valerii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-10 00:00:00.000000000 Z
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.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.14.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.21'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.21'
55
+ description: This awesome gem can create a secret code and a lot of other beautyful
56
+ things!
57
+ email:
58
+ - valerii.radzhabov@rubygarage.org
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".fasterer.yml"
64
+ - ".idea/.gitignore"
65
+ - ".idea/codebreaker.iml"
66
+ - ".rspec"
67
+ - ".rubocop.yml"
68
+ - ".ruby-version"
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.md
72
+ - Rakefile
73
+ - codebreaker.gemspec
74
+ - lib/codebreaker.rb
75
+ - lib/codebreaker/version.rb
76
+ - lib/src/autoloader.rb
77
+ - lib/src/code_verifier.rb
78
+ - lib/src/config/locale.rb
79
+ - lib/src/data_base_manager.rb
80
+ - lib/src/factory.rb
81
+ - sig/codebreaker.rbs
82
+ homepage: https://rubygems.org/gems/codebreaker_vv
83
+ licenses: []
84
+ metadata:
85
+ allowed_push_host: https://rubygems.org
86
+ homepage_uri: https://rubygems.org/gems/codebreaker_vv
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '3.1'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.3.7
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Codebreaker game
106
+ test_files: []