codebreaker_vk_vitaliy 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 +7 -0
- data/.circleci/config.yml +63 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +20 -0
- data/.overcommit.yml +27 -0
- data/.rspec +3 -0
- data/.rubocop.yml +58 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +87 -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/config/locales/en.yml +12 -0
- data/lib/codebreaker.rb +14 -0
- data/lib/codebreaker/difficulty.rb +27 -0
- data/lib/codebreaker/game.rb +109 -0
- data/lib/codebreaker/guess.rb +41 -0
- data/lib/codebreaker/player.rb +47 -0
- data/lib/codebreaker/statistics.rb +22 -0
- data/lib/codebreaker/storage_wrapper.rb +19 -0
- data/lib/codebreaker/version.rb +5 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 614524fb5b559c4a16b00ea7a25165adaaf2727e0b17fdefa2905a0820fecb10
|
4
|
+
data.tar.gz: 54a8aac85c325a19f07befcf7bf5c3cabcc8fb29a648dbfef4ce52f6a4635984
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ceddbea8af82171508021a5ab05a563db679fd850bd942693be029a65c14bc519472be3d6559c3abaa2cd190bf91551c4fb89a3b80acab0c0256987d29defd0
|
7
|
+
data.tar.gz: 170f577e009c34a959699eb772fc07b4b853fac9b0157254bfee4d8338e662d515cc1530420bff6514d692ae281f820d4d0c87d83985d1a0d606c1a4c06b7d66
|
@@ -0,0 +1,63 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
executors:
|
4
|
+
default:
|
5
|
+
working_directory: ~/repo
|
6
|
+
description: The official CircleCI Ruby Docker image
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.7.1
|
9
|
+
|
10
|
+
caches:
|
11
|
+
- &bundle_cache_full v2-repo-{{ checksum "Gemfile.lock" }}
|
12
|
+
- &bundle_cache v2-repo-
|
13
|
+
|
14
|
+
commands:
|
15
|
+
defaults:
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
- restore_cache:
|
19
|
+
keys:
|
20
|
+
- *bundle_cache_full
|
21
|
+
- *bundle_cache
|
22
|
+
- run: bundle install --path vendor/bundle
|
23
|
+
- save_cache:
|
24
|
+
key: *bundle_cache_full
|
25
|
+
paths:
|
26
|
+
- vendor/bundle
|
27
|
+
run_linters:
|
28
|
+
description: command to start linters
|
29
|
+
steps:
|
30
|
+
- run:
|
31
|
+
name: rubocop
|
32
|
+
command: bundle exec rubocop
|
33
|
+
run_specs:
|
34
|
+
steps:
|
35
|
+
- run:
|
36
|
+
name: run specs
|
37
|
+
command: |
|
38
|
+
bundle exec rspec --format progress \
|
39
|
+
--format RspecJunitFormatter \
|
40
|
+
--out /tmp/test-results/rspec/rspec.xml
|
41
|
+
when: always
|
42
|
+
- store_test_results:
|
43
|
+
path: /tmp/test-results/rspec/
|
44
|
+
jobs:
|
45
|
+
lintering:
|
46
|
+
executor: default
|
47
|
+
steps:
|
48
|
+
- defaults
|
49
|
+
- run_linters
|
50
|
+
run_specs:
|
51
|
+
executor: default
|
52
|
+
steps:
|
53
|
+
- defaults
|
54
|
+
- run_specs
|
55
|
+
|
56
|
+
workflows:
|
57
|
+
version: 2.1
|
58
|
+
build:
|
59
|
+
jobs:
|
60
|
+
- lintering
|
61
|
+
- run_specs:
|
62
|
+
requires:
|
63
|
+
- lintering
|
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/.overcommit.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PreCommit:
|
2
|
+
RuboCop:
|
3
|
+
enabled: true
|
4
|
+
on_warn: warn
|
5
|
+
required: true
|
6
|
+
|
7
|
+
Fasterer:
|
8
|
+
enabled: true
|
9
|
+
on_warn: warn
|
10
|
+
required: true
|
11
|
+
|
12
|
+
CommitMsg:
|
13
|
+
CapitalizedSubject:
|
14
|
+
enabled: true
|
15
|
+
on_warn: fail
|
16
|
+
|
17
|
+
TrailingPeriod:
|
18
|
+
enabled: true
|
19
|
+
on_warn: fail
|
20
|
+
|
21
|
+
TextWidth:
|
22
|
+
enabled: true
|
23
|
+
on_warn: fail
|
24
|
+
|
25
|
+
SingleLineSubject:
|
26
|
+
enabled: true
|
27
|
+
on_warn: fail
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
Metrics/BlockLength:
|
4
|
+
ExcludedMethods: ['describe', 'context']
|
5
|
+
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Layout/SpaceAroundMethodCallOperator:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Lint/DeprecatedOpenSSLConstant:
|
16
|
+
Enabled: true
|
17
|
+
|
18
|
+
Lint/RaiseException:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Lint/StructNewOverride:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Style/ExponentialNotation:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Style/HashEachMethods:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Style/HashTransformKeys:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Style/HashTransformValues:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Style/SlicingWithRange:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Lint/MixedRegexpCaptureTypes:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Style/RedundantRegexpCharacterClass:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Style/RedundantRegexpEscape:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/AccessorGrouping:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Style/BisectedAttrAccessor:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Style/RedundantAssignment:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
Style/RedundantFetchBlock:
|
58
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
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 vitaliy@vivino.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,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker_vk_vitaliy (0.1.0)
|
5
|
+
faker (~> 2.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.1)
|
11
|
+
coderay (1.1.3)
|
12
|
+
colorize (0.8.1)
|
13
|
+
concurrent-ruby (1.1.6)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
docile (1.3.2)
|
16
|
+
faker (2.13.0)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
fasterer (0.8.3)
|
19
|
+
colorize (~> 0.7)
|
20
|
+
ruby_parser (>= 3.14.1)
|
21
|
+
i18n (1.8.3)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
method_source (1.0.0)
|
24
|
+
parallel (1.19.2)
|
25
|
+
parser (2.7.1.4)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
pry (0.13.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rainbow (3.0.0)
|
31
|
+
rake (13.0.1)
|
32
|
+
regexp_parser (1.7.1)
|
33
|
+
rexml (3.2.4)
|
34
|
+
rspec (3.9.0)
|
35
|
+
rspec-core (~> 3.9.0)
|
36
|
+
rspec-expectations (~> 3.9.0)
|
37
|
+
rspec-mocks (~> 3.9.0)
|
38
|
+
rspec-core (3.9.2)
|
39
|
+
rspec-support (~> 3.9.3)
|
40
|
+
rspec-expectations (3.9.2)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-mocks (3.9.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.9.0)
|
46
|
+
rspec-support (3.9.3)
|
47
|
+
rspec_junit_formatter (0.4.1)
|
48
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
49
|
+
rubocop (0.87.1)
|
50
|
+
parallel (~> 1.10)
|
51
|
+
parser (>= 2.7.1.1)
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
regexp_parser (>= 1.7)
|
54
|
+
rexml
|
55
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
58
|
+
rubocop-ast (0.1.0)
|
59
|
+
parser (>= 2.7.0.1)
|
60
|
+
rubocop-rspec (1.42.0)
|
61
|
+
rubocop (>= 0.87.0)
|
62
|
+
ruby-progressbar (1.10.1)
|
63
|
+
ruby_parser (3.14.2)
|
64
|
+
sexp_processor (~> 4.9)
|
65
|
+
sexp_processor (4.15.0)
|
66
|
+
simplecov (0.18.5)
|
67
|
+
docile (~> 1.1)
|
68
|
+
simplecov-html (~> 0.11)
|
69
|
+
simplecov-html (0.12.2)
|
70
|
+
unicode-display_width (1.7.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
codebreaker_vk_vitaliy!
|
77
|
+
fasterer (~> 0.8.3)
|
78
|
+
pry (~> 0.13.1)
|
79
|
+
rake (~> 13.0, >= 13.0.1)
|
80
|
+
rspec (~> 3.9)
|
81
|
+
rspec_junit_formatter (~> 0.4.1)
|
82
|
+
rubocop (~> 0.87.1)
|
83
|
+
rubocop-rspec (~> 1.42)
|
84
|
+
simplecov (~> 0.18.5)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Vitaliy Kashchin
|
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.required_ruby_version = Gem::Requirement.new('>= 2.6.6')
|
7
|
+
|
8
|
+
spec.name = 'codebreaker_vk_vitaliy'
|
9
|
+
spec.version = Codebreaker::VERSION
|
10
|
+
spec.summary = 'Codebreaker game through user interaction'
|
11
|
+
spec.authors = ['Vitaliy Kashchin']
|
12
|
+
spec.email = 'vk.vital@gmail.com'
|
13
|
+
spec.homepage = 'https://github.com/vitalyk/codebreaker_vk_vitaliy'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.require_paths = 'lib'
|
16
|
+
|
17
|
+
spec.add_dependency 'faker', '~> 2.13'
|
18
|
+
|
19
|
+
spec.add_development_dependency 'fasterer', '~> 0.8.3'
|
20
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
21
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
23
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.87.1'
|
25
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.42'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
errors:
|
4
|
+
difficulty: 'Wrong difficulty!'
|
5
|
+
guess:
|
6
|
+
length: "guess should have %{length} digits length"
|
7
|
+
range: "each guess digit is allowed in #{range} range inclusively"
|
8
|
+
player:
|
9
|
+
blank_name: 'name cannot be blank'
|
10
|
+
non_string_name: 'name should be a string'
|
11
|
+
min_length_name: "min name length is %{length}"
|
12
|
+
max_length_name: "max name length is %{length}"
|
data/lib/codebreaker.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'yaml/store'
|
5
|
+
require 'faker'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
require 'codebreaker/statistics'
|
9
|
+
require 'codebreaker/storage_wrapper'
|
10
|
+
require 'codebreaker/difficulty'
|
11
|
+
require 'codebreaker/guess'
|
12
|
+
require 'codebreaker/player'
|
13
|
+
require 'codebreaker/game'
|
14
|
+
require 'codebreaker/version'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Difficulty
|
5
|
+
LEVELS = { easy: { name: :easy, attempts: 15, hints: 2 },
|
6
|
+
medium: { name: :medium, attempts: 10, hints: 1 },
|
7
|
+
hell: { name: :hell, attempts: 5, hints: 1 } }.freeze
|
8
|
+
|
9
|
+
attr_reader :level, :errors
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@level = LEVELS.fetch(name&.to_sym) { nil }
|
13
|
+
@errors = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid?
|
17
|
+
assert
|
18
|
+
errors.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def assert
|
24
|
+
errors << I18n.t(:'errors.difficulty') if @level.nil?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Game
|
5
|
+
SECRET_CODE_LENGTH = 4
|
6
|
+
SECRET_CODE_RANGE = (1..6).freeze
|
7
|
+
EXACT_MATCH_SIGN = '1'
|
8
|
+
NOT_EXACT_MATCH_SIGN = '0'
|
9
|
+
|
10
|
+
attr_reader :player, :difficulty, :secret_number, :hints_used, :attempts_used, :hints_left, :attempts_left, :hints
|
11
|
+
|
12
|
+
def initialize(player, difficulty)
|
13
|
+
@player = player
|
14
|
+
@difficulty = difficulty.level
|
15
|
+
@secret_number = code_maker
|
16
|
+
assign_hints
|
17
|
+
@hints_used = 0
|
18
|
+
@attempts_used = 0
|
19
|
+
@hints_left = @difficulty[:hints]
|
20
|
+
@attempts_left = @difficulty[:attempts]
|
21
|
+
@hints = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def hints_total
|
25
|
+
@difficulty[:hints]
|
26
|
+
end
|
27
|
+
|
28
|
+
def attempts_total
|
29
|
+
@difficulty[:attempts]
|
30
|
+
end
|
31
|
+
|
32
|
+
def attempt
|
33
|
+
@attempts_used += 1
|
34
|
+
@attempts_left -= 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def increment_hint
|
38
|
+
@hints_used += 1
|
39
|
+
@hints_left -= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def hints_available?
|
43
|
+
@hints_used < @difficulty[:hints]
|
44
|
+
end
|
45
|
+
|
46
|
+
def attempts_available?
|
47
|
+
@attempts_used < @difficulty[:attempts]
|
48
|
+
end
|
49
|
+
|
50
|
+
def win?
|
51
|
+
@output == EXACT_MATCH_SIGN * SECRET_CODE_LENGTH
|
52
|
+
end
|
53
|
+
|
54
|
+
def compare(player_number)
|
55
|
+
return EXACT_MATCH_SIGN * SECRET_CODE_LENGTH if win? || !attempts_available?
|
56
|
+
|
57
|
+
attempt
|
58
|
+
compare_numbers(player_number)
|
59
|
+
end
|
60
|
+
|
61
|
+
def hint
|
62
|
+
increment_hint if hints_available?
|
63
|
+
|
64
|
+
value = @assigned_hints.pop
|
65
|
+
@hints << value
|
66
|
+
value
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def assign_hints
|
72
|
+
@assigned_hints = @secret_number.chars.shuffle.sample(difficulty[:hints])
|
73
|
+
end
|
74
|
+
|
75
|
+
def code_maker
|
76
|
+
Array.new(SECRET_CODE_LENGTH) { rand(SECRET_CODE_RANGE) }.join.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def compare_numbers(player_number)
|
80
|
+
secret_digits = @secret_number.chars
|
81
|
+
player_digits = player_number.chars
|
82
|
+
@output = strong_match(secret_digits, player_digits)
|
83
|
+
@output += not_strong_match(secret_digits, player_digits)
|
84
|
+
end
|
85
|
+
|
86
|
+
def strong_match(secret_digits, player_digits)
|
87
|
+
output = ''
|
88
|
+
secret_digits.each_with_index do |digit, index|
|
89
|
+
next unless digit == player_digits[index]
|
90
|
+
|
91
|
+
output += EXACT_MATCH_SIGN
|
92
|
+
secret_digits[index] = nil
|
93
|
+
player_digits[index] = nil
|
94
|
+
end
|
95
|
+
output
|
96
|
+
end
|
97
|
+
|
98
|
+
def not_strong_match(secret_digits, player_digits)
|
99
|
+
output = ''
|
100
|
+
secret_digits.each do |digit|
|
101
|
+
next unless digit && player_digits.include?(digit)
|
102
|
+
|
103
|
+
output += NOT_EXACT_MATCH_SIGN
|
104
|
+
player_digits.delete_at(player_digits.index(digit))
|
105
|
+
end
|
106
|
+
output
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Guess
|
5
|
+
attr_reader :value, :errors
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
@errors = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
assert
|
14
|
+
errors.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.decorate(value, strict_match = '+', soft_match = '-')
|
18
|
+
value.gsub(Codebreaker::Game::EXACT_MATCH_SIGN, strict_match)
|
19
|
+
.gsub(Codebreaker::Game::NOT_EXACT_MATCH_SIGN, soft_match)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def assert
|
25
|
+
validate_length
|
26
|
+
validate_range if errors.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_length
|
30
|
+
error_message = I18n.t(:'errors.guess.length', length: Game::SECRET_CODE_LENGTH)
|
31
|
+
errors << error_message unless @value.to_s.chars.length == Game::SECRET_CODE_LENGTH
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_range
|
35
|
+
error_message = I18n.t(:'errors.guess.range', range: Game::SECRET_CODE_RANGE)
|
36
|
+
allowed_range = Game::SECRET_CODE_RANGE.to_a
|
37
|
+
is_valid_range = @value.to_s.chars.map(&:to_i).all? { |n| allowed_range.include? n }
|
38
|
+
errors << error_message unless is_valid_range
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Player
|
5
|
+
NAME_LENGTH_RANGE = (3..20).freeze
|
6
|
+
|
7
|
+
attr_reader :name, :created_at, :errors
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
@created_at = DateTime.now
|
12
|
+
@errors = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
assert
|
17
|
+
errors.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def assert
|
23
|
+
validate_not_empty
|
24
|
+
validate_string if errors.empty?
|
25
|
+
validate_min_length if errors.empty?
|
26
|
+
validate_max_length if errors.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_not_empty
|
30
|
+
errors << I18n.t(:'errors.player.blank_name') if name.to_s.strip.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_string
|
34
|
+
errors << I18n.t(:'errors.player.non_string_name') unless !!(name =~ /\A[a-zA-Z_0-9]+\z/)
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_min_length
|
38
|
+
min_length = NAME_LENGTH_RANGE.min
|
39
|
+
errors << I18n.t(:'errors.player.min_length_name', length: min_length) if name.length < min_length
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate_max_length
|
43
|
+
max_length = NAME_LENGTH_RANGE.max
|
44
|
+
errors << I18n.t(:'errors.player.max_length_name', length: max_length) if name.length > max_length
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class Statistics
|
5
|
+
class << self
|
6
|
+
def sorted_winners(winners)
|
7
|
+
winners.sort_by do |winner|
|
8
|
+
[winner.difficulty[:attempts], winner.difficulty[:hints],
|
9
|
+
winner.attempts_used, winner.hints_used]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def decorated_top_players(game_plays)
|
14
|
+
game_plays.map.with_index do |game, index|
|
15
|
+
{ rating: index + 1, name: game.player.name, difficulty: game.difficulty[:name],
|
16
|
+
attempts_total: game.attempts_total, attempts_used: game.attempts_used,
|
17
|
+
hints_total: game.hints_total, hints_used: game.hints_used, date: game.player.created_at }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
class StorageWrapper
|
5
|
+
attr_reader :storage_file
|
6
|
+
|
7
|
+
def initialize(storage_file = 'statistics.yml')
|
8
|
+
@storage_file = storage_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_store
|
12
|
+
YAML::Store.new(storage_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def storage_exists?
|
16
|
+
File.exist? storage_file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker_vk_vitaliy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitaliy Kashchin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faker
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fasterer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 13.0.1
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '13.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 13.0.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.9'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.9'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec_junit_formatter
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.4.1
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.4.1
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.87.1
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.87.1
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop-rspec
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '1.42'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '1.42'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: simplecov
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.18.5
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.18.5
|
145
|
+
description:
|
146
|
+
email: vk.vital@gmail.com
|
147
|
+
executables: []
|
148
|
+
extensions: []
|
149
|
+
extra_rdoc_files: []
|
150
|
+
files:
|
151
|
+
- ".circleci/config.yml"
|
152
|
+
- ".fasterer.yml"
|
153
|
+
- ".gitignore"
|
154
|
+
- ".overcommit.yml"
|
155
|
+
- ".rspec"
|
156
|
+
- ".rubocop.yml"
|
157
|
+
- ".ruby-version"
|
158
|
+
- ".travis.yml"
|
159
|
+
- CODE_OF_CONDUCT.md
|
160
|
+
- Gemfile
|
161
|
+
- Gemfile.lock
|
162
|
+
- LICENSE.txt
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- bin/console
|
166
|
+
- bin/setup
|
167
|
+
- codebreaker.gemspec
|
168
|
+
- config/locales/en.yml
|
169
|
+
- lib/codebreaker.rb
|
170
|
+
- lib/codebreaker/difficulty.rb
|
171
|
+
- lib/codebreaker/game.rb
|
172
|
+
- lib/codebreaker/guess.rb
|
173
|
+
- lib/codebreaker/player.rb
|
174
|
+
- lib/codebreaker/statistics.rb
|
175
|
+
- lib/codebreaker/storage_wrapper.rb
|
176
|
+
- lib/codebreaker/version.rb
|
177
|
+
homepage: https://github.com/vitalyk/codebreaker_vk_vitaliy
|
178
|
+
licenses:
|
179
|
+
- MIT
|
180
|
+
metadata: {}
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 2.6.6
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubygems_version: 3.1.2
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Codebreaker game through user interaction
|
200
|
+
test_files: []
|