ep-codebreaker 0.3.1 → 0.3.2

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
  SHA1:
3
- metadata.gz: 9d8b421d3c5caf1b37d80b9d168a7ebc32820b58
4
- data.tar.gz: 26c7ee1e48c44513879769ebce8984bc6b9d5e7f
3
+ metadata.gz: 1bfaaf8084c62deada86235e21b8d00083cffb19
4
+ data.tar.gz: 074d6e1faa9313dda342f0955185208eea75139f
5
5
  SHA512:
6
- metadata.gz: f7e0278325eabc82ccfa08f38035df512801f64ef8270521b3ade44ad4a1bf3fe869bdec67adba03c481be69b2e5a8713491419181dfea4d67edd063acf1ec6c
7
- data.tar.gz: a84d3cf7b3136cec8df57365cc71ef2262b1d43a60ec6496b62a9edce86c947a7b985c22b4a443975dc64325e41f79aa85c9e891be510c3cbaa050a8bf51b663
6
+ metadata.gz: c0972fdbfa7fc7b1df76b16f595080f1f88c5ed200c4839469af0cd01193b8723538e6949ba342cf1142999f43d075a38f28b3c24c328f75027bf03c4a3a28d7
7
+ data.tar.gz: 5a674713394eda837d6ef357282499cc913608276f307cf1d166bdbb61e4b4783a4114a379bc2daf827a0af08902ae046ddb9bb61872bb629c37c54bf5fdcb2a
@@ -7,55 +7,43 @@ module Codebreaker
7
7
  class Game
8
8
  include GameWriter
9
9
 
10
- MIN = 1
11
- MAX = 6
10
+ MIN = 1
11
+ MAX = 6
12
12
  LENGTH = 4
13
13
 
14
- REGEXP = Regexp.new("^[#{MIN}-#{MAX}]{#{LENGTH}}$")
15
-
16
14
  TRIES = 10
17
15
  HINTS = 3
18
16
 
19
- private_constant :MIN, :MAX, :LENGTH, :REGEXP, :TRIES, :HINTS
17
+ private_constant :MIN, :MAX, :LENGTH, :TRIES, :HINTS
20
18
  attr_reader :tries_left, :hints_left
21
19
 
22
20
  def start
23
- @code = Array.new(LENGTH) { rand(MIN..MAX) }.join
21
+ @code = Array.new(LENGTH) { rand(MIN..MAX) }.join
22
+ @result = ''
23
+ @tries_left = TRIES
24
+ @hints_left = HINTS
24
25
  @indexes_for_hint = (0...LENGTH).to_a
25
-
26
- @tries_left = TRIES
27
- @hints_left = HINTS
28
-
29
- @finished = false
30
- @won = false
31
26
  end
32
27
 
33
28
  def check_guess(input)
34
29
  verify input
35
-
36
30
  @tries_left -= 1
37
-
38
- result = check_input(@code.chars, input.chars)
39
- define_stage result
40
- result
31
+ @result = check_input(@code.chars, input.chars)
41
32
  end
42
33
 
43
34
  def hint
44
35
  return false if @hints_left.zero?
45
-
46
36
  @tries_left -= 1
47
37
  @hints_left -= 1
48
- define_stage
49
-
50
38
  generate_hint
51
39
  end
52
40
 
53
41
  def finished?
54
- @finished
42
+ @tries_left.zero? || won?
55
43
  end
56
44
 
57
45
  def won?
58
- @won
46
+ @result == ('+' * LENGTH)
59
47
  end
60
48
 
61
49
  def answer
@@ -108,18 +96,10 @@ module Codebreaker
108
96
  hint
109
97
  end
110
98
 
111
- def define_stage(result = '')
112
- if result == ('+' * LENGTH)
113
- @finished = true
114
- @won = true
115
- elsif @tries_left.zero?
116
- @finished = true
117
- end
118
- end
119
-
120
99
  def verify(input)
100
+ regexp = Regexp.new("^[#{MIN}-#{MAX}]{#{LENGTH}}$")
121
101
  msg = "Guesses must consist of #{LENGTH} digits from #{MIN} to #{MAX}"
122
- raise(ArgumentError, msg) if !input.is_a?(String) || !input.match?(REGEXP)
102
+ raise(ArgumentError, msg) if !input.is_a?(String) || !input.match?(regexp)
123
103
  end
124
104
  end
125
105
  end
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ep-codebreaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Poberezhny