codebreaker_anzq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ed305e13f01729104c0783908234688845947e4152d650adaf88924ffe44591
4
+ data.tar.gz: a475204c158fd2c390fd34018647238886bbdfe3a41d91403b50eef051db5e35
5
+ SHA512:
6
+ metadata.gz: f028919d8ff8f8c93b7f33a392efaaa8ac490a32acfd857a768fec66cb5006a7f85129e2a7278fe31e6923291756da5e619cdaad73b8c320e7a61b55032e5729
7
+ data.tar.gz: b6648850b2e1965fc86437ebc95d1c3e353fb70d5e5c4dfed0fe878b9b51f2a3153be11d8371d4b06f485815f03c1ca76ddf5ed14e6afd3d2a30e3c4dc252b8f
data/.fasterer.yml ADDED
@@ -0,0 +1,21 @@
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
20
+ exclude_paths:
21
+ - vendor/**/*.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7.3
7
+ Exclude:
8
+ - 'vendor/bundle/**/*'
9
+ NewCops: enable
10
+
11
+ Layout/LineLength:
12
+ Max: 120
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/HashSyntax:
18
+ Enabled: false
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'codebreaker.gemspec'
23
+ IgnoredMethods: ['describe', 'context']
24
+
25
+ RSpec/MultipleMemoizedHelpers:
26
+ Enabled: False
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-06-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at shpakovych18@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in codebreaker.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codebreaker_anzq (0.1.0)
5
+ bundler (~> 2.3.7)
6
+ rake (~> 13.0.6)
7
+ yaml (~> 0.2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ colorize (0.8.1)
14
+ concurrent-ruby (1.1.10)
15
+ diff-lcs (1.5.0)
16
+ docile (1.4.0)
17
+ fasterer (0.10.0)
18
+ colorize (~> 0.7)
19
+ ruby_parser (>= 3.19.1)
20
+ i18n (1.10.0)
21
+ concurrent-ruby (~> 1.0)
22
+ parallel (1.22.1)
23
+ parser (3.1.2.0)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.1.1)
26
+ rake (13.0.6)
27
+ regexp_parser (2.5.0)
28
+ rexml (3.2.5)
29
+ rspec (3.11.0)
30
+ rspec-core (~> 3.11.0)
31
+ rspec-expectations (~> 3.11.0)
32
+ rspec-mocks (~> 3.11.0)
33
+ rspec-core (3.11.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-expectations (3.11.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.11.0)
38
+ rspec-mocks (3.11.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.11.0)
41
+ rspec-support (3.11.0)
42
+ rubocop (1.30.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.1.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.18.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 3.0)
51
+ rubocop-ast (1.18.0)
52
+ parser (>= 3.1.1.0)
53
+ rubocop-performance (1.14.2)
54
+ rubocop (>= 1.7.0, < 2.0)
55
+ rubocop-ast (>= 0.4.0)
56
+ rubocop-rspec (2.11.1)
57
+ rubocop (~> 1.19)
58
+ ruby-progressbar (1.11.0)
59
+ ruby_parser (3.19.1)
60
+ sexp_processor (~> 4.16)
61
+ sexp_processor (4.16.1)
62
+ simplecov (0.21.2)
63
+ docile (~> 1.1)
64
+ simplecov-html (~> 0.11)
65
+ simplecov_json_formatter (~> 0.1)
66
+ simplecov-html (0.12.3)
67
+ simplecov_json_formatter (0.1.4)
68
+ unicode-display_width (2.1.0)
69
+ yaml (0.2.0)
70
+
71
+ PLATFORMS
72
+ x86_64-linux
73
+
74
+ DEPENDENCIES
75
+ codebreaker_anzq!
76
+ fasterer (~> 0.10.0)
77
+ i18n (~> 1.10.0)
78
+ rspec (~> 3.0)
79
+ rubocop (~> 1.30.1)
80
+ rubocop-performance (~> 1.14.2)
81
+ rubocop-rspec (~> 2.11.1)
82
+ simplecov (~> 0.21.2)
83
+
84
+ BUNDLED WITH
85
+ 2.3.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 AntonShpakovych
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
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
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add codebreaker
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install codebreaker
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codebreaker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Codebreaker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
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,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ I18n.load_path << Dir[File.expand_path('codebreaker/config/locales/*.yml')]
4
+ I18n.config.available_locales = :en
@@ -0,0 +1,38 @@
1
+ en:
2
+ guess: Number, required, length - %{length_good} digits, each digit is a number in the range %{correct_range_first} - %{correct_range_last}
3
+ name: Name - string, required, min length - %{min_length} symbols, max length - %{max_length}
4
+ empty_data: "Don't have data for save"
5
+ bad_file: "File doesn't exist or File doesn't have data"
6
+ message_for_attempts: You have not any attempts left
7
+ message_for_hints: You have not any hints left
8
+ rules: "
9
+ 1 - Codebreaker is a logic game in which a code-breaker tries to break a secret code created
10
+ by a code-maker.
11
+ The codemaker, which will be played by the application we're going to write,
12
+ creates a secret code of four numbers between %{correct_range_first} and %{correct_range_last}.
13
+
14
+ 2 - The codebreaker gets some number of chances to break the code (depends on chosen difficulty).
15
+ In each turn, the codebreaker makes a guess of %{length_good} numbers.
16
+ The codemaker then marks the guess with up to %{length_good} signs - + or - or empty spaces.
17
+
18
+ 3 - A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in
19
+ the secret code and in the same position.
20
+ For example:
21
+ Secret number - 1234
22
+ Input number - 6264
23
+ Number of pluses - 2 (second and fourth position)
24
+
25
+ 4 - A - indicates a number match: one of the numbers in the guess is the same as one of the numbers in
26
+ the secret code but in a different position.
27
+ For example:
28
+ Secret number - 1234
29
+ Input number - 6462
30
+ Number of minuses - 2 (second and fourth position)
31
+
32
+ 5 - An empty space indicates that there is not a current digit in a secret number.
33
+
34
+ 6 - If codebreaker inputs the exact number as a secret number - codebreaker wins the game.
35
+ If all attempts are spent - codebreaker loses.
36
+ 7 - Codebreaker also has some number of hints(depends on chosen difficulty).
37
+ If a user takes a hint - he receives back a separate digit of the secret code.
38
+ "
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class Game
5
+ include Validations
6
+ include Constants::Shared
7
+
8
+ attr_reader :user, :attempts, :hints, :type, :win
9
+
10
+ def initialize(user:, type_of_difficulty:)
11
+ @win = false
12
+ @user = user
13
+ @secret_code = RandomSecretCode.call
14
+ @attempts = TYPE_OF_DIFFICULTY[type_of_difficulty][:attempts]
15
+ @hints = TYPE_OF_DIFFICULTY[type_of_difficulty][:hints]
16
+ @secret_code_for_hints = @secret_code.shuffle
17
+ @type = type_of_difficulty
18
+ end
19
+
20
+ def my_guess(guess)
21
+ validate_for_guess(guess)
22
+ raise(StandardError, I18n.t(:message_for_attempts)) unless @attempts.positive?
23
+
24
+ @result = GuessChecker.new(guess.chars, @secret_code).check_guess
25
+ @attempts -= 1
26
+ @win = won?
27
+ @result
28
+ end
29
+
30
+ def give_hints
31
+ @hints.positive? ? check_hints : raise(StandardError, I18n.t(:message_for_hints))
32
+ end
33
+
34
+ def self.user_validate_in_game?(user)
35
+ user.is_a?(User)
36
+ end
37
+
38
+ def self.type_of_difficulty_validate?(difficulty)
39
+ TYPE_OF_DIFFICULTY.key?(difficulty.to_sym)
40
+ end
41
+
42
+ private
43
+
44
+ def won?
45
+ @result[:index] == WINNING_INDEX
46
+ end
47
+
48
+ def check_hints
49
+ @hints -= 1
50
+ @secret_code_for_hints.pop
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class GuessChecker
5
+ attr_reader :store
6
+
7
+ def initialize(guess, secret_code)
8
+ @store = { index: 0, include: 0 }
9
+ @encryption = secret_code
10
+ @hypothesis = guess
11
+ end
12
+
13
+ def check_guess
14
+ temp_encryption = @encryption.dup
15
+ temp_hypothesis = @hypothesis.dup
16
+ each_for_index(temp_hypothesis, temp_encryption)
17
+ each_for_include(temp_hypothesis, temp_encryption)
18
+ @store
19
+ end
20
+
21
+ private
22
+
23
+ def for_index(temp_guess, index, temp_object)
24
+ @store[:index] += 1
25
+ temp_object.delete_at(index)
26
+ temp_guess.delete_at(index)
27
+ end
28
+
29
+ def each_for_index(temp_guess, temp_object)
30
+ temp_object.zip(temp_guess).map do |item_object, item_guess|
31
+ for_index(temp_guess, temp_guess.index(item_object), temp_object) if item_object == item_guess
32
+ end
33
+ end
34
+
35
+ def each_for_include(temp_guess, temp_object)
36
+ @store[:include] += temp_object.length - (temp_object - temp_guess).length
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ module Constants
5
+ module Shared
6
+ WINNING_INDEX = 4
7
+ LENGTH_GOOD = 4
8
+ CORRECT_RANGE = (1..6).freeze
9
+ TYPE_OF_DIFFICULTY = { easy: { attempts: 15, hints: 2 },
10
+ medium: { attempts: 10, hints: 1 },
11
+ hell: { attempts: 5, hints: 1 } }.freeze
12
+
13
+ REGULAR_FOR_CODE = /\A[1-6]{4}\z/.freeze
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class RandomSecretCode
5
+ include Constants::Shared
6
+
7
+ def self.call
8
+ Array.new(LENGTH_GOOD) { Random.rand(CORRECT_RANGE).to_s }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class Rules
5
+ include Constants::Shared
6
+
7
+ def self.call
8
+ I18n.t(:rules,
9
+ correct_range_first: CORRECT_RANGE.first,
10
+ correct_range_last: CORRECT_RANGE.last,
11
+ length_good: LENGTH_GOOD)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class Statistics
5
+ include Constants::Shared
6
+
7
+ attr_reader :filename
8
+
9
+ FILENAME = 'default.yml'
10
+
11
+ def initialize(filename = FILENAME)
12
+ @filename = filename
13
+ @data_store = []
14
+ end
15
+
16
+ def add_to_data_store(game)
17
+ @data_store.push(data_to_save(game))
18
+ end
19
+
20
+ def save_unit
21
+ @data_store.empty? ? raise(StandardError, I18n.t(:empty_data)) : File.write(@filename, @data_store.to_yaml)
22
+ end
23
+
24
+ def show
25
+ file_valid? ? sort_store(YAML.load_file(@filename)) : raise(StandardError, I18n.t(:bad_file))
26
+ end
27
+
28
+ private
29
+
30
+ def sort_store(data)
31
+ sort_attemps_hints = data.sort_by { |hints| hints[:hints_used] }.sort_by { |attempts| attempts[:attempts_used] }
32
+ sort_attemps_hints.sort_by { |difficulty| difficulty[:hints_total] && difficulty[:attempts_total] }
33
+ end
34
+
35
+ def file_valid?
36
+ File.exist?(@filename) && !File.zero?(@filename)
37
+ end
38
+
39
+ def total_attempts(type)
40
+ TYPE_OF_DIFFICULTY[type][:attempts]
41
+ end
42
+
43
+ def total_hints(type)
44
+ TYPE_OF_DIFFICULTY[type][:hints]
45
+ end
46
+
47
+ def data_to_save(game)
48
+ { user: game.user,
49
+ difficulty: game.type,
50
+ attempts_total: total_attempts(game.type),
51
+ attempts_used: total_attempts(game.type) - game.attempts,
52
+ hints_total: total_hints(game.type),
53
+ hints_used: total_hints(game.type) - game.hints }
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class User
5
+ extend Validations
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ module Validations
5
+ include Constants::Shared
6
+
7
+ MAX_LENGTH = 20
8
+ MIN_LENGTH = 3
9
+ ERROR_NAME = 'name'
10
+ ERROR_GUESS = 'guess'
11
+
12
+ def validate_for_name(name)
13
+ (MIN_LENGTH..MAX_LENGTH).cover?(name.length) ? name : error(ERROR_NAME)
14
+ end
15
+
16
+ private
17
+
18
+ def validate_for_guess(guess)
19
+ error(ERROR_GUESS) unless guess.match(REGULAR_FOR_CODE)
20
+ end
21
+
22
+ def error(error_for)
23
+ case error_for
24
+ when ERROR_NAME then raise(StandardError, I18n.t(:name, min_length: MIN_LENGTH, max_length: MAX_LENGTH))
25
+ when ERROR_GUESS
26
+ raise(StandardError, I18n.t(:guess,
27
+ length_good: LENGTH_GOOD, correct_range_first: CORRECT_RANGE.first,
28
+ correct_range_last: CORRECT_RANGE.last))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'i18n'
5
+ require_relative 'codebreaker/config/initializer/text_resources'
6
+ require_relative 'codebreaker/helpers/constants'
7
+ require_relative 'codebreaker/validations/validations'
8
+ require_relative 'codebreaker/user'
9
+ require_relative 'codebreaker/rules'
10
+ require_relative 'codebreaker/guess'
11
+ require_relative 'codebreaker/randomsecret'
12
+ require_relative 'codebreaker/game'
13
+ require_relative 'codebreaker/statistics'
14
+ require_relative 'codebreaker/version'
15
+
16
+ module Codebreaker
17
+ 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,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker_anzq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AntonShpakovych
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: fasterer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: i18n
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.10.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.30.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.30.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.14.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.14.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.11.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.11.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.21.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.21.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: yaml
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.2.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.2.0
153
+ description: |-
154
+ Codebreaker is a logic game in which a code-breaker tries to break a secret code
155
+ created by a code-maker.
156
+ The codemaker, which will be played by the application we're going to write,
157
+ creates a secret code of four numbers between 1 and 6.
158
+ The codebreaker gets some number of chances to break the code (depends on chosen difficulty).
159
+ In each turn, the codebreaker makes a guess of 4 numbers.
160
+ email:
161
+ - shpakovych18@gmail.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".fasterer.yml"
167
+ - ".rspec"
168
+ - ".rubocop.yml"
169
+ - ".ruby-version"
170
+ - CHANGELOG.md
171
+ - CODE_OF_CONDUCT.md
172
+ - Gemfile
173
+ - Gemfile.lock
174
+ - LICENSE.txt
175
+ - README.md
176
+ - Rakefile
177
+ - lib/codebreaker.rb
178
+ - lib/codebreaker/config/initializer/text_resources.rb
179
+ - lib/codebreaker/config/locales/en.yml
180
+ - lib/codebreaker/game.rb
181
+ - lib/codebreaker/guess.rb
182
+ - lib/codebreaker/helpers/constants.rb
183
+ - lib/codebreaker/randomsecret.rb
184
+ - lib/codebreaker/rules.rb
185
+ - lib/codebreaker/statistics.rb
186
+ - lib/codebreaker/user.rb
187
+ - lib/codebreaker/validations/validations.rb
188
+ - lib/codebreaker/version.rb
189
+ - sig/codebreaker.rbs
190
+ homepage: https://github.com/AntonShpakovych/newgemruby
191
+ licenses:
192
+ - MIT
193
+ metadata:
194
+ allowed_push_host: https://rubygems.org/
195
+ homepage_uri: https://github.com/AntonShpakovych/newgemruby
196
+ source_code_uri: https://github.com/AntonShpakovych/newgemruby
197
+ changelog_uri: https://github.com/AntonShpakovych/newgemruby/CHANGELOG.md
198
+ rubygems_mfa_required: 'true'
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: 2.7.3
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubygems_version: 3.1.6
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Codebreaker is a logic game in which a code-breaker tries to break a secret
218
+ code created by a code-maker.
219
+ test_files: []