codebreaker_PI 0.6.1 → 0.6.4
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/Gemfile.lock +1 -1
- data/lib/codebreaker/version.rb +1 -1
- data/lib/entities/console.rb +8 -8
- data/lib/entities/game.rb +13 -11
- data/lib/modules/uploader.rb +0 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b30612d628e14c6fc981b89a11a02741327163574297e655be631555ef4d1758
|
4
|
+
data.tar.gz: e7277141e4bf7e34c470bf0a11bb23d45805e2226d830e49ceb3522705895085
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9200a8b67579819df23308bad2a02b85e0c44e4c9f469ff3b17d8a7c27aaf234aaa2d25689264f30af48a9dc0f8319823f334be579fb0d479e8dec23abfc7429
|
7
|
+
data.tar.gz: f5796badac894472b6a45485ce7656e8c079b9d3ccf628d4a5c3810b55bf52b0ac4a8a048ced0865d83fd235675dce43b5227a5f125a07dc6ff401533df007d7
|
data/Gemfile.lock
CHANGED
data/lib/codebreaker/version.rb
CHANGED
data/lib/entities/console.rb
CHANGED
@@ -24,6 +24,14 @@ module Codebreaker
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def show_statistics
|
28
|
+
respondent.show(winners_load)
|
29
|
+
end
|
30
|
+
|
31
|
+
def winners_load
|
32
|
+
statistic.winners(load_db)
|
33
|
+
end
|
34
|
+
|
27
35
|
private
|
28
36
|
|
29
37
|
def player
|
@@ -113,13 +121,5 @@ module Codebreaker
|
|
113
121
|
respondent.show_message(:leave)
|
114
122
|
exit
|
115
123
|
end
|
116
|
-
|
117
|
-
def show_statistics
|
118
|
-
respondent.show(winners_load)
|
119
|
-
end
|
120
|
-
|
121
|
-
def winners_load
|
122
|
-
statistic.winners(load_db)
|
123
|
-
end
|
124
124
|
end
|
125
125
|
end
|
data/lib/entities/game.rb
CHANGED
@@ -2,17 +2,19 @@ module Codebreaker
|
|
2
2
|
class Game
|
3
3
|
include Validation
|
4
4
|
|
5
|
+
INCREMENT = 1
|
5
6
|
AMOUNT_DIGITS = 4
|
6
|
-
|
7
|
+
POSITIVE_DIGIT = '+'.freeze
|
8
|
+
NEGATIVE_DIGIT = '-'.freeze
|
7
9
|
DIFFICULTIES = {
|
8
10
|
easy: { attempts: 15, hints: 2, difficulty: 'easy' },
|
9
11
|
hard: { attempts: 10, hints: 2, difficulty: 'hard' },
|
10
12
|
expert: { attempts: 5, hints: 1, difficulty: 'expert' }
|
11
13
|
}.freeze
|
12
|
-
RANGE_OF_DIGITS =
|
14
|
+
RANGE_OF_DIGITS = 1..6.freeze
|
13
15
|
GUESS_CODE = { hint: 'hint', leave: 'exit' }.freeze
|
14
16
|
|
15
|
-
attr_reader :name, :hints_total, :have_hints, :attempts_total, :hints_used, :attempts_used, :difficulty, :winner, :attempts_left
|
17
|
+
attr_reader :got_hints, :secret_code, :name, :hints_total, :have_hints, :attempts_total, :hints_used, :attempts_used, :difficulty, :winner, :attempts_left
|
16
18
|
attr_accessor :errors
|
17
19
|
|
18
20
|
def game_options(user_difficulty:, player:)
|
@@ -70,12 +72,12 @@ module Codebreaker
|
|
70
72
|
return unless validate_length(entity, length)
|
71
73
|
return unless validate_match(entity)
|
72
74
|
|
73
|
-
valid_digits?(entity,
|
75
|
+
valid_digits?(entity, RANGE_OF_DIGITS)
|
74
76
|
end
|
75
77
|
|
76
78
|
def count_attempt
|
77
|
-
@attempts_left -=
|
78
|
-
@attempts_used +=
|
79
|
+
@attempts_left -= INCREMENT
|
80
|
+
@attempts_used += INCREMENT
|
79
81
|
end
|
80
82
|
|
81
83
|
def use_hint
|
@@ -84,8 +86,8 @@ module Codebreaker
|
|
84
86
|
end
|
85
87
|
|
86
88
|
def count_tip
|
87
|
-
@have_hints -=
|
88
|
-
@hints_used +=
|
89
|
+
@have_hints -= INCREMENT
|
90
|
+
@hints_used += INCREMENT
|
89
91
|
@hints_array ||= secret_code.clone.shuffle
|
90
92
|
hint = @hints_array.pop.to_s
|
91
93
|
@got_hints += hint
|
@@ -103,7 +105,7 @@ module Codebreaker
|
|
103
105
|
|
104
106
|
def guessing(user_code)
|
105
107
|
count_attempt
|
106
|
-
return @winner = true if compare_with_right_code(user_code)
|
108
|
+
@date = Time.new and return @winner = true if compare_with_right_code(user_code)
|
107
109
|
|
108
110
|
pin = []
|
109
111
|
clone_secret_code = secret_code.clone
|
@@ -111,13 +113,13 @@ module Codebreaker
|
|
111
113
|
complex_code.map do |user_digit, secret_digit|
|
112
114
|
next unless user_digit == secret_digit
|
113
115
|
|
114
|
-
pin <<
|
116
|
+
pin << POSITIVE_DIGIT
|
115
117
|
user_code.delete_at(user_code.index(user_digit))
|
116
118
|
clone_secret_code.delete_at(clone_secret_code.index(secret_digit))
|
117
119
|
end
|
118
120
|
clone_secret_code.each do |digit|
|
119
121
|
next unless user_code.include? digit
|
120
|
-
pin <<
|
122
|
+
pin << NEGATIVE_DIGIT
|
121
123
|
user_code.delete_at(user_code.index(digit))
|
122
124
|
end
|
123
125
|
pin.sort.join('')
|
data/lib/modules/uploader.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_PI
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Pauls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|