gem_codebreaker_amidasd 0.1.8 → 0.1.9
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/gem_codebreaker_amidasd-0.1.8.gem +0 -0
- data/lib/gem_codebreaker_amidasd/db_utility.rb +1 -3
- data/lib/gem_codebreaker_amidasd/game.rb +25 -30
- data/lib/gem_codebreaker_amidasd/statistic.rb +2 -1
- data/lib/gem_codebreaker_amidasd/user.rb +1 -1
- data/lib/gem_codebreaker_amidasd/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b392407822fdf8a8de4a5c82a586cef805e59e3cc0886a23aaad729ec6e514e
|
4
|
+
data.tar.gz: 3ed5f6a1a6cb8930a939a57dd69a408610252b6fa3760169aa9632003d3d6996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 446853aa06ec6cf502b5f871c81bb651a9fc7e070143a73e68cc9dc74c633e8eaa6abe0f58b504d8446cbd034bea9f92235b87a296cded7ec751a1d450a0362b
|
7
|
+
data.tar.gz: 84e3dac8acc19ac7e578bfe3b125e75b39d59743bc85b65cd66445ce69f027b2615cff20cfd29af2c34551c9e13d69a57061317863d3386ea971138dd3e7739f
|
Binary file
|
@@ -10,9 +10,7 @@ module GemCodebreakerAmidasd
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def load_yaml_db(yml_db = PATH_CODEBREAKER_DB)
|
13
|
-
return YAML.load_file(yml_db) if File.exist?(yml_db)
|
14
|
-
|
15
|
-
[]
|
13
|
+
return YAML.load_file(yml_db) if File.exist?(yml_db); []
|
16
14
|
end
|
17
15
|
|
18
16
|
def add_in_db(array:, user:, game:)
|
@@ -19,7 +19,10 @@ module GemCodebreakerAmidasd
|
|
19
19
|
|
20
20
|
def initialize(other_difficulty: {})
|
21
21
|
@difficulty_hash = DIFFICULTY_HASH.merge(other_difficulty)
|
22
|
-
@
|
22
|
+
@total_count_attempt = 0
|
23
|
+
@total_count_hints = 0
|
24
|
+
@count_plus = 0
|
25
|
+
@count_minus = 0
|
23
26
|
@length_code = 4
|
24
27
|
@min_num = 1
|
25
28
|
@max_num = 6
|
@@ -35,8 +38,6 @@ module GemCodebreakerAmidasd
|
|
35
38
|
def setDifficulty(difficulty)
|
36
39
|
return unless @difficulty_hash.key? difficulty
|
37
40
|
|
38
|
-
generate_secret_code
|
39
|
-
secret_code_shuffle
|
40
41
|
@difficulty = difficulty
|
41
42
|
@total_count_attempt = @difficulty_hash[difficulty][:total_count_attempt]
|
42
43
|
@total_count_hints = @difficulty_hash[difficulty][:total_count_hints]
|
@@ -45,53 +46,47 @@ module GemCodebreakerAmidasd
|
|
45
46
|
def gets_hint
|
46
47
|
empty_result
|
47
48
|
return add_error(ERRORS[:HintsEnd]) unless @total_count_hints > @count_hints
|
48
|
-
return add_error(ERRORS[:NoCluesAvailable]) unless
|
49
|
+
return add_error(ERRORS[:NoCluesAvailable]) unless secret_code_rand
|
49
50
|
|
50
51
|
@count_hints += 1
|
51
|
-
@hint =
|
52
|
+
@hint = secret_code_rand.pop
|
52
53
|
end
|
53
54
|
|
54
|
-
def
|
55
|
-
@
|
56
|
-
@secret_code_rand.shuffle!
|
57
|
-
@secret_code_rand.uniq!
|
55
|
+
def secret_code
|
56
|
+
@secret_code ||= Array.new(@length_code) { rand(@min_num..@max_num) }
|
58
57
|
end
|
59
58
|
|
60
|
-
def
|
61
|
-
@
|
62
|
-
@length_code.times do
|
63
|
-
@secret_code << rand(@min_num..@max_num)
|
64
|
-
end
|
59
|
+
def secret_code_rand
|
60
|
+
@secret_code_rand ||= secret_code.clone.shuffle!
|
65
61
|
end
|
66
62
|
|
67
63
|
def guess_code(code_attempt)
|
68
64
|
empty_result
|
69
65
|
input_code = to_array(code_attempt)
|
66
|
+
return @status = STATUS[:win] if input_code == secret_code
|
67
|
+
|
70
68
|
return add_error(ERRORS[:WrongCode]) unless valid_code? input_code
|
71
69
|
|
72
|
-
|
73
|
-
prepare_arrays(input_code, cache_secret_code)
|
74
|
-
@status = STATUS[:win] if cache_secret_code.empty?
|
70
|
+
check_results(input_code)
|
75
71
|
@count_attempt += 1
|
76
|
-
@status = STATUS[:lose] if @total_count_attempt <= @count_attempt
|
72
|
+
@status = STATUS[:lose] if @total_count_attempt <= @count_attempt
|
77
73
|
end
|
78
74
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
private
|
76
|
+
|
77
|
+
def check_results(input_code)
|
78
|
+
secret_code_temp = secret_code.map.with_index do |value,key|
|
79
|
+
next input_code[key] = nil if value == input_code[key]; value
|
84
80
|
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
@count_plus = secret_code_temp.count(nil)
|
83
|
+
secret_code_temp = secret_code_temp.map.with_index do |value, |
|
84
|
+
next nil if value && input_code.include?(value)
|
85
|
+
value
|
89
86
|
end
|
90
|
-
|
87
|
+
@count_minus = secret_code_temp.count(nil) - @count_plus
|
91
88
|
end
|
92
89
|
|
93
|
-
private
|
94
|
-
|
95
90
|
def empty_result
|
96
91
|
@error = nil
|
97
92
|
@count_plus = 0
|
@@ -108,7 +103,7 @@ module GemCodebreakerAmidasd
|
|
108
103
|
end
|
109
104
|
|
110
105
|
def to_array(str)
|
111
|
-
str.to_i
|
106
|
+
str.chars.map(&:to_i)
|
112
107
|
end
|
113
108
|
end
|
114
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_codebreaker_amidasd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amidasd
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- gem_codebreaker_amidasd-0.1.5.gem
|
137
137
|
- gem_codebreaker_amidasd-0.1.6.gem
|
138
138
|
- gem_codebreaker_amidasd-0.1.7.gem
|
139
|
+
- gem_codebreaker_amidasd-0.1.8.gem
|
139
140
|
- gem_codebreaker_amidasd.gemspec
|
140
141
|
- lib/gem_codebreaker_amidasd.rb
|
141
142
|
- lib/gem_codebreaker_amidasd/db_utility.rb
|