codebreaker2018 0.3.5.0 → 0.3.5.1
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 +4 -4
- data/.rubocop.yml +22 -0
- data/.travis.yml +2 -2
- data/Gemfile +8 -2
- data/README.md +13 -4
- data/codebreaker.gemspec +1 -1
- data/lib/codebreaker/console.rb +1 -1
- data/lib/codebreaker/game.rb +8 -14
- data/lib/codebreaker/localization.rb +1 -1
- data/lib/codebreaker/storage.rb +7 -8
- data/lib/codebreaker/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7253bad10a3b25e352ce1f7426bdae6ad6da7c096b79a9a240837bfcd56cd96d
|
4
|
+
data.tar.gz: 955a190aaca6ae68ccf17ecd52b87f751d631f4d7753c38ef2fd659e245122a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '049804bb13d92830f52f940593a6e015df471fa514432a41758aa4c2cc35ed42cbdbb30e6fef48efdeeec390a54a68719e1d694b89ecee31113269b0d6185f49'
|
7
|
+
data.tar.gz: fd448d971e3cbc5d3076c5c1737ae933420884374aba213d0019bfb2205535fa94abe871e7c11186bdf9f803be3688e642ab7b9d48a23ac61d8a57bdfd3a21f0
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
Style/FrozenStringLiteralComment:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
EnforcedStyle: single_quotes
|
8
|
+
SupportedStyles:
|
9
|
+
- single_quotes
|
10
|
+
- double_quotes
|
11
|
+
|
12
|
+
Style/ParallelAssignment:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 200
|
17
|
+
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 120
|
20
|
+
|
21
|
+
Documentation:
|
22
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
3
|
-
|
3
|
+
|
4
4
|
gem 'colorize'
|
5
|
-
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'simplecov', '~> 0.13.0'
|
9
|
+
gem 'rspec_file_chef'
|
10
|
+
gem 'codeclimate-test-reporter'
|
11
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# codebreaker2018
|
2
|
+
[](https://codeclimate.com/github/bestwebua/codebreaker/maintainability) [](https://codeclimate.com/github/bestwebua/codebreaker/test_coverage) [](https://badge.fury.io/rb/codebreaker2018) [](https://travis-ci.org/bestwebua/codebreaker)
|
2
3
|
|
3
|
-
Codebreaker is a logic game in which the code-breaker tries to break a secret code created by a code-maker. The code-maker, which will be played by the application we’re going to write, creates a secret code of four numbers between 1 and 6.
|
4
|
+
Codebreaker is a logic game in which the code-breaker tries to break a secret code created by a code-maker. The code-maker, which will be played by the application we’re going to write, creates a secret code of four numbers between 1 and 6. This is new terminal version of a game represented as Ruby gem.
|
5
|
+
|
6
|
+
Codebreaker2018 Rack version: https://github.com/bestwebua/codebreaker-web
|
4
7
|
|
5
8
|
## Installation ##
|
6
9
|
|
@@ -45,6 +48,7 @@ Codebreaker::Console.new
|
|
45
48
|
- Autoload localizations from locale dir
|
46
49
|
- Default language
|
47
50
|
- Ability to change locale
|
51
|
+
- Ability to use custom locale location
|
48
52
|
|
49
53
|
### Score features ###
|
50
54
|
- Date
|
@@ -53,6 +57,12 @@ Codebreaker::Console.new
|
|
53
57
|
- Level
|
54
58
|
- Score
|
55
59
|
|
60
|
+
### Data saving ###
|
61
|
+
- Ability to use custom game-data location
|
62
|
+
|
63
|
+
### Testing ###
|
64
|
+
- RSpec tests have 100% code coverage
|
65
|
+
|
56
66
|
### Detail sample of Codebreaker usage ###
|
57
67
|
|
58
68
|
```ruby
|
@@ -104,8 +114,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
104
114
|
|
105
115
|
## Contributing
|
106
116
|
|
107
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/
|
108
|
-
|
117
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/codebreaker. 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.
|
109
118
|
|
110
119
|
## License
|
111
120
|
|
data/codebreaker.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = %q{Codebreaker}
|
12
12
|
spec.description = %q{New version of logic terminal game with English and Russian localizations. For demo mode just use: Codebreaker::Console.new}
|
13
|
-
spec.homepage = 'https://github.com/bestwebua/
|
13
|
+
spec.homepage = 'https://github.com/bestwebua/codebreaker'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.required_ruby_version = '>= 2.5.0'
|
data/lib/codebreaker/console.rb
CHANGED
data/lib/codebreaker/game.rb
CHANGED
@@ -47,6 +47,8 @@ module Codebreaker
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
+
attr_reader :result, :secret_code
|
51
|
+
|
50
52
|
def check_configuration
|
51
53
|
levels = [SIMPLE_LEVEL, MIDDLE_LEVEL, HARD_LEVEL]
|
52
54
|
raise message['errors']['fail_configuration'] if configuration.any?(&:nil?)
|
@@ -71,18 +73,10 @@ module Codebreaker
|
|
71
73
|
create_instance_vars
|
72
74
|
end
|
73
75
|
|
74
|
-
def result
|
75
|
-
@result
|
76
|
-
end
|
77
|
-
|
78
76
|
def generate_secret_code
|
79
77
|
@secret_code = (1..4).map { rand(1..6) }
|
80
78
|
end
|
81
79
|
|
82
|
-
def secret_code
|
83
|
-
@secret_code
|
84
|
-
end
|
85
|
-
|
86
80
|
def fancy_algo(guess, secret_code)
|
87
81
|
guessed_indexes, guess = [], guess.chars.map(&:to_i)
|
88
82
|
|
@@ -95,21 +89,21 @@ module Codebreaker
|
|
95
89
|
secret_code.reject.with_index do |_, guessed_index|
|
96
90
|
guessed_indexes.include?(guessed_index)
|
97
91
|
end
|
98
|
-
|
99
92
|
case
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
when item == secret_code[index] then RIGHT_ANSWER
|
94
|
+
when not_guessed_secret_nums.include?(item) then RIGHT_ANSWER_DIFF_INDEX
|
95
|
+
else WRONG_ANSWER
|
103
96
|
end
|
104
97
|
end.join
|
105
98
|
end
|
106
99
|
|
107
100
|
def calculate_score
|
108
|
-
level_rates =
|
101
|
+
level_rates =
|
102
|
+
case configuration.level
|
109
103
|
when SIMPLE_LEVEL then [TEN_POINTS, ZERO_POINTS]
|
110
104
|
when MIDDLE_LEVEL then [TWENTY_POINTS, TWENTY_POINTS]
|
111
105
|
else [FIFTY_POINTS, ONE_HUNDRED_POINTS]
|
112
|
-
|
106
|
+
end
|
113
107
|
|
114
108
|
attempt_rate, hint_rate = level_rates
|
115
109
|
guessed = result.count(RIGHT_ANSWER)
|
@@ -27,7 +27,7 @@ module Codebreaker
|
|
27
27
|
if external_path && Dir.glob("#{external_path}/*/*.yml").empty?
|
28
28
|
raise ArgumentError, 'Invalid external path.'
|
29
29
|
end
|
30
|
-
@external_path = external_path
|
30
|
+
@external_path = external_path || false
|
31
31
|
end
|
32
32
|
|
33
33
|
def localizations_dir
|
data/lib/codebreaker/storage.rb
CHANGED
@@ -7,16 +7,15 @@ module Codebreaker
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def apply_external_path(external_path = false)
|
10
|
+
raise ArgumentError, 'Invalid external path.' if external_path && !Dir.exist?(external_path)
|
10
11
|
yml_file = 'scores.yml'
|
11
|
-
|
12
|
-
raise ArgumentError, 'Invalid external path.'
|
13
|
-
end
|
12
|
+
|
14
13
|
@storage_path =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
if external_path
|
15
|
+
"#{external_path}/#{yml_file}"
|
16
|
+
else
|
17
|
+
File.expand_path("./data/#{yml_file}", File.dirname(__FILE__))
|
18
|
+
end
|
20
19
|
end
|
21
20
|
|
22
21
|
def load_game_data
|
data/lib/codebreaker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker2018
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.5.
|
4
|
+
version: 0.3.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Trotsenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
79
80
|
- ".ruby-version"
|
80
81
|
- ".travis.yml"
|
81
82
|
- Gemfile
|
@@ -100,7 +101,7 @@ files:
|
|
100
101
|
- lib/codebreaker/storage.rb
|
101
102
|
- lib/codebreaker/user_score.rb
|
102
103
|
- lib/codebreaker/version.rb
|
103
|
-
homepage: https://github.com/bestwebua/
|
104
|
+
homepage: https://github.com/bestwebua/codebreaker
|
104
105
|
licenses:
|
105
106
|
- MIT
|
106
107
|
metadata: {}
|