codebreaker_diz 0.1.2
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 +28 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +4 -0
- data/autotest.sh +65 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codebreaker_diz.gemspec +46 -0
- data/lib/codebreaker_diz.rb +4 -0
- data/lib/codebreaker_diz/config.rb +14 -0
- data/lib/codebreaker_diz/game.rb +129 -0
- data/lib/codebreaker_diz/version.rb +5 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5776f239b86da1fae9144099edf66640b13d65a4095d11839633ac3c1559c82d
|
4
|
+
data.tar.gz: 8f7fce024e2706fad7396de4934f8178fe28299667c4e66018e1e39cf119dd82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35cb186d0fbabfefda9e1391d58bf2a733fc5410f3dbb55e56b2a72c19708c62454e1b8a5717fab8b913e6fcb49239cb5b0e13e12b43bbeeb61d2e05f500a05b
|
7
|
+
data.tar.gz: 105bb6670197d51213bf51e449a5223383f4d0c948f50dc2b3c7c87bfda4dabf94de188d09c456ce7cfa3be2abf77ad581c7da5591ade4d73e27723948456539
|
@@ -0,0 +1,28 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
test:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.5.5
|
6
|
+
steps:
|
7
|
+
- checkout
|
8
|
+
- run:
|
9
|
+
name: Bundle installation
|
10
|
+
command: gem install bundler
|
11
|
+
- run:
|
12
|
+
name: Dependencies installation
|
13
|
+
command: bundle check || bundle install
|
14
|
+
- run:
|
15
|
+
name: Check with rubocop
|
16
|
+
command: bundle exec rubocop
|
17
|
+
- run:
|
18
|
+
name: Check with fasterer
|
19
|
+
command: bundle exec fasterer
|
20
|
+
- run:
|
21
|
+
name: Check with rspec
|
22
|
+
command: bundle exec rspec
|
23
|
+
workflows:
|
24
|
+
version: 2
|
25
|
+
build_and_test:
|
26
|
+
jobs:
|
27
|
+
- test
|
28
|
+
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'node_modules/**/*'
|
4
|
+
- 'vendor/**/*'
|
5
|
+
- '.git/**/*'
|
6
|
+
- 'spec/**/*'
|
7
|
+
- 'test/**/*'
|
8
|
+
- 'bin/**/*'
|
9
|
+
- 'codebreaker_diz.gemspec'
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Description: 'Document classes and non-namespace modules.'
|
13
|
+
Enabled: false
|
14
|
+
VersionAdded: '0.9'
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
codebreaker_diz
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.5
|
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 temaflash96@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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker_diz (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
colorize (0.8.1)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
fasterer (0.5.1)
|
13
|
+
colorize (~> 0.7)
|
14
|
+
ruby_parser (>= 3.13.0)
|
15
|
+
jaro_winkler (1.5.2)
|
16
|
+
parallel (1.17.0)
|
17
|
+
parser (2.6.3.0)
|
18
|
+
ast (~> 2.4.0)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.8.0)
|
22
|
+
rspec-core (~> 3.8.0)
|
23
|
+
rspec-expectations (~> 3.8.0)
|
24
|
+
rspec-mocks (~> 3.8.0)
|
25
|
+
rspec-core (3.8.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-expectations (3.8.3)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-mocks (3.8.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-support (3.8.0)
|
34
|
+
rubocop (0.69.0)
|
35
|
+
jaro_winkler (~> 1.5.1)
|
36
|
+
parallel (~> 1.10)
|
37
|
+
parser (>= 2.6)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
41
|
+
ruby-progressbar (1.10.0)
|
42
|
+
ruby_parser (3.13.1)
|
43
|
+
sexp_processor (~> 4.9)
|
44
|
+
sexp_processor (4.12.0)
|
45
|
+
unicode-display_width (1.6.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 2.0)
|
52
|
+
codebreaker_diz!
|
53
|
+
fasterer (~> 0.5.1)
|
54
|
+
rake (~> 10.0)
|
55
|
+
rspec (~> 3.8)
|
56
|
+
rubocop (~> 0.69.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 bl0rch1d
|
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,43 @@
|
|
1
|
+
# CodebreakerDiz
|
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_diz`. 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_diz'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install codebreaker_diz
|
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. 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_diz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the CodebreakerDiz project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker_diz/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/autotest.sh
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#===============================================================================
|
3
|
+
# FILE: autotest.sh
|
4
|
+
#
|
5
|
+
# USAGE: ./autotest.sh
|
6
|
+
#
|
7
|
+
# DESCRIPTION: Automated ruby code checker and spec runner. Just add this
|
8
|
+
# file to your ruby project folder and run.
|
9
|
+
#
|
10
|
+
# OPTIONS: You can add/remove gems if you wish.
|
11
|
+
#
|
12
|
+
# AUTHOR: bl0rch1d
|
13
|
+
# VERSION: 0.2.0
|
14
|
+
#===============================================================================
|
15
|
+
|
16
|
+
|
17
|
+
FILES_TO_WATCH='./**/**/*'
|
18
|
+
|
19
|
+
current_files_hash=()
|
20
|
+
new_files_hash=()
|
21
|
+
|
22
|
+
get_mdsum() {
|
23
|
+
sudo md5sum $1
|
24
|
+
}
|
25
|
+
|
26
|
+
collect_hashes(){
|
27
|
+
local ary=()
|
28
|
+
|
29
|
+
for file in $FILES_TO_WATCH; do
|
30
|
+
local ary+=($(get_mdsum $file))
|
31
|
+
done
|
32
|
+
|
33
|
+
eval $1="'${ary[@]}'"
|
34
|
+
}
|
35
|
+
|
36
|
+
start(){
|
37
|
+
while true; do
|
38
|
+
collect_hashes current_files_hash
|
39
|
+
|
40
|
+
while true; do
|
41
|
+
collect_hashes new_files_hash
|
42
|
+
|
43
|
+
if [ "${current_files_hash[*]}" != "${new_files_hash[*]}" ]; then
|
44
|
+
|
45
|
+
echo "========== FASTERER =========="
|
46
|
+
bundle exec fasterer
|
47
|
+
|
48
|
+
echo "========== RUBOCOP =========="
|
49
|
+
bundle exec rubocop
|
50
|
+
|
51
|
+
echo "=========== RSPEC ==========="
|
52
|
+
bundle exec rspec
|
53
|
+
|
54
|
+
# Add more gems here
|
55
|
+
# Example: bundle exec <gemname>
|
56
|
+
|
57
|
+
break
|
58
|
+
fi
|
59
|
+
|
60
|
+
sleep 1
|
61
|
+
done
|
62
|
+
done
|
63
|
+
}
|
64
|
+
|
65
|
+
start
|
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_diz'
|
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
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'codebreaker_diz/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'codebreaker_diz'
|
9
|
+
spec.version = CodebreakerDiz::VERSION
|
10
|
+
spec.authors = ['bl0rch1d']
|
11
|
+
spec.email = ['temaflash96@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Codebreaker game.'
|
14
|
+
spec.description = "'Game for true Hackers'"
|
15
|
+
spec.homepage = 'https://github.com/bl0rch1d/codebreaker_diz'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
22
|
+
|
23
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
24
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
25
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
26
|
+
else
|
27
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
28
|
+
"public gem pushes."
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
spec.required_ruby_version = '>= 2.5.5'
|
40
|
+
|
41
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
42
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
43
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
44
|
+
spec.add_development_dependency 'rubocop', '~> 0.69.0'
|
45
|
+
spec.add_development_dependency 'fasterer', '~> 0.5.1'
|
46
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'config'
|
4
|
+
|
5
|
+
module CodebreakerDiz
|
6
|
+
class Game
|
7
|
+
attr_reader :summary, :tries_count, :hints_count
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
set_default_difficulty
|
11
|
+
end
|
12
|
+
|
13
|
+
def difficulty(value)
|
14
|
+
raise ArgumentError unless DIFFICULTIES.include? value.to_sym
|
15
|
+
|
16
|
+
@difficulty = value.to_sym
|
17
|
+
@difficulty_data = DIFFICULTIES[value.to_sym]
|
18
|
+
end
|
19
|
+
|
20
|
+
def prepare_data
|
21
|
+
@hints = (0...CODE_LENGTH).to_a
|
22
|
+
@code = Array.new(CODE_LENGTH) { rand(MIN..MAX) }
|
23
|
+
@tries_count = @difficulty_data[:tries]
|
24
|
+
@hints_count = @difficulty_data[:hints]
|
25
|
+
|
26
|
+
create_summary_container
|
27
|
+
end
|
28
|
+
|
29
|
+
def jsonify
|
30
|
+
@summary.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_guess(input)
|
34
|
+
input = to_array(input)
|
35
|
+
|
36
|
+
return update_summary(:guess_result, 'no tries left') if lose?
|
37
|
+
|
38
|
+
return update_summary(:guess_result, 'wrong format') unless valid? input
|
39
|
+
|
40
|
+
make_results calculate_matches(input)
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_hint
|
44
|
+
return update_summary(:hint, 'no hints left') if @hints_count.zero?
|
45
|
+
|
46
|
+
index = @hints.sample
|
47
|
+
|
48
|
+
hint = @code[index]
|
49
|
+
|
50
|
+
@hints.delete index
|
51
|
+
|
52
|
+
@hints_count -= 1
|
53
|
+
|
54
|
+
update_summary :hints_used, :increase
|
55
|
+
update_summary :hint, hint
|
56
|
+
end
|
57
|
+
|
58
|
+
def win?
|
59
|
+
@summary[:guess_result] == Array.new(CODE_LENGTH, '+').join
|
60
|
+
end
|
61
|
+
|
62
|
+
def lose?
|
63
|
+
@tries_count.zero?
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def update_summary(key, value)
|
69
|
+
return ArgumentError unless @summary.include? key
|
70
|
+
|
71
|
+
case value
|
72
|
+
when :increase
|
73
|
+
@summary[key] += 1
|
74
|
+
else
|
75
|
+
@summary[key] = value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_default_difficulty
|
80
|
+
@difficulty = :kid
|
81
|
+
@difficulty_data = DIFFICULTIES[@difficulty]
|
82
|
+
end
|
83
|
+
|
84
|
+
def calculate_matches(user_code)
|
85
|
+
delta = []
|
86
|
+
result = []
|
87
|
+
|
88
|
+
(0...CODE_LENGTH).each do |i|
|
89
|
+
if @code[i] == user_code[i] then result << '+'
|
90
|
+
elsif (@code - delta).include? user_code[i] then result << '-'
|
91
|
+
end
|
92
|
+
|
93
|
+
delta << user_code[i]
|
94
|
+
end
|
95
|
+
|
96
|
+
result.sort!.join
|
97
|
+
end
|
98
|
+
|
99
|
+
def make_results(guess_result)
|
100
|
+
@tries_count -= 1
|
101
|
+
|
102
|
+
update_summary :tries_used, :increase
|
103
|
+
update_summary :guess_result, guess_result
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_array(input)
|
107
|
+
input.to_i.digits.reverse
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_summary_container
|
111
|
+
@summary = {
|
112
|
+
secret: @code,
|
113
|
+
difficulty: DIFFICULTIES.keys.index(@difficulty),
|
114
|
+
tries_total: @tries_count,
|
115
|
+
hints_total: @hints_count,
|
116
|
+
tries_used: 0,
|
117
|
+
hints_used: 0,
|
118
|
+
guess_result: nil,
|
119
|
+
hint: nil
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def valid?(input)
|
124
|
+
input != 0 && input.size == CODE_LENGTH && input.all? do |number|
|
125
|
+
number.between? MIN, MAX
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker_diz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bl0rch1d
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-28 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.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.69.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.69.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fasterer
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.5.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.5.1
|
83
|
+
description: "'Game for true Hackers'"
|
84
|
+
email:
|
85
|
+
- temaflash96@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".circleci/config.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".ruby-gemset"
|
95
|
+
- ".ruby-version"
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- autotest.sh
|
103
|
+
- bin/console
|
104
|
+
- bin/setup
|
105
|
+
- codebreaker_diz.gemspec
|
106
|
+
- lib/codebreaker_diz.rb
|
107
|
+
- lib/codebreaker_diz/config.rb
|
108
|
+
- lib/codebreaker_diz/game.rb
|
109
|
+
- lib/codebreaker_diz/version.rb
|
110
|
+
homepage: https://github.com/bl0rch1d/codebreaker_diz
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
allowed_push_host: https://rubygems.org
|
115
|
+
homepage_uri: https://github.com/bl0rch1d/codebreaker_diz
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.5.5
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.0.3
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Codebreaker game.
|
135
|
+
test_files: []
|