codebreaker-ga 0.2.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 +72 -0
- data/.fasterer.yml +20 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +75 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +29 -0
- data/lib/codebreaker/base_class.rb +16 -0
- data/lib/codebreaker/difficulty.rb +12 -0
- data/lib/codebreaker/game.rb +136 -0
- data/lib/codebreaker/game_stage.rb +22 -0
- data/lib/codebreaker/init_difficulties.rb +10 -0
- data/lib/codebreaker/statistic.rb +51 -0
- data/lib/codebreaker/user.rb +18 -0
- data/lib/codebreaker/validator.rb +11 -0
- data/lib/codebreaker/version.rb +3 -0
- data/lib/codebreaker/yaml_file.rb +14 -0
- data/lib/codebreaker.rb +13 -0
- data/pec +211 -0
- data/statistic_test.yml +7 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47b3c2326b29c72f7bd7a6c645483cdfa80e469c25820ac4483019f6d4422811
|
4
|
+
data.tar.gz: 9e9cc4bd377e99cf7ec146079cae74227e8d320efb0e61afca40e2265b8bb80f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba07a0eb1810c6d153b922c7f17ae538dec5b49cc29c38f716dcee6117b77fcf4b28b30186c9556e0cb45986159c7ca9f5f40d1e6064af6f5977ab8bf5bef530
|
7
|
+
data.tar.gz: 8543f7b2884642e7927e64a979eb94631aef9fbda7d24a84eef3f538928b5f8dcd7b67b9256ff0bd31fd09d26dcd75943973af8b8b242afe92de3e41ba8444be
|
@@ -0,0 +1,72 @@
|
|
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.3-node
|
9
|
+
|
10
|
+
caches:
|
11
|
+
- &bundle_cache v1-repo-{{ checksum "Gemfile.lock" }}
|
12
|
+
|
13
|
+
commands:
|
14
|
+
run_linters:
|
15
|
+
description: command to start linters
|
16
|
+
steps:
|
17
|
+
- run:
|
18
|
+
name: rubocop
|
19
|
+
command: bundle exec rubocop
|
20
|
+
- run:
|
21
|
+
name: fasterer
|
22
|
+
command: bundle exec fasterer
|
23
|
+
|
24
|
+
run_specs:
|
25
|
+
steps:
|
26
|
+
- run:
|
27
|
+
name: run specs
|
28
|
+
command: |
|
29
|
+
mkdir /tmp/test-results
|
30
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
31
|
+
bundle exec rspec --format progress \
|
32
|
+
--out /tmp/test-results/rspec.xml \
|
33
|
+
--format progress \
|
34
|
+
$TEST_FILES
|
35
|
+
defaults:
|
36
|
+
steps:
|
37
|
+
- checkout
|
38
|
+
- restore_cache:
|
39
|
+
key: *bundle_cache
|
40
|
+
- run: gem install bundler:2.0.2
|
41
|
+
- run: bundle install
|
42
|
+
- save_cache:
|
43
|
+
key: *bundle_cache
|
44
|
+
paths:
|
45
|
+
- bundle vendor/bundle
|
46
|
+
|
47
|
+
jobs:
|
48
|
+
lintering:
|
49
|
+
executor: default
|
50
|
+
steps:
|
51
|
+
- defaults
|
52
|
+
- run_linters
|
53
|
+
run_specs:
|
54
|
+
executor: default
|
55
|
+
steps:
|
56
|
+
- defaults
|
57
|
+
- run_specs
|
58
|
+
|
59
|
+
workflows:
|
60
|
+
version: 2.1
|
61
|
+
build:
|
62
|
+
jobs:
|
63
|
+
- lintering:
|
64
|
+
filters:
|
65
|
+
branches:
|
66
|
+
only: div
|
67
|
+
- run_specs:
|
68
|
+
filters:
|
69
|
+
branches:
|
70
|
+
only: div
|
71
|
+
requires:
|
72
|
+
- lintering
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
speedups:
|
2
|
+
parallel_assignment: false
|
3
|
+
rescue_vs_respond_to: true
|
4
|
+
module_eval: true
|
5
|
+
shuffle_first_vs_sample: true
|
6
|
+
for_loop_vs_each: true
|
7
|
+
each_with_index_vs_while: false
|
8
|
+
map_flatten_vs_flat_map: true
|
9
|
+
reverse_each_vs_reverse_each: true
|
10
|
+
select_first_vs_detect: true
|
11
|
+
sort_vs_sort_by: true
|
12
|
+
fetch_with_argument_vs_block: true
|
13
|
+
keys_each_vs_each_key: true
|
14
|
+
hash_merge_bang_vs_hash_brackets: true
|
15
|
+
block_vs_symbol_to_proc: true
|
16
|
+
proc_call_vs_yield: true
|
17
|
+
gsub_vs_tr: true
|
18
|
+
select_last_vs_reverse_detect: true
|
19
|
+
getter_vs_attr_reader: true
|
20
|
+
setter_vs_attr_writer: true
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker-ga (0.2.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
colorize (0.8.1)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.3.2)
|
14
|
+
fasterer (0.8.1)
|
15
|
+
colorize (~> 0.7)
|
16
|
+
ruby_parser (>= 3.14.1)
|
17
|
+
jaro_winkler (1.5.4)
|
18
|
+
json (2.3.0)
|
19
|
+
method_source (0.9.2)
|
20
|
+
parallel (1.19.1)
|
21
|
+
parser (2.6.5.0)
|
22
|
+
ast (~> 2.4.0)
|
23
|
+
pry (0.12.2)
|
24
|
+
coderay (~> 1.1.0)
|
25
|
+
method_source (~> 0.9.0)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (12.3.3)
|
28
|
+
rspec (3.9.0)
|
29
|
+
rspec-core (~> 3.9.0)
|
30
|
+
rspec-expectations (~> 3.9.0)
|
31
|
+
rspec-mocks (~> 3.9.0)
|
32
|
+
rspec-core (3.9.0)
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-expectations (3.9.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-mocks (3.9.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-support (3.9.0)
|
41
|
+
rubocop (0.77.0)
|
42
|
+
jaro_winkler (~> 1.5.1)
|
43
|
+
parallel (~> 1.10)
|
44
|
+
parser (>= 2.6)
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
48
|
+
rubocop-rspec (1.37.1)
|
49
|
+
rubocop (>= 0.68.1)
|
50
|
+
ruby-progressbar (1.10.1)
|
51
|
+
ruby_parser (3.14.1)
|
52
|
+
sexp_processor (~> 4.9)
|
53
|
+
sexp_processor (4.13.0)
|
54
|
+
simplecov (0.17.1)
|
55
|
+
docile (~> 1.1)
|
56
|
+
json (>= 1.8, < 3)
|
57
|
+
simplecov-html (~> 0.10.0)
|
58
|
+
simplecov-html (0.10.2)
|
59
|
+
unicode-display_width (1.6.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
bundler (~> 2.0)
|
66
|
+
codebreaker-ga!
|
67
|
+
fasterer (~> 0.8.0)
|
68
|
+
pry (~> 0.12.2)
|
69
|
+
rake (~> 12.3.1)
|
70
|
+
rspec (~> 3.0)
|
71
|
+
rubocop-rspec
|
72
|
+
simplecov
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# CodebreakerGem
|
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
|
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. 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_gem.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'codebreaker'
|
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
data/codebreaker.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'codebreaker/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codebreaker-ga'
|
7
|
+
spec.version = Codebreaker::VERSION
|
8
|
+
spec.authors = ['GorohovAlex']
|
9
|
+
spec.email = ['gorochov.as@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Write a short summary, because RubyGems requires one.'
|
12
|
+
spec.description = 'Write a longer description or delete this line.'
|
13
|
+
spec.homepage = 'https://github.com/GorohovAlex/codebreaker_gem'
|
14
|
+
|
15
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
23
|
+
spec.add_development_dependency 'fasterer', '~> 0.8.0'
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.12.2'
|
25
|
+
spec.add_development_dependency 'rake', '~> 12.3.1'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop-rspec'
|
28
|
+
spec.add_development_dependency 'simplecov'
|
29
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
class CodebreakerGem < BaseClass
|
3
|
+
include InitDifficulties
|
4
|
+
|
5
|
+
CODE_LENGTH = 4
|
6
|
+
CODE_NUMBERS = ('1'..'6').freeze
|
7
|
+
|
8
|
+
attr_reader :statistic, :difficulty, :game_stage, :difficulty_change, :errors
|
9
|
+
attr_accessor :user, :hint_code
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@errors = {}
|
13
|
+
@statistic = Statistic.new
|
14
|
+
@difficulty = init_difficulties
|
15
|
+
end
|
16
|
+
|
17
|
+
def user_code_valid_length?(user_code)
|
18
|
+
return true if validate_length?(user_code, CODE_LENGTH..CODE_LENGTH)
|
19
|
+
|
20
|
+
false || @errors[:user_code] = 'error_user_code_length'
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_user_code_number_range?(user_code)
|
24
|
+
return true if validate_number_range?(user_code, CODE_NUMBERS)
|
25
|
+
|
26
|
+
false || @errors[:user_code] = 'error_user_code_number'
|
27
|
+
end
|
28
|
+
|
29
|
+
def difficulty_change=(difficulty)
|
30
|
+
@difficulty_change = @difficulty.detect { |value| value.name == difficulty }
|
31
|
+
end
|
32
|
+
|
33
|
+
def game_start
|
34
|
+
generate_secret_code
|
35
|
+
generate_hints unless @difficulty_change.nil?
|
36
|
+
@game_stage = GameStage.new(user_code_length: CODE_LENGTH, attempts: @difficulty_change.attempts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def game_step(user_code)
|
40
|
+
return unless user_code_valid?(user_code)
|
41
|
+
|
42
|
+
@user_code_positions = get_code_positions(user_code)
|
43
|
+
@game_stage.step(compare_codes(user_code))
|
44
|
+
@game_stage.compare_result
|
45
|
+
end
|
46
|
+
|
47
|
+
def registration(username)
|
48
|
+
@user = User.new(username)
|
49
|
+
{ status: @user.valid?, value: @user.errors.empty? ? @user.username : @user.errors.first }
|
50
|
+
end
|
51
|
+
|
52
|
+
def hint_show
|
53
|
+
return if @hint_code.empty?
|
54
|
+
|
55
|
+
@game_stage.hint_used += 1
|
56
|
+
@hint_code.shift
|
57
|
+
end
|
58
|
+
|
59
|
+
def statistic_save
|
60
|
+
@statistic.statistic_add_item(name: user.username, difficulty: difficulty_change, game_stage: game_stage)
|
61
|
+
@statistic.statistic_save
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def user_code_valid?(user_code)
|
67
|
+
return unless user_code_valid_length?(user_code)
|
68
|
+
return unless validate_user_code_number_range?(user_code)
|
69
|
+
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def difficulty_valid?
|
74
|
+
return true unless @difficulty_change.nil? || @difficulty_change.empty?
|
75
|
+
|
76
|
+
@errors[:difficulty] = 'difficulty_change_error'
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def compare_codes(user_code)
|
81
|
+
crossing_values = @secret_code & user_code
|
82
|
+
crossing_values.each_with_object([]) { |value, cross_result| cross_result << get_cross_value(value) }
|
83
|
+
.flatten.sort_by { |item| item ? 0 : 1 }
|
84
|
+
end
|
85
|
+
|
86
|
+
def generate_number
|
87
|
+
Array.new(CODE_LENGTH) { CODE_NUMBERS.to_a.sample }
|
88
|
+
end
|
89
|
+
|
90
|
+
def generate_secret_code
|
91
|
+
@secret_code = generate_number
|
92
|
+
@secret_code_positions = get_code_positions(@secret_code)
|
93
|
+
generate_hints
|
94
|
+
end
|
95
|
+
|
96
|
+
def generate_hints
|
97
|
+
@hint_code = @secret_code.nil? ? [] : @secret_code.sample(@difficulty_change.hints)
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_cross_value(value)
|
101
|
+
guess_position(value) + guess_value(value)
|
102
|
+
end
|
103
|
+
|
104
|
+
def guess_position(value)
|
105
|
+
crossing_positions = @user_code_positions[value] & @secret_code_positions[value]
|
106
|
+
crossing_positions.empty? ? [] : Array.new(crossing_positions.size, true)
|
107
|
+
end
|
108
|
+
|
109
|
+
def guess_value(value)
|
110
|
+
crossing_positions = @user_code_positions[value] & @secret_code_positions[value]
|
111
|
+
|
112
|
+
user_code_positions = crossing_code_position(value, @user_code_positions, crossing_positions)
|
113
|
+
secret_code_positions = crossing_code_position(value, @secret_code_positions, crossing_positions)
|
114
|
+
|
115
|
+
size_no_cross_code = [secret_code_positions[value].size, user_code_positions[value].size].min
|
116
|
+
crossing_positions.empty? && size_no_cross_code.zero? ? [] : Array.new(size_no_cross_code, false)
|
117
|
+
end
|
118
|
+
|
119
|
+
def crossing_code_position(value, code_array, crossing_positions)
|
120
|
+
code_positions = code_array.dup
|
121
|
+
code_positions[value] -= crossing_positions
|
122
|
+
code_positions
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_code_positions(code_array)
|
126
|
+
return if code_array.nil? || code_array.empty?
|
127
|
+
|
128
|
+
code_array.each_with_object(Hash.new([])).with_index { |(value, code), index| code[value] += [index] }
|
129
|
+
end
|
130
|
+
|
131
|
+
def validate?
|
132
|
+
@errors = {}
|
133
|
+
difficulty_valid?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
class GameStage
|
3
|
+
attr_reader :step_number, :endgame, :attempts, :compare_result, :win
|
4
|
+
attr_accessor :hint_used
|
5
|
+
|
6
|
+
def initialize(user_code_length:, attempts:)
|
7
|
+
@step_number = 1
|
8
|
+
@endgame = false
|
9
|
+
@attempts = attempts
|
10
|
+
@compare_result = []
|
11
|
+
@user_code_length = user_code_length
|
12
|
+
@hint_used = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def step(compare_result)
|
16
|
+
@compare_result = compare_result
|
17
|
+
@step_number += 1
|
18
|
+
@win = @compare_result.length == @user_code_length && @compare_result.all?
|
19
|
+
@endgame = true if @step_number > @attempts || @win
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
module InitDifficulties
|
3
|
+
def init_difficulties
|
4
|
+
difficulty = []
|
5
|
+
difficulty << Difficulty.new(name: 'Easy', attempts: 15, hints: 2, level: 0)
|
6
|
+
difficulty << Difficulty.new(name: 'Medium', attempts: 10, hints: 1, level: 1)
|
7
|
+
difficulty << Difficulty.new(name: 'Hell', attempts: 5, hints: 1, level: 2)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
class Statistic
|
3
|
+
include YamlFile
|
4
|
+
|
5
|
+
STAT_HEADER_LIST = %w[rating name difficulty attempts_total attempts_used hints_total hints_used].freeze
|
6
|
+
STAT_FILE_PATH = 'statistic.yml'.freeze
|
7
|
+
|
8
|
+
attr_reader :statistic, :headings
|
9
|
+
def initialize
|
10
|
+
@headings = STAT_HEADER_LIST
|
11
|
+
@statistic_items = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def statistic_get
|
15
|
+
statistic_load
|
16
|
+
statistic_sort
|
17
|
+
@statistic_items.each_with_index.map do |stat, index|
|
18
|
+
[index.next, stat[:name], stat[:difficulty], stat[:attempts_total],
|
19
|
+
stat[:attempts_used], stat[:hints_total], stat[:hints_used]]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def statistic_add_item(name:, difficulty:, game_stage:)
|
24
|
+
@statistic_items << { name: name,
|
25
|
+
difficulty: difficulty.name,
|
26
|
+
attempts_total: game_stage.attempts,
|
27
|
+
attempts_used: game_stage.step_number,
|
28
|
+
hints_total: difficulty.hints,
|
29
|
+
hints_used: game_stage.hint_used }
|
30
|
+
end
|
31
|
+
|
32
|
+
def statistic_save
|
33
|
+
YamlFile.save(STAT_FILE_PATH, @statistic_items)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def statistic_load
|
39
|
+
return unless File.file?(STAT_FILE_PATH) && File.size(STAT_FILE_PATH).positive?
|
40
|
+
|
41
|
+
@statistic_items = YamlFile.load(STAT_FILE_PATH)
|
42
|
+
end
|
43
|
+
|
44
|
+
def statistic_sort
|
45
|
+
@statistic_items.sort_by! do |stat|
|
46
|
+
[stat[:attempts_total] + stat[:hints_total],
|
47
|
+
stat[:attempts_used], stat[:hints_used]]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
class User < BaseClass
|
3
|
+
USERNAME_LENGTH_RANGE = (3..20).freeze
|
4
|
+
|
5
|
+
attr_reader :username, :errors
|
6
|
+
|
7
|
+
def initialize(username_new)
|
8
|
+
@username = username_new
|
9
|
+
@errors = []
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def validate
|
15
|
+
@errors << 'error_name_length' unless validate_length?(@username, USERNAME_LENGTH_RANGE)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
require 'yaml'
|
3
|
+
module YamlFile
|
4
|
+
def self.load(file_path)
|
5
|
+
return unless File.exist?(file_path)
|
6
|
+
|
7
|
+
YAML.safe_load(File.read(file_path), [Symbol], [], true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.save(file_path, object)
|
11
|
+
File.open(file_path, 'w') { |file| file.write(object.to_yaml) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/codebreaker.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Codebreaker
|
2
|
+
require 'pry'
|
3
|
+
require 'codebreaker/version'
|
4
|
+
require 'codebreaker/yaml_file.rb'
|
5
|
+
require 'codebreaker/validator.rb'
|
6
|
+
require 'codebreaker/base_class.rb'
|
7
|
+
require 'codebreaker/difficulty.rb'
|
8
|
+
require 'codebreaker/init_difficulties.rb'
|
9
|
+
require 'codebreaker/game.rb'
|
10
|
+
require 'codebreaker/game_stage.rb'
|
11
|
+
require 'codebreaker/user.rb'
|
12
|
+
require 'codebreaker/statistic.rb'
|
13
|
+
end
|
data/pec
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
[33mcommit 868b6b555febde795fdbcd603849bcccb9ee72f7[m[33m ([m[1;36mHEAD -> [m[1;32mdiv[m[33m)[m
|
2
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
3
|
+
Date: Tue Dec 17 14:38:12 2019 +0200
|
4
|
+
|
5
|
+
delete config.rb
|
6
|
+
|
7
|
+
[33mcommit 97ab18e0dedca0ee07cf682475a3054828f12906[m
|
8
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
9
|
+
Date: Tue Dec 17 14:37:41 2019 +0200
|
10
|
+
|
11
|
+
add module to BaseClass
|
12
|
+
|
13
|
+
[33mcommit d182d8050db60968f6b8c06718ea6969ffb27457[m[33m ([m[1;31morigin/div[m[33m)[m
|
14
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
15
|
+
Date: Tue Dec 17 14:17:52 2019 +0200
|
16
|
+
|
17
|
+
delete %s from it
|
18
|
+
|
19
|
+
[33mcommit d12f6b9e74bf0c254c1c4b9870e2d4202b1a73d9[m
|
20
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
21
|
+
Date: Tue Dec 17 14:11:05 2019 +0200
|
22
|
+
|
23
|
+
change name it
|
24
|
+
|
25
|
+
[33mcommit dd1c0e70fb182f2f7be4c09413692575c2d521a1[m
|
26
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
27
|
+
Date: Tue Dec 17 13:48:42 2019 +0200
|
28
|
+
|
29
|
+
fix pry position
|
30
|
+
|
31
|
+
[33mcommit 98b5bf22c4fa8a7c380551edb5ca3ad2d6794732[m
|
32
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
33
|
+
Date: Tue Dec 17 13:46:38 2019 +0200
|
34
|
+
|
35
|
+
six bug compare_result
|
36
|
+
|
37
|
+
[33mcommit df7cd546de9940ac1b3400eef0c7198fd0b3920e[m
|
38
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
39
|
+
Date: Tue Dec 17 12:48:29 2019 +0200
|
40
|
+
|
41
|
+
merge user_code, game_step and compare_result
|
42
|
+
|
43
|
+
[33mcommit 9e26b8d6faf424e34e18b711b6d2ed1573ddb9d5[m
|
44
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
45
|
+
Date: Mon Dec 16 16:16:46 2019 +0200
|
46
|
+
|
47
|
+
change spec 'when compare code'
|
48
|
+
|
49
|
+
[33mcommit d00e2100936f20aeaa459b396babc2d54a6cf00c[m
|
50
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
51
|
+
Date: Mon Dec 16 15:52:06 2019 +0200
|
52
|
+
|
53
|
+
change bugs
|
54
|
+
|
55
|
+
[33mcommit 4cf1c4f9ce3c8b8c8d8a84374eb43d15b8a77256[m
|
56
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
57
|
+
Date: Fri Dec 13 14:42:57 2019 +0200
|
58
|
+
|
59
|
+
change spec
|
60
|
+
|
61
|
+
[33mcommit ea4ec9a93b76834b73515ee46d0a3d8a5403f88d[m
|
62
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
63
|
+
Date: Fri Dec 13 14:41:22 2019 +0200
|
64
|
+
|
65
|
+
change spec
|
66
|
+
|
67
|
+
[33mcommit 086c1c68ec82e4b8df3ed3dc4ee5c78ff6d64ae2[m
|
68
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
69
|
+
Date: Fri Dec 13 14:40:00 2019 +0200
|
70
|
+
|
71
|
+
change spec
|
72
|
+
|
73
|
+
[33mcommit 9f23a1741bbc25fbc598f33a4e0389cbf0aa0cdd[m
|
74
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
75
|
+
Date: Fri Dec 13 14:37:59 2019 +0200
|
76
|
+
|
77
|
+
change spec
|
78
|
+
|
79
|
+
[33mcommit 6cb94bff3709022da1c022d6874bd3239e36912b[m
|
80
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
81
|
+
Date: Fri Dec 13 14:35:33 2019 +0200
|
82
|
+
|
83
|
+
change spec
|
84
|
+
|
85
|
+
[33mcommit 6e4b388895a3a944cac34e2ff72c61145da93a76[m
|
86
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
87
|
+
Date: Fri Dec 13 14:29:48 2019 +0200
|
88
|
+
|
89
|
+
fix rubocop-spec errors
|
90
|
+
|
91
|
+
[33mcommit 841f30a5a0250a35e3be61e7e56a2c90448bead4[m
|
92
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
93
|
+
Date: Fri Dec 13 12:25:35 2019 +0200
|
94
|
+
|
95
|
+
change coverage value
|
96
|
+
|
97
|
+
[33mcommit 21ae5625d8cc64d0ab7967a97f3e71090fe13368[m
|
98
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
99
|
+
Date: Fri Dec 13 12:24:09 2019 +0200
|
100
|
+
|
101
|
+
fix tests
|
102
|
+
|
103
|
+
[33mcommit a2dab1a35dc088bc30666ee8d76b00ca0bfbf1b5[m
|
104
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
105
|
+
Date: Thu Dec 12 17:37:53 2019 +0200
|
106
|
+
|
107
|
+
add tests
|
108
|
+
|
109
|
+
[33mcommit 8a6dc7467c690cdda523191f2e9ab3dc2f584d93[m
|
110
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
111
|
+
Date: Wed Dec 11 12:11:53 2019 +0200
|
112
|
+
|
113
|
+
change config
|
114
|
+
|
115
|
+
[33mcommit 42d4be4d9ed74e8233b51167ab022826b2f173d4[m
|
116
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
117
|
+
Date: Wed Dec 11 12:10:41 2019 +0200
|
118
|
+
|
119
|
+
change config
|
120
|
+
|
121
|
+
[33mcommit b5f46afc950d962c95b02dc6f35f821dfc7d6d57[m
|
122
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
123
|
+
Date: Wed Dec 11 12:07:46 2019 +0200
|
124
|
+
|
125
|
+
change config
|
126
|
+
|
127
|
+
[33mcommit 7f3b332eb842928ea138da7360b725c87569d752[m
|
128
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
129
|
+
Date: Wed Dec 11 12:05:33 2019 +0200
|
130
|
+
|
131
|
+
change config
|
132
|
+
|
133
|
+
[33mcommit b44d3fd380acd908da5f59a0a74398951973d15a[m
|
134
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
135
|
+
Date: Wed Dec 11 12:02:58 2019 +0200
|
136
|
+
|
137
|
+
change config
|
138
|
+
|
139
|
+
[33mcommit 27a7a66fd25617e770374601f3bfffe5e91e6f4e[m
|
140
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
141
|
+
Date: Wed Dec 11 11:55:15 2019 +0200
|
142
|
+
|
143
|
+
add circleCI
|
144
|
+
|
145
|
+
[33mcommit 85006d6ac2240e5b2453b59bc29a461a364666a1[m
|
146
|
+
Merge: ffb7765 da5eff2
|
147
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
148
|
+
Date: Tue Dec 10 20:27:10 2019 +0200
|
149
|
+
|
150
|
+
Merge branch 'div' of https://github.com/GorohovAlex/codebreaker_gem into div
|
151
|
+
|
152
|
+
[33mcommit ffb77656c86bb34f26918607a450dcc55e488bff[m
|
153
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
154
|
+
Date: Tue Dec 10 20:25:28 2019 +0200
|
155
|
+
|
156
|
+
fix difficulty_
|
157
|
+
|
158
|
+
[33mcommit ec4194e6466a45d137a1f3e255bb0867ec0f93d1[m
|
159
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
160
|
+
Date: Tue Dec 10 14:57:55 2019 +0200
|
161
|
+
|
162
|
+
add config
|
163
|
+
|
164
|
+
[33mcommit 2e50084492c89413d32d9f1f842ae00289608cac[m
|
165
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
166
|
+
Date: Tue Dec 10 13:45:26 2019 +0200
|
167
|
+
|
168
|
+
add enities
|
169
|
+
|
170
|
+
[33mcommit da5eff25ce36ef8d394e21bf68197507ff3c6e0f[m
|
171
|
+
Merge: c4d148d e62281b
|
172
|
+
Author: GorohovAlex <34690739+GorohovAlex@users.noreply.github.com>
|
173
|
+
Date: Mon Dec 9 16:13:04 2019 +0200
|
174
|
+
|
175
|
+
Merge branch 'master' into div
|
176
|
+
|
177
|
+
[33mcommit c4d148d195c61146e532a6edbbc8b5d67c17c241[m
|
178
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
179
|
+
Date: Mon Dec 9 16:10:43 2019 +0200
|
180
|
+
|
181
|
+
fix bug reject
|
182
|
+
|
183
|
+
[33mcommit dfad87e0d25225c36759a59c96b43deb665e7493[m
|
184
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
185
|
+
Date: Mon Dec 9 16:09:37 2019 +0200
|
186
|
+
|
187
|
+
fix bugs
|
188
|
+
|
189
|
+
[33mcommit bf25c78dafd7c61cbfde2a2f7da9c0e9e7128d14[m
|
190
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
191
|
+
Date: Mon Dec 9 15:30:27 2019 +0200
|
192
|
+
|
193
|
+
cover tests
|
194
|
+
|
195
|
+
[33mcommit 77bb8f09ca29db929cbdca7f45c30238cfb5f554[m
|
196
|
+
Author: GorohovAlex <gorochov.as@gmail.com>
|
197
|
+
Date: Sat Dec 7 21:33:31 2019 +0200
|
198
|
+
|
199
|
+
create gem
|
200
|
+
|
201
|
+
[33mcommit e62281b90a678f080cb9802cb7f98be7b97537ec[m[33m ([m[1;31morigin/master[m[33m, [m[1;31morigin/HEAD[m[33m, [m[1;32mmaster[m[33m)[m
|
202
|
+
Author: Smile <gorochov.as@gmail.com>
|
203
|
+
Date: Thu Nov 21 17:52:30 2019 +0200
|
204
|
+
|
205
|
+
some change
|
206
|
+
|
207
|
+
[33mcommit e66347fe5da7e55ca34de5597d0ce15597333df8[m
|
208
|
+
Author: GorohovAlex <34690739+GorohovAlex@users.noreply.github.com>
|
209
|
+
Date: Thu Nov 21 14:13:07 2019 +0200
|
210
|
+
|
211
|
+
Initial commit
|
data/statistic_test.yml
ADDED
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker-ga
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GorohovAlex
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-21 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.8.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.8.0
|
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.12.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.12.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 12.3.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 12.3.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Write a longer description or delete this line.
|
112
|
+
email:
|
113
|
+
- gorochov.as@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".circleci/config.yml"
|
119
|
+
- ".fasterer.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- codebreaker.gemspec
|
130
|
+
- lib/codebreaker.rb
|
131
|
+
- lib/codebreaker/base_class.rb
|
132
|
+
- lib/codebreaker/difficulty.rb
|
133
|
+
- lib/codebreaker/game.rb
|
134
|
+
- lib/codebreaker/game_stage.rb
|
135
|
+
- lib/codebreaker/init_difficulties.rb
|
136
|
+
- lib/codebreaker/statistic.rb
|
137
|
+
- lib/codebreaker/user.rb
|
138
|
+
- lib/codebreaker/validator.rb
|
139
|
+
- lib/codebreaker/version.rb
|
140
|
+
- lib/codebreaker/yaml_file.rb
|
141
|
+
- pec
|
142
|
+
- statistic_test.yml
|
143
|
+
homepage: https://github.com/GorohovAlex/codebreaker_gem
|
144
|
+
licenses: []
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.7.6.2
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Write a short summary, because RubyGems requires one.
|
166
|
+
test_files: []
|