codebreakerq 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +15 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +44 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +29 -0
- data/lib/codebreaker/bll/comands.rb +39 -0
- data/lib/codebreaker/bll/game_engine.rb +95 -0
- data/lib/codebreaker/bll/modules/error_module.rb +13 -0
- data/lib/codebreaker/bll/modules/rules_module.rb +15 -0
- data/lib/codebreaker/bll/spec/bll_spec.rb +0 -0
- data/lib/codebreaker/bll/statistic.rb +6 -0
- data/lib/codebreaker/dal/modules/dal_module.rb +15 -0
- data/lib/codebreaker/dal/modules/error_module.rb +11 -0
- data/lib/codebreaker/dal/spec/dal_spec.rb +0 -0
- data/lib/codebreaker/helpers/error.rb +5 -0
- data/lib/codebreaker/helpers/helpers_module.rb +6 -0
- data/lib/codebreaker/helpers/validation_module.rb +35 -0
- data/lib/codebreaker/index.rb +22 -0
- data/lib/codebreaker/version.rb +5 -0
- data/lib/codebreaker.rb +38 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c31b9328367e799a547506f25268c44afdc819860a4d8813189ff9cabdbc4bd3
|
4
|
+
data.tar.gz: 447b9a0d252f1cec4fbb29c73bcdba86ff30059d0375f1a53d28126abf0790cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea314febeb3178fe6b5fdd668c529f03753fa2ec8f81d269a906ace0df0dfdb00c8de6dec641ba86410ddaee51b05f36267e785469c603cea659fbc057836560
|
7
|
+
data.tar.gz: 0b591a2386c4c92e39af8164b1a8b6307ce0b2984f7a9b4b58e70ec736c503e7312f22a8a23f54f9a651530369b43bbde01d6f5dfdfe06fa90f878f460c728ea
|
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/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/RedundantFetchBlock:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Layout/SpaceAroundMethodCallOperator:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Lint/DeprecatedOpenSSLConstant:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Lint/RaiseException:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/StructNewOverride:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Style/ExponentialNotation:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Style/HashEachMethods:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Style/HashTransformKeys:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Style/HashTransformValues:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
Style/SlicingWithRange:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Lint/MixedRegexpCaptureTypes:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Style/RedundantRegexpCharacterClass:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Style/RedundantRegexpEscape:
|
44
|
+
Enabled: true
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at noobfrizz1@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreakerq (0.1.7)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
cli-ui (1.3.0)
|
10
|
+
diff-lcs (1.4.1)
|
11
|
+
rake (12.3.3)
|
12
|
+
rspec (3.9.0)
|
13
|
+
rspec-core (~> 3.9.0)
|
14
|
+
rspec-expectations (~> 3.9.0)
|
15
|
+
rspec-mocks (~> 3.9.0)
|
16
|
+
rspec-core (3.9.2)
|
17
|
+
rspec-support (~> 3.9.3)
|
18
|
+
rspec-expectations (3.9.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.9.0)
|
21
|
+
rspec-mocks (3.9.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-support (3.9.3)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler
|
31
|
+
cli-ui
|
32
|
+
codebreakerq!
|
33
|
+
rake (~> 12.0)
|
34
|
+
rspec (~> 3.0)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 bastare
|
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,44 @@
|
|
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 tags, 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. 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).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
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
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'codebreaker'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/codebreaker.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/codebreaker/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codebreakerq'
|
7
|
+
spec.version = Codebreaker::VERSION
|
8
|
+
spec.authors = ['bastare']
|
9
|
+
spec.email = ['noobfrizz1@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Game `Codebreaker`'
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://github.com/bastare/codebreaker-gem'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'cli-ui'
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
module BLL
|
7
|
+
module Commands
|
8
|
+
class << self
|
9
|
+
def start(**difucult)
|
10
|
+
Codebreaker.start(**difucult)
|
11
|
+
end
|
12
|
+
|
13
|
+
def stats
|
14
|
+
# TODO: add DAL
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_game_statistic(**statistic)
|
18
|
+
p statistic.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def enter_name
|
22
|
+
DAL.enter_name(CLI::UI.ask('What ur name?'))
|
23
|
+
# DAL.enter_name('qwer')
|
24
|
+
end
|
25
|
+
|
26
|
+
def chose_diffucult
|
27
|
+
CLI::UI::Prompt.ask('Chose diffucult:') do |handler|
|
28
|
+
BLL::DIFFUCULTS.each do |diffucult_name, diffucult_parameters|
|
29
|
+
handler.option(diffucult_name.to_s) do
|
30
|
+
{ diffucult_name: diffucult_name, diffucult_parameters: diffucult_parameters }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# BLL::DIFFUCULTS.values.first
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
module BLL
|
7
|
+
class GameEngine
|
8
|
+
WrongGuessNumber = Class.new(Error::ValidationError)
|
9
|
+
|
10
|
+
attr_reader :secret_number, :hints, :attempts
|
11
|
+
|
12
|
+
def initialize(**diffucult)
|
13
|
+
diffucult_parameters = diffucult[:diffucult_parameters]
|
14
|
+
|
15
|
+
@number_of_digits = BLL::NUMBER[:digits]
|
16
|
+
@digits_range = BLL::NUMBER[:range]
|
17
|
+
@hints = diffucult_parameters[:hints]
|
18
|
+
@attempts = diffucult_parameters[:attempts]
|
19
|
+
|
20
|
+
@secret_number = generate_number(@number_of_digits, @digits_range)
|
21
|
+
end
|
22
|
+
|
23
|
+
def input_guess?(guess_number)
|
24
|
+
return unless guess_number_valid? guess_number
|
25
|
+
|
26
|
+
attemps_counter
|
27
|
+
|
28
|
+
metching(guess_number) == '++++'
|
29
|
+
end
|
30
|
+
|
31
|
+
def hint
|
32
|
+
return CLI::UI.fmt '{{x}}All hints were used' if @hints.zero?
|
33
|
+
|
34
|
+
@hints -= 1
|
35
|
+
|
36
|
+
CLI::UI.fmt "{{*}}#{@secret_number.sample}"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def metching(guess_number)
|
42
|
+
secret_number = @secret_number.clone
|
43
|
+
|
44
|
+
[].tap do |result_array|
|
45
|
+
result_array.concat perfect_metching!(guess_number, secret_number)
|
46
|
+
result_array.concat metching!(guess_number, secret_number)
|
47
|
+
end.join
|
48
|
+
end
|
49
|
+
|
50
|
+
def perfect_metching!(guess_number, secret_number)
|
51
|
+
@secret_number.each_with_index.each_with_object([]) do |(digit, index), result_array|
|
52
|
+
next unless digit == guess_number[index]
|
53
|
+
|
54
|
+
guess_number[index] = nil
|
55
|
+
secret_number[index] = nil
|
56
|
+
|
57
|
+
result_array << '+'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def metching!(guess_number, secret_number)
|
62
|
+
guess_number.compact!
|
63
|
+
secret_number.compact!
|
64
|
+
|
65
|
+
secret_number.each_with_object([]) do |digit, result_array|
|
66
|
+
next unless guess_number.any?(digit)
|
67
|
+
|
68
|
+
result_array << '-'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def attemps_counter
|
73
|
+
raise(NoAttamptsError, CLI::UI.fmt('{{x}} No atempts left')) if @attempts.zero?
|
74
|
+
|
75
|
+
@attempts -= 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def generate_number(digits, range)
|
79
|
+
[].tap do |result_array|
|
80
|
+
digits.times { result_array << Random.rand(range) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def guess_number_valid?(guess_number)
|
85
|
+
if guess_number.all? { |digit| @digits_range.include?(digit) } && guess_number.size == @number_of_digits
|
86
|
+
true
|
87
|
+
else
|
88
|
+
p "`Guesse` should be in #{@digits_range} range & should`ve #{@number_of_digits} digits"
|
89
|
+
|
90
|
+
false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
module BLL
|
7
|
+
module Error
|
8
|
+
class ValidationError < Codebreaker::UnexpectedActionError; end
|
9
|
+
class WrongDiffucultError < Codebreaker::UnexpectedActionError; end
|
10
|
+
class NoHintsError < Codebreaker::UnexpectedActionError; end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
module BLL
|
7
|
+
DIFFUCULTS = {
|
8
|
+
easy: { attempts: 15, hints: 2 }.freeze,
|
9
|
+
medium: { attempts: 10, hints: 1 }.freeze,
|
10
|
+
hell: { attempts: 5, hints: 1 }.freeze
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
NUMBER = { digits: 4, range: 1..6 }.freeze
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
module DAL
|
7
|
+
extend Helpers::Validatable
|
8
|
+
|
9
|
+
def self.enter_name(player_name)
|
10
|
+
validation(player_name, ->(name) { name.length.between?(3, 20) }, presence: true) do
|
11
|
+
raise Error::ValidationError, '`Player name` '
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
module Helpers
|
5
|
+
module Validatable
|
6
|
+
ArgumentNilError = Class.new(ArgumentError)
|
7
|
+
WrongTypeError = Class.new(ArgumentError)
|
8
|
+
ValidationError = Class.new(ArgumentError)
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def validation(target, *predicates, type: nil, presence: false, &block)
|
13
|
+
required_validation(target) if presence
|
14
|
+
type_validation(target, type) if type
|
15
|
+
condition_validation(target, predicates, &block) if predicates.any?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def type_validation(target, type)
|
21
|
+
raise(WrongTypeError, 'Wrong type') unless target.is_a? type
|
22
|
+
end
|
23
|
+
|
24
|
+
def condition_validation(target, predicates)
|
25
|
+
return if predicates.all? { |predicate| predicate.call(target) }
|
26
|
+
|
27
|
+
block_given? ? yield(target) : raise(ValidationError, 'Validation failed')
|
28
|
+
end
|
29
|
+
|
30
|
+
def required_validation(target)
|
31
|
+
raise(ArgumentNilError, 'Value is nil') if target.nil?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'require_all'
|
4
|
+
# require 'rspec'
|
5
|
+
# require 'cli/ui'
|
6
|
+
|
7
|
+
require_relative './helpers/error'
|
8
|
+
require_relative './helpers/helpers_module'
|
9
|
+
require_relative './helpers/validation_module'
|
10
|
+
|
11
|
+
require_relative './bll/modules/error_module'
|
12
|
+
require_relative './bll/modules/rules_module'
|
13
|
+
|
14
|
+
require_relative './dal/modules/error_module'
|
15
|
+
require_relative './dal/modules/dal_module'
|
16
|
+
|
17
|
+
require_relative './bll/comands'
|
18
|
+
require_relative './bll/game_engine'
|
19
|
+
require_relative './bll/statistic'
|
20
|
+
|
21
|
+
require_relative 'version'
|
22
|
+
require_relative '../codebreaker'
|
data/lib/codebreaker.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'codebreaker/index'
|
4
|
+
|
5
|
+
module Codebreaker
|
6
|
+
NoAttamptsError = Class.new(ArgumentError)
|
7
|
+
class << self
|
8
|
+
def start(**diffucult)
|
9
|
+
BLL::GameEngine.new(**diffucult).tap do |breaker|
|
10
|
+
loop do
|
11
|
+
input = CLI::UI.ask("Enter ur guesse. (`hint` - total #{breaker.hints}, `attempts - #{breaker.attempts}`)")
|
12
|
+
|
13
|
+
p breaker.secret_number.to_s
|
14
|
+
|
15
|
+
if input == 'hint'
|
16
|
+
puts breaker.hint
|
17
|
+
|
18
|
+
next
|
19
|
+
end
|
20
|
+
|
21
|
+
break if breaker.input_guess?(input.chars.map(&:to_i))
|
22
|
+
end
|
23
|
+
|
24
|
+
save_statistic(diffucult_name: diffucult[:diffucult_name], attempts: breaker.attempts, hints: breaker.hints)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def save_statistic(**stats)
|
30
|
+
UI::SuccessesPage.save_statistic(
|
31
|
+
diffucult_name: stats[:diffucult_name],
|
32
|
+
attempts: stats[:attempts],
|
33
|
+
hints: stats[:hints]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreakerq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bastare
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-12 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: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cli-ui
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- noobfrizz1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".circleci/config.yml"
|
77
|
+
- ".fasterer.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".ruby-version"
|
82
|
+
- ".travis.yml"
|
83
|
+
- CODE_OF_CONDUCT.md
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- bin/console
|
90
|
+
- bin/setup
|
91
|
+
- codebreaker.gemspec
|
92
|
+
- lib/codebreaker.rb
|
93
|
+
- lib/codebreaker/bll/comands.rb
|
94
|
+
- lib/codebreaker/bll/game_engine.rb
|
95
|
+
- lib/codebreaker/bll/modules/error_module.rb
|
96
|
+
- lib/codebreaker/bll/modules/rules_module.rb
|
97
|
+
- lib/codebreaker/bll/spec/bll_spec.rb
|
98
|
+
- lib/codebreaker/bll/statistic.rb
|
99
|
+
- lib/codebreaker/dal/modules/dal_module.rb
|
100
|
+
- lib/codebreaker/dal/modules/error_module.rb
|
101
|
+
- lib/codebreaker/dal/spec/dal_spec.rb
|
102
|
+
- lib/codebreaker/helpers/error.rb
|
103
|
+
- lib/codebreaker/helpers/helpers_module.rb
|
104
|
+
- lib/codebreaker/helpers/validation_module.rb
|
105
|
+
- lib/codebreaker/index.rb
|
106
|
+
- lib/codebreaker/version.rb
|
107
|
+
homepage: https://github.com/bastare/codebreaker-gem
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 2.3.0
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.1.4
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Game `Codebreaker`
|
130
|
+
test_files: []
|