gem_codebreaker_amidasd 0.1.4 → 0.1.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 +4 -4
- data/gem_codebreaker_amidasd-0.1.4.gem +0 -0
- data/lib/gem_codebreaker_amidasd.rb +1 -8
- data/lib/gem_codebreaker_amidasd/db_utility.rb +18 -18
- data/lib/gem_codebreaker_amidasd/gem_codebreaker.rb +11 -11
- data/lib/gem_codebreaker_amidasd/user.rb +20 -21
- 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: 65f81d2ecb7263634807f5d042e8d513534dcf7420dd8469e77672078860060b
|
4
|
+
data.tar.gz: c30e98b582e54cf7adea32993e74e9033359b532183a98de51f95b6a2025b2a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3677c98735935df4d0cb7b48c864a59489138eec00bc7370aa54ae4fe4a2c5927f4087710840a352416d1d9ef4cbd2484aa26b91c21e4be55f836b2b6a6efe6e
|
7
|
+
data.tar.gz: d5d987b906b62309208b98ca1339c29cd867809e6ff468d873a006e9bee5fd549748af18aab2c341868c2ffa0bfe7ebe11ce5153650ad329ef5e93d7b85fb786
|
Binary file
|
@@ -1,11 +1,4 @@
|
|
1
1
|
require 'gem_codebreaker_amidasd/version'
|
2
|
-
require 'gem_codebreaker_amidasd/gem_codebreaker'
|
3
2
|
require 'gem_codebreaker_amidasd/db_utility'
|
4
3
|
require 'gem_codebreaker_amidasd/user'
|
5
|
-
require 'gem_codebreaker_amidasd/
|
6
|
-
|
7
|
-
# Dir[Dir.pwd + './gem_codebreaker_amidasd/**/*.rb'].sort.reverse_each { |f| require f }
|
8
|
-
# module GemCodebreakerAmidasd
|
9
|
-
# # class Error < StandardError; end
|
10
|
-
# #
|
11
|
-
# # end
|
4
|
+
require 'gem_codebreaker_amidasd/gem_codebreaker'
|
@@ -1,25 +1,25 @@
|
|
1
1
|
module GemCodebreakerAmidasd
|
2
|
-
|
3
|
-
class << self
|
4
|
-
def save_yaml_db(user, yml_db)
|
5
|
-
# yml_db = CodebreakerConfig::PATH_DB
|
6
|
-
File.write(yml_db, user.to_yaml)
|
7
|
-
end
|
2
|
+
require 'yaml'
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class DbUtility
|
5
|
+
class << self
|
6
|
+
def save_yaml_db(user, yml_db)
|
7
|
+
File.write(yml_db, user.to_yaml)
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
10
|
+
def load_yaml_db(yml_db)
|
11
|
+
return unless File.exist?(yml_db)
|
12
|
+
|
13
|
+
YAML.load_file(yml_db)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def add_db(user, path)
|
17
|
+
db = load_yaml_db(path)
|
18
|
+
db ||= []
|
19
|
+
db << user
|
20
|
+
db = db.sort_by { |value| [value.total_count_attempt, value.count_attempt, value.count_hint] }
|
21
|
+
save_yaml_db(db, path)
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
|
-
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module GemCodebreakerAmidasd
|
2
|
-
DIFFICULTY_HASH = {:
|
3
|
-
|
4
|
-
|
2
|
+
DIFFICULTY_HASH = { easy: { total_count_attempt: 15, total_count_hints: 2 },
|
3
|
+
medium: { total_count_attempt: 10, total_count_hints: 1 },
|
4
|
+
hell: { total_count_attempt: 5, total_count_hints: 1 } }.freeze
|
5
5
|
|
6
6
|
class GemCodebreaker
|
7
|
-
|
8
7
|
attr_accessor :difficulty_hash, :difficulty
|
9
8
|
attr_accessor :length_code, :max_num, :min_num
|
10
9
|
attr_reader :total_count_attempt, :total_count_hints, :error, :win, :count_plus, :count_minus, :hint
|
@@ -21,12 +20,13 @@ module GemCodebreakerAmidasd
|
|
21
20
|
empty_result
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
23
|
+
def string_secretcode
|
25
24
|
@secret_code.join('')
|
26
25
|
end
|
27
26
|
|
28
27
|
def set_difficulty(difficulty)
|
29
|
-
return unless @difficulty_hash.
|
28
|
+
return unless @difficulty_hash.key? difficulty
|
29
|
+
|
30
30
|
@difficulty = difficulty
|
31
31
|
@total_count_attempt = @difficulty_hash[difficulty][:total_count_attempt]
|
32
32
|
@total_count_hints = @difficulty_hash[difficulty][:total_count_hints]
|
@@ -71,17 +71,17 @@ module GemCodebreakerAmidasd
|
|
71
71
|
def search_hint
|
72
72
|
cache_array = []
|
73
73
|
@secret_code.each { |val| cache_array << val if !@array_hints.include?(val) && !cache_array.include?(val) }
|
74
|
-
@error =
|
75
|
-
@error =
|
74
|
+
@error = :HintsEnd unless @total_count_hints > @array_hints.size
|
75
|
+
@error = :NoCluesAvailable if cache_array.empty?
|
76
76
|
cache_array
|
77
77
|
end
|
78
78
|
|
79
79
|
def check_code(code_attempt)
|
80
80
|
correct_code = to_array(code_attempt)
|
81
81
|
empty_result
|
82
|
-
@error =
|
83
|
-
@error =
|
84
|
-
return nil if @error ==
|
82
|
+
@error = :WrongCode unless code_attempt.match(/[1-6]+$/)
|
83
|
+
@error = :WrongCode unless correct_code.size == @length_code
|
84
|
+
return nil if @error == :WrongCode
|
85
85
|
|
86
86
|
status_game(correct_code)
|
87
87
|
@count_attempt += 1
|
@@ -1,27 +1,26 @@
|
|
1
1
|
module GemCodebreakerAmidasd
|
2
|
-
class User
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
class User
|
3
|
+
attr_accessor :name,
|
4
|
+
:difficulty,
|
5
|
+
:total_count_attempt,
|
6
|
+
:count_attempt,
|
7
|
+
:total_count_hints,
|
8
|
+
:count_hint
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(name:)
|
11
|
+
@name = name
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def set_params(difficulty:, total_count_attempt:, count_attempt:, total_count_hints:, count_hint:)
|
15
|
+
@difficulty = difficulty
|
16
|
+
@total_count_attempt = total_count_attempt
|
17
|
+
@count_attempt = count_attempt
|
18
|
+
@total_count_hints = total_count_hints
|
19
|
+
@count_hint = count_hint
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
def self.validtion_name(name)
|
23
|
+
name.is_a?(String) && !name.empty? && name.length.between?(3, 20)
|
24
|
+
end
|
24
25
|
end
|
25
|
-
|
26
26
|
end
|
27
|
-
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.5
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- gem_codebreaker_amidasd-0.1.1.gem
|
133
133
|
- gem_codebreaker_amidasd-0.1.2.gem
|
134
134
|
- gem_codebreaker_amidasd-0.1.3.gem
|
135
|
+
- gem_codebreaker_amidasd-0.1.4.gem
|
135
136
|
- gem_codebreaker_amidasd.gemspec
|
136
137
|
- lib/gem_codebreaker_amidasd.rb
|
137
138
|
- lib/gem_codebreaker_amidasd/db_utility.rb
|