codebreaker_game 0.1.0
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 +76 -0
- data/.fasterer.yml +23 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codebreaker_game.gemspec +39 -0
- data/lib/codebreaker_game.rb +127 -0
- data/lib/codebreaker_game/entities/difficulty.rb +11 -0
- data/lib/codebreaker_game/entities/difficulty_factory.rb +17 -0
- data/lib/codebreaker_game/entities/user.rb +50 -0
- data/lib/codebreaker_game/errors/wrong_difficulty_error.rb +4 -0
- data/lib/codebreaker_game/random.rb +25 -0
- data/lib/codebreaker_game/storage.rb +17 -0
- data/lib/codebreaker_game/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8868a9b0d999b99507f556efea58e1080a2e42141adbeac51cf847c3c1f32533
|
4
|
+
data.tar.gz: 8e1164d7133e1fe88f074af6efbbb84b83f5f7930eb86aadcd142ea484ed7609
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc66b24c524fde5a1c51399de7372cdbc673c2f56c34495aa6cce765312512c89faff00f1d956eb2d380341d456c7be00a131fad4429857c06b86da28f86bb28
|
7
|
+
data.tar.gz: 745569746ec95659028c5861287850c7f16814bae6f0453c7d442bb73bb84ee143336f5138370d907f5b27bf0e8726b432771975176ee9d82cfd2a161b59ea4e
|
@@ -0,0 +1,76 @@
|
|
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.6.1
|
9
|
+
environment:
|
10
|
+
RAILS_ENV: test
|
11
|
+
|
12
|
+
caches:
|
13
|
+
- &bundle_cache v2-repo-{{ checksum "Gemfile.lock" }}
|
14
|
+
|
15
|
+
commands:
|
16
|
+
update_bundler:
|
17
|
+
steps:
|
18
|
+
- run:
|
19
|
+
name: install dependencies
|
20
|
+
command: |
|
21
|
+
gem update --system
|
22
|
+
gem install bundler
|
23
|
+
run_linters:
|
24
|
+
description: command to start linters
|
25
|
+
steps:
|
26
|
+
- run:
|
27
|
+
name: rubocop
|
28
|
+
command: bundle exec rubocop
|
29
|
+
- run:
|
30
|
+
name: fasterer
|
31
|
+
command: bundle exec fasterer
|
32
|
+
|
33
|
+
run_specs:
|
34
|
+
steps:
|
35
|
+
- run:
|
36
|
+
name: run specs
|
37
|
+
command: |
|
38
|
+
mkdir /tmp/test-results
|
39
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
40
|
+
bundle exec rspec --format progress \
|
41
|
+
--out /tmp/test-results/rspec.xml \
|
42
|
+
$TEST_FILES
|
43
|
+
setup_environment:
|
44
|
+
steps:
|
45
|
+
- checkout
|
46
|
+
- restore_cache:
|
47
|
+
key: *bundle_cache
|
48
|
+
- run:
|
49
|
+
command: |
|
50
|
+
gem update --system
|
51
|
+
gem install bundler
|
52
|
+
bundle install --path vendor/bundle
|
53
|
+
- save_cache:
|
54
|
+
key: *bundle_cache
|
55
|
+
paths:
|
56
|
+
- vendor/bundle
|
57
|
+
jobs:
|
58
|
+
lintering:
|
59
|
+
executor: default
|
60
|
+
steps:
|
61
|
+
- setup_environment
|
62
|
+
- run_linters
|
63
|
+
run_specs:
|
64
|
+
executor: default
|
65
|
+
steps:
|
66
|
+
- setup_environment
|
67
|
+
- run_specs
|
68
|
+
|
69
|
+
workflows:
|
70
|
+
version: 2.1
|
71
|
+
build:
|
72
|
+
jobs:
|
73
|
+
- lintering
|
74
|
+
- run_specs:
|
75
|
+
requires:
|
76
|
+
- lintering
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
+
|
21
|
+
exclude_paths:
|
22
|
+
- 'storage'
|
23
|
+
- 'vendor/**/*.rb'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker_game (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
|
+
docile (1.1.5)
|
13
|
+
fasterer (0.8.1)
|
14
|
+
colorize (~> 0.7)
|
15
|
+
ruby_parser (>= 3.14.1)
|
16
|
+
jaro_winkler (1.5.4)
|
17
|
+
json (2.2.0)
|
18
|
+
parallel (1.19.1)
|
19
|
+
parser (2.6.5.0)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-expectations (3.9.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.0)
|
36
|
+
rubocop (0.77.0)
|
37
|
+
jaro_winkler (~> 1.5.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.6)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
43
|
+
ruby-progressbar (1.10.1)
|
44
|
+
ruby_parser (3.14.1)
|
45
|
+
sexp_processor (~> 4.9)
|
46
|
+
sexp_processor (4.13.0)
|
47
|
+
simplecov (0.12.0)
|
48
|
+
docile (~> 1.1.0)
|
49
|
+
json (>= 1.8, < 3)
|
50
|
+
simplecov-html (~> 0.10.0)
|
51
|
+
simplecov-html (0.10.2)
|
52
|
+
unicode-display_width (1.6.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 2.0)
|
59
|
+
codebreaker_game!
|
60
|
+
fasterer
|
61
|
+
rake (~> 10.0)
|
62
|
+
rspec (~> 3.0)
|
63
|
+
rubocop
|
64
|
+
simplecov (~> 0.12.0)
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Michael
|
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,39 @@
|
|
1
|
+
# CodebreakerGame
|
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_game`. 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_game'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install codebreaker_game
|
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_game.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'codebreaker_game'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'codebreaker_game/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codebreaker_game'
|
7
|
+
spec.version = CodebreakerGame::VERSION
|
8
|
+
spec.authors = ['Michael']
|
9
|
+
spec.email = ['somov.michail.yur@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Test application for RubyGarage.'
|
12
|
+
spec.description = 'Test application for RubyGarage.'
|
13
|
+
spec.homepage = 'https://github.com/maiksimov/codebreaker_game'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
|
+
spec.add_development_dependency 'fasterer'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop'
|
38
|
+
spec.add_development_dependency 'simplecov', '~> 0.12.0'
|
39
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'yaml/store'
|
2
|
+
require 'codebreaker_game/version'
|
3
|
+
require 'codebreaker_game/random'
|
4
|
+
require 'codebreaker_game/storage'
|
5
|
+
require 'codebreaker_game/entities/user'
|
6
|
+
require 'codebreaker_game/entities/difficulty'
|
7
|
+
require 'codebreaker_game/entities/difficulty_factory'
|
8
|
+
require 'codebreaker_game/errors/wrong_difficulty_error'
|
9
|
+
|
10
|
+
module CodebreakerGame
|
11
|
+
class Game
|
12
|
+
include CodebreakerGame::Random
|
13
|
+
extend CodebreakerGame::Storage
|
14
|
+
attr_reader :user
|
15
|
+
|
16
|
+
STATUS_IN_PROGRESS = 'in_process'.freeze
|
17
|
+
STATUS_WIN = 'win'.freeze
|
18
|
+
STATUS_LOSE = 'lose'.freeze
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@secret_number = generate_secret
|
22
|
+
@status = STATUS_IN_PROGRESS
|
23
|
+
@storage = yaml_store
|
24
|
+
@difficulty_factory = CodebreakerGame::DifficultyFactory.new
|
25
|
+
save_storage unless CodebreakerGame::Game.storage_exists?
|
26
|
+
synchronize_storage
|
27
|
+
end
|
28
|
+
|
29
|
+
def win?
|
30
|
+
@status == STATUS_WIN
|
31
|
+
end
|
32
|
+
|
33
|
+
def lose?
|
34
|
+
@status == STATUS_LOSE
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_user(name:, difficulty:)
|
38
|
+
@user = User.new(name, difficulty)
|
39
|
+
@user
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_difficulty(difficulty:)
|
43
|
+
@difficulty_factory.difficulty_by_name(difficulty)
|
44
|
+
end
|
45
|
+
|
46
|
+
def attempt(user_number)
|
47
|
+
return compare(@secret_number, user_number) if user.attempts?
|
48
|
+
|
49
|
+
@status = STATUS_LOSE
|
50
|
+
end
|
51
|
+
|
52
|
+
def sorted_winners
|
53
|
+
@winners.sort_by do |winner|
|
54
|
+
[winner.difficulty.attempts,
|
55
|
+
winner.attempts_used,
|
56
|
+
winner.hints_used]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def hint
|
61
|
+
return 'You have no hints!' unless user.hints?
|
62
|
+
|
63
|
+
user.hint
|
64
|
+
@secret_number.to_s.chars[rand(CodebreakerGame::Random::RANDOM_LENGTH)]
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def win
|
70
|
+
@winners << user
|
71
|
+
save_storage
|
72
|
+
@status = STATUS_WIN
|
73
|
+
end
|
74
|
+
|
75
|
+
def compare(number, number_two)
|
76
|
+
user.attempt
|
77
|
+
compare_numbers(number, number_two)
|
78
|
+
end
|
79
|
+
|
80
|
+
def compare_numbers(number, number_two)
|
81
|
+
secret_digits = number.to_s.chars
|
82
|
+
user_digits = number_two.to_s.chars
|
83
|
+
response = pluses(secret_digits, user_digits)
|
84
|
+
response += minuses(secret_digits, user_digits)
|
85
|
+
win if response == '++++'
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
def pluses(secret_digits, user_digits)
|
90
|
+
response = ''
|
91
|
+
secret_digits.each_with_index do |digit, index|
|
92
|
+
next if digit != user_digits[index]
|
93
|
+
|
94
|
+
response += '+'
|
95
|
+
secret_digits[index] = nil
|
96
|
+
user_digits[index] = nil
|
97
|
+
end
|
98
|
+
response
|
99
|
+
end
|
100
|
+
|
101
|
+
def minuses(secret_digits, user_digits)
|
102
|
+
response = ''
|
103
|
+
secret_digits.each_with_index do |digit, index|
|
104
|
+
next unless digit != user_digits[index] && user_digits.include?(digit)
|
105
|
+
|
106
|
+
response += '-'
|
107
|
+
end
|
108
|
+
response
|
109
|
+
end
|
110
|
+
|
111
|
+
def synchronize_storage
|
112
|
+
@storage.transaction(true) do
|
113
|
+
@winners = @storage[:winners]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def save_storage
|
118
|
+
@storage.transaction do
|
119
|
+
@storage[:winners] = @winners || []
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def yaml_store
|
124
|
+
YAML::Store.new(CodebreakerGame::Game.storage_file)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CodebreakerGame
|
2
|
+
class DifficultyFactory
|
3
|
+
EASY_NAME = 'easy'.freeze
|
4
|
+
MEDIUM_NAME = 'medium'.freeze
|
5
|
+
HARD_NAME = 'hard'.freeze
|
6
|
+
|
7
|
+
def difficulty_by_name(name)
|
8
|
+
case name
|
9
|
+
when EASY_NAME then Difficulty.new(EASY_NAME, 2, 15)
|
10
|
+
when MEDIUM_NAME then Difficulty.new(MEDIUM_NAME, 1, 10)
|
11
|
+
when HARD_NAME then Difficulty.new(HARD_NAME, 1, 5)
|
12
|
+
else
|
13
|
+
raise WrongDifficultyError, 'Wrong difficulty name'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CodebreakerGame
|
2
|
+
class User
|
3
|
+
attr_reader :name, :hints_used, :attempts_used
|
4
|
+
|
5
|
+
def initialize(name, difficulty)
|
6
|
+
@name = name
|
7
|
+
@difficulty = difficulty
|
8
|
+
@hints_used = 0
|
9
|
+
@attempts_used = 0
|
10
|
+
validate
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :difficulty
|
14
|
+
|
15
|
+
def hints_total
|
16
|
+
@difficulty.hints
|
17
|
+
end
|
18
|
+
|
19
|
+
def attempts_total
|
20
|
+
@difficulty.attempts
|
21
|
+
end
|
22
|
+
|
23
|
+
def attempt
|
24
|
+
@attempts_used += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def hint
|
28
|
+
@hints_used += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def hints?
|
32
|
+
@hints_used < @difficulty.hints
|
33
|
+
end
|
34
|
+
|
35
|
+
def attempts?
|
36
|
+
@attempts_used < @difficulty.attempts
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def validate
|
42
|
+
# required?(name)
|
43
|
+
# string?(name)
|
44
|
+
# not_empty?(name)
|
45
|
+
# required?(difficulty)
|
46
|
+
# difficulty?(difficulty)
|
47
|
+
# not_empty?(difficulty)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CodebreakerGame
|
2
|
+
module Random
|
3
|
+
RANDOM_MIN = 1
|
4
|
+
RANDOM_MAX = 6
|
5
|
+
RANDOM_LENGTH = 4
|
6
|
+
|
7
|
+
def generate_secret(length = RANDOM_LENGTH)
|
8
|
+
number = 0
|
9
|
+
length.times do |degree|
|
10
|
+
number += generate_random * order(degree)
|
11
|
+
end
|
12
|
+
number
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def order(degree)
|
18
|
+
10**degree
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_random(min = RANDOM_MIN, max = RANDOM_MAX)
|
22
|
+
rand(min..max)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CodebreakerGame
|
2
|
+
module Storage
|
3
|
+
STAT_FILE = './storage/statistics.yml'.freeze
|
4
|
+
|
5
|
+
def storage_exists?
|
6
|
+
File.exist? STAT_FILE
|
7
|
+
end
|
8
|
+
|
9
|
+
def storage_file
|
10
|
+
STAT_FILE
|
11
|
+
end
|
12
|
+
|
13
|
+
def flush
|
14
|
+
File.delete(STAT_FILE) if storage_exists?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-04 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: fasterer
|
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: '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: '10.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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.12.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.12.0
|
97
|
+
description: Test application for RubyGarage.
|
98
|
+
email:
|
99
|
+
- somov.michail.yur@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".circleci/config.yml"
|
105
|
+
- ".fasterer.yml"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- codebreaker_game.gemspec
|
118
|
+
- lib/codebreaker_game.rb
|
119
|
+
- lib/codebreaker_game/entities/difficulty.rb
|
120
|
+
- lib/codebreaker_game/entities/difficulty_factory.rb
|
121
|
+
- lib/codebreaker_game/entities/user.rb
|
122
|
+
- lib/codebreaker_game/errors/wrong_difficulty_error.rb
|
123
|
+
- lib/codebreaker_game/random.rb
|
124
|
+
- lib/codebreaker_game/storage.rb
|
125
|
+
- lib/codebreaker_game/version.rb
|
126
|
+
homepage: https://github.com/maiksimov/codebreaker_game
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata:
|
130
|
+
homepage_uri: https://github.com/maiksimov/codebreaker_game
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.7.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Test application for RubyGarage.
|
151
|
+
test_files: []
|