code_brkr_game_training 0.7.2 → 0.7.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e08993644da18256d3cd3720ec7ccc939ee82074a1effb12659116931c4d2a10
|
4
|
+
data.tar.gz: e10409ead753bdc0bd7f3cb6c89bdea87ca335c1b481abed9f912b36dd341370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ed4ebe5861682f5a3c77cc6e46de4e9d0b5dad2d6eca1390e223cc9208676d9821d19fbb65a2ccaf839c058e04622072b65b07696238ecf66418f804527e854
|
7
|
+
data.tar.gz: 9375923f2eca595e325eec041bd2852c15da1e7d79a9e4f9b9308110f9ca32332f57c18da3b409befb24c52151a6987287f4c9e9f91c33cc4de42de601735235
|
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ module CodeBrkrGameTraining
|
|
9
9
|
GAME_NUMBERS = { from: 1, to: 6, count: 4 }.freeze
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
@secret_digit_arr =
|
12
|
+
@secret_digit_arr = generate_code
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
@@ -18,23 +18,22 @@ module CodeBrkrGameTraining
|
|
18
18
|
|
19
19
|
def code_check(user_digits_arr)
|
20
20
|
check_array_code_format(user_digits_arr)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
|
22
|
+
{
|
23
|
+
in_positions: check_in_positions(user_digits_arr),
|
24
|
+
out_of_positions: check_out_positions(user_digits_arr),
|
25
|
+
not_guessed: check_not_guessed(user_digits_arr)
|
25
26
|
}
|
26
|
-
result[:not_guessed] = GAME_NUMBERS[:count] - result[:in_position] - result[:out_of_position]
|
27
|
-
result
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
29
|
+
def random_digit(exclude_indexes)
|
31
30
|
rand_index = @secret_digit_arr.each_index.reject { |index| exclude_indexes.include? index }.sample
|
32
31
|
{ index: rand_index, digit: @secret_digit_arr[rand_index] }
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
36
35
|
|
37
|
-
def
|
36
|
+
def generate_code
|
38
37
|
Array.new(GAME_NUMBERS[:count]) { rand(GAME_NUMBERS[:from]..GAME_NUMBERS[:to]) }
|
39
38
|
end
|
40
39
|
|
@@ -46,14 +45,25 @@ module CodeBrkrGameTraining
|
|
46
45
|
code_arr.each { |digit| raise GameError, 'incorrect_code_format' unless digits_range_arr.member? digit }
|
47
46
|
end
|
48
47
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
def check_miss_indexes(user_arr)
|
49
|
+
GAME_NUMBERS[:count].times.reject { |user_index| user_arr[user_index] == @secret_digit_arr[user_index] }
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_in_positions(user_arr)
|
53
|
+
GAME_NUMBERS[:count] - check_miss_indexes(user_arr).length
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_out_positions(user_arr)
|
57
|
+
miss_indexes = check_miss_indexes(user_arr)
|
58
|
+
system_digits = @secret_digit_arr.select.with_index { |_, system_index| miss_indexes.include? system_index }
|
59
|
+
miss_indexes.collect do |miss_index|
|
60
|
+
found = system_digits.find_index { |system_num| user_arr[miss_index] == system_num }
|
61
|
+
found.nil? ? nil : system_digits.delete_at(found)
|
62
|
+
end.compact.length
|
63
|
+
end
|
64
|
+
|
65
|
+
def check_not_guessed(user_arr)
|
66
|
+
GAME_NUMBERS[:count] - check_in_positions(user_arr) - check_out_positions(user_arr)
|
57
67
|
end
|
58
68
|
end
|
59
69
|
end
|
@@ -21,11 +21,11 @@ module CodeBrkrGameTraining
|
|
21
21
|
.collect { |difficulty| difficulty[:name] }
|
22
22
|
end
|
23
23
|
|
24
|
-
def initialize(
|
25
|
-
@value_name =
|
24
|
+
def initialize(difficulty_value)
|
25
|
+
@value_name = difficulty_value
|
26
26
|
validate
|
27
27
|
|
28
|
-
@init_values = GAME_DIFFICULTIES[
|
28
|
+
@init_values = GAME_DIFFICULTIES[difficulty_value.to_sym]
|
29
29
|
@actual_values = @init_values.clone
|
30
30
|
end
|
31
31
|
|
@@ -24,7 +24,7 @@ module CodeBrkrGameTraining
|
|
24
24
|
def code_guessing_attempt(digits_arr)
|
25
25
|
@difficulty.guessing_attempts_decrement!
|
26
26
|
result = @code.code_check(digits_arr)
|
27
|
-
if result[:
|
27
|
+
if result[:in_positions] == Code::GAME_NUMBERS[:count]
|
28
28
|
result = { win: true }
|
29
29
|
elsif !@difficulty.guessing_attempts_available?
|
30
30
|
result = { loss: true, сorrect_answer: @code.to_s }
|
@@ -34,7 +34,7 @@ module CodeBrkrGameTraining
|
|
34
34
|
|
35
35
|
def game_hint
|
36
36
|
@difficulty.hints_decrement!
|
37
|
-
hint = @code.
|
37
|
+
hint = @code.random_digit(@hints_indexes)
|
38
38
|
@hints_indexes << hint[:index]
|
39
39
|
hint[:digit]
|
40
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_brkr_game_training
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fasterer
|