GemCodebreaker 0.1.4 → 0.1.8
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/.circleci/config.yml +4 -1
- data/.fasterer.yml +21 -0
- data/.gitignore +0 -1
- data/Gemfile.lock +74 -0
- data/bin/{console.rb → console} +3 -3
- data/lib/GemCodebreaker/classes/codemaker.rb +1 -1
- data/lib/GemCodebreaker/classes/game.rb +12 -14
- data/lib/GemCodebreaker/classes/game_config.rb +1 -3
- data/lib/GemCodebreaker/classes/game_statistic.rb +3 -5
- data/lib/GemCodebreaker/gem_codebreaker.rb +0 -1
- data/lib/GemCodebreaker/modules/game_configurations.rb +0 -4
- data/lib/GemCodebreaker/modules/serializer_deserializer.rb +1 -1
- data/lib/GemCodebreaker/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d387ad1e4ffd7b5f742c61768832b940267eabd5ffbfb920acb57debc5c84492
|
4
|
+
data.tar.gz: e8faf1b025e53f99585212d4264d99296d008b3696b96f8df3b8053a993b9c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2faa57d32240522392f40efe51240956609e36253142163d71ca2d7625711a1c460a8e82ed8a02734b48c0a1cd83d9bd69c67ebd8c4248f39b8fa2d5424cc9f
|
7
|
+
data.tar.gz: 26b9a4e0280a7ef4e0580c0139e086d8433cfb5a9e9ff6b5293ab327841c73495411fcd3a8832b22096f4634530772e5ffa097fbcdb97b174264afde19d4aed1
|
data/.circleci/config.yml
CHANGED
@@ -3,7 +3,7 @@ version: 2.1
|
|
3
3
|
executors:
|
4
4
|
default:
|
5
5
|
working_directory: ~/codebreaker
|
6
|
-
description: Gem for codebreaker
|
6
|
+
description: Gem for game codebreaker
|
7
7
|
docker:
|
8
8
|
- image: circleci/ruby:2.7.1
|
9
9
|
|
@@ -30,6 +30,9 @@ commands:
|
|
30
30
|
- run:
|
31
31
|
name: rubocop
|
32
32
|
command: bundle exec rubocop
|
33
|
+
- run:
|
34
|
+
name: fasterer
|
35
|
+
command: bundle exec fasterer
|
33
36
|
run_specs:
|
34
37
|
description: Run specs
|
35
38
|
steps:
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
exclude_paths:
|
21
|
+
- 'vendor/**/*.rb'
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
GemCodebreaker (0.1.8)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
colorize (0.8.1)
|
11
|
+
concurrent-ruby (1.1.6)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.3.2)
|
14
|
+
fasterer (0.8.3)
|
15
|
+
colorize (~> 0.7)
|
16
|
+
ruby_parser (>= 3.14.1)
|
17
|
+
i18n (1.8.3)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
parallel (1.19.2)
|
20
|
+
parser (2.7.1.3)
|
21
|
+
ast (~> 2.4.0)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (13.0.1)
|
24
|
+
rexml (3.2.4)
|
25
|
+
rspec (3.7.0)
|
26
|
+
rspec-core (~> 3.7.0)
|
27
|
+
rspec-expectations (~> 3.7.0)
|
28
|
+
rspec-mocks (~> 3.7.0)
|
29
|
+
rspec-core (3.7.1)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-expectations (3.7.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.7.0)
|
34
|
+
rspec-mocks (3.7.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-support (3.7.1)
|
38
|
+
rubocop (0.84.0)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 2.7.0.1)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 0.0.3)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
46
|
+
rubocop-ast (0.0.3)
|
47
|
+
parser (>= 2.7.0.1)
|
48
|
+
rubocop-rspec (1.41.0)
|
49
|
+
rubocop (>= 0.68.1)
|
50
|
+
ruby-progressbar (1.10.1)
|
51
|
+
ruby_parser (3.14.2)
|
52
|
+
sexp_processor (~> 4.9)
|
53
|
+
sexp_processor (4.15.0)
|
54
|
+
simplecov (0.18.5)
|
55
|
+
docile (~> 1.1)
|
56
|
+
simplecov-html (~> 0.11)
|
57
|
+
simplecov-html (0.12.2)
|
58
|
+
unicode-display_width (1.7.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
GemCodebreaker!
|
65
|
+
fasterer (~> 0.8.3)
|
66
|
+
i18n (~> 1.8.3)
|
67
|
+
rake (~> 13.0.1)
|
68
|
+
rspec (~> 3.7.0)
|
69
|
+
rubocop (~> 0.84.0)
|
70
|
+
rubocop-rspec (~> 1.41.0)
|
71
|
+
simplecov (~> 0.18.5)
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.1.4
|
data/bin/{console.rb → console}
RENAMED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
#
|
3
|
+
# frozen_string_literal: true
|
4
4
|
|
5
5
|
require 'bundler/setup'
|
6
|
-
require 'GemCodebreaker'
|
6
|
+
require 'GemCodebreaker/gem_codebreaker'
|
7
7
|
|
8
8
|
# You can add fixtures and/or initialization code here to make experimenting
|
9
9
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -32,7 +32,7 @@ module GemCodebreaker
|
|
32
32
|
@game_code.each do |secret_code_item|
|
33
33
|
if @user_code.include?(secret_code_item)
|
34
34
|
@minus_match += 1
|
35
|
-
@user_code.
|
35
|
+
@user_code.delete_at(@user_code.index(secret_code_item))
|
36
36
|
else
|
37
37
|
@empty_match += 1
|
38
38
|
end
|
@@ -3,18 +3,16 @@
|
|
3
3
|
module GemCodebreaker
|
4
4
|
# Game class
|
5
5
|
class Game
|
6
|
-
LENGTH_OF_SECRET_CODE =
|
6
|
+
LENGTH_OF_SECRET_CODE = 4
|
7
7
|
DIGIT_RANGE = (1..6).freeze
|
8
8
|
|
9
9
|
include GameConfigurations
|
10
10
|
include Validator
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :secrete_code, :statistic, :matcher_hash
|
12
12
|
attr_accessor :config
|
13
13
|
|
14
14
|
def initialize(user, level)
|
15
15
|
@config = GameConfig.new(user, level.to_sym)
|
16
|
-
@attempts = @config.user_attempts
|
17
|
-
@hints = @config.user_hints
|
18
16
|
@statistic = []
|
19
17
|
end
|
20
18
|
|
@@ -23,20 +21,20 @@ module GemCodebreaker
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def generate_secret_code
|
26
|
-
@secrete_code = LENGTH_OF_SECRET_CODE.map { rand DIGIT_RANGE }
|
24
|
+
@secrete_code = (1..LENGTH_OF_SECRET_CODE).map { rand DIGIT_RANGE }
|
27
25
|
end
|
28
26
|
|
29
27
|
def guess_valid?(user_code)
|
30
28
|
validate_string(user_code)
|
31
|
-
validate_guess_length if user_code.length != LENGTH_OF_SECRET_CODE
|
29
|
+
validate_guess_length if user_code.length != LENGTH_OF_SECRET_CODE
|
32
30
|
validate_chars_range unless user_code[/\A[1-6]{4}\z/]
|
33
31
|
true
|
34
32
|
end
|
35
33
|
|
36
34
|
def guess_start(input_code)
|
37
|
-
validate_number_of_attempts if @
|
35
|
+
validate_number_of_attempts if @config.user_attempts >= @config.max_attempts
|
38
36
|
|
39
|
-
@
|
37
|
+
@config.user_attempts += 1
|
40
38
|
user_code = convert_string_to_array(input_code)
|
41
39
|
code_marker = CodeMaker.new(@secrete_code, user_code)
|
42
40
|
code_marker.calculate_result_code
|
@@ -44,27 +42,27 @@ module GemCodebreaker
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def win_game?
|
47
|
-
@matcher_hash[:plus] == LENGTH_OF_SECRET_CODE
|
45
|
+
@matcher_hash[:plus] == LENGTH_OF_SECRET_CODE
|
48
46
|
end
|
49
47
|
|
50
48
|
def game_over?
|
51
|
-
(@
|
49
|
+
(@config.user_attempts >= @config.max_attempts) && win_game? == false
|
52
50
|
end
|
53
51
|
|
54
52
|
def hints_used?
|
55
|
-
@
|
53
|
+
@config.user_hints >= @config.max_hints
|
56
54
|
end
|
57
55
|
|
58
56
|
def hint
|
59
57
|
validate_number_of_hints if hints_used?
|
60
58
|
|
61
|
-
@
|
59
|
+
@config.user_hints += 1
|
62
60
|
@secrete_code.sample
|
63
61
|
end
|
64
62
|
|
65
63
|
def reset
|
66
|
-
@
|
67
|
-
@
|
64
|
+
@config.user_attempts = 0
|
65
|
+
@config.user_hints = 0
|
68
66
|
generate_secret_code
|
69
67
|
end
|
70
68
|
|
@@ -4,15 +4,13 @@ module GemCodebreaker
|
|
4
4
|
# Configuration class for game
|
5
5
|
class GameConfig
|
6
6
|
include GameConfigurations
|
7
|
-
|
8
|
-
attr_accessor :user_nick_name, :difficulty, :max_attempts, :max_hints
|
7
|
+
attr_accessor :user_nick_name, :difficulty, :max_attempts, :max_hints, :user_attempts, :user_hints
|
9
8
|
|
10
9
|
def initialize(user, level)
|
11
10
|
@user_nick_name = user.nick_name
|
12
11
|
@difficulty = level
|
13
12
|
@max_attempts = GAME_LEVEL[level][:attempts]
|
14
13
|
@max_hints = GAME_LEVEL[level][:hints]
|
15
|
-
@difficulty_priority = GAME_LEVEL_PRIORITY[level]
|
16
14
|
@user_attempts = 0
|
17
15
|
@user_hints = 0
|
18
16
|
end
|
@@ -3,17 +3,15 @@
|
|
3
3
|
module GemCodebreaker
|
4
4
|
# Game statistic class
|
5
5
|
class GameStatistic
|
6
|
-
attr_reader :user_nickname, :difficulty, :attempts_total, :attempts_used, :hints_total, :hints_used
|
7
|
-
:difficulty_priority
|
6
|
+
attr_reader :user_nickname, :difficulty, :attempts_total, :attempts_used, :hints_total, :hints_used
|
8
7
|
|
9
8
|
def initialize(game)
|
10
9
|
@user_nickname = game.config.user_nick_name
|
11
10
|
@difficulty = game.config.difficulty
|
12
11
|
@attempts_total = game.config.max_attempts
|
13
|
-
@attempts_used = game.
|
12
|
+
@attempts_used = game.config.user_attempts
|
14
13
|
@hints_total = game.config.max_hints
|
15
|
-
@hints_used = game.
|
16
|
-
@difficulty_priority = game.config.difficulty_priority
|
14
|
+
@hints_used = game.config.user_hints
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -5,7 +5,7 @@ module GemCodebreaker
|
|
5
5
|
module SerializerDeserializer
|
6
6
|
FILE_NAME = 'game_statistic.yml'
|
7
7
|
STATISTIC_DIR = 'data'
|
8
|
-
STORAGE_PATH = File.expand_path("./#{STATISTIC_DIR}/#{FILE_NAME}"
|
8
|
+
STORAGE_PATH = File.expand_path("./#{STATISTIC_DIR}/#{FILE_NAME}")
|
9
9
|
|
10
10
|
def data_dir_get
|
11
11
|
data_directory = File.dirname(STORAGE_PATH)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: GemCodebreaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fasterer
|
@@ -116,14 +116,16 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".circleci/config.yml"
|
119
|
+
- ".fasterer.yml"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".rspec"
|
121
122
|
- ".rubocop.yml"
|
122
123
|
- GemCodebreaker.gemspec
|
123
124
|
- Gemfile
|
125
|
+
- Gemfile.lock
|
124
126
|
- LICENSE.txt
|
125
127
|
- README.md
|
126
|
-
- bin/console
|
128
|
+
- bin/console
|
127
129
|
- bin/setup
|
128
130
|
- lib/GemCodebreaker/classes/codemaker.rb
|
129
131
|
- lib/GemCodebreaker/classes/game.rb
|