codebreaker_game 0.1.0 → 0.1.1

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: 8868a9b0d999b99507f556efea58e1080a2e42141adbeac51cf847c3c1f32533
4
- data.tar.gz: 8e1164d7133e1fe88f074af6efbbb84b83f5f7930eb86aadcd142ea484ed7609
3
+ metadata.gz: c834fd35a0d502315d62fc4d1bf762d86c00358cd7f3c68ae625b7a205d9f21e
4
+ data.tar.gz: f55dd523970e01fe39e31caeb9c81c249242ae305c8977d257df62d5dc70f389
5
5
  SHA512:
6
- metadata.gz: dc66b24c524fde5a1c51399de7372cdbc673c2f56c34495aa6cce765312512c89faff00f1d956eb2d380341d456c7be00a131fad4429857c06b86da28f86bb28
7
- data.tar.gz: 745569746ec95659028c5861287850c7f16814bae6f0453c7d442bb73bb84ee143336f5138370d907f5b27bf0e8726b432771975176ee9d82cfd2a161b59ea4e
6
+ metadata.gz: 25f2e5c012907e01ee90e6277576503008a69786eec71bc2305e7c87a81ac519371f0ddbf7f1fcba1266e8b0a8c17f9c32340dc79881806dd84cb3cba24bf72a
7
+ data.tar.gz: 8514c94e16c2bb9ccc6472836605de32fbc20e434acde35524fbddb95fc0d58a040eebe349900d35b3b995fc66f0b636f2b3300297a001c681746d7e0fb89d79
@@ -16,10 +16,14 @@ module CodebreakerGame
16
16
  STATUS_IN_PROGRESS = 'in_process'.freeze
17
17
  STATUS_WIN = 'win'.freeze
18
18
  STATUS_LOSE = 'lose'.freeze
19
+ STRONG_INTERSECTION = '+'.freeze
20
+ NOT_STRONG_INTERSECTION = '-'.freeze
21
+ SECRET_LENGTH = 4
19
22
 
20
23
  def initialize
21
- @secret_number = generate_secret
24
+ @secret_number = generate_secret(SECRET_LENGTH)
22
25
  @status = STATUS_IN_PROGRESS
26
+ @hints = @secret_number.to_s.chars.shuffle
23
27
  @storage = yaml_store
24
28
  @difficulty_factory = CodebreakerGame::DifficultyFactory.new
25
29
  save_storage unless CodebreakerGame::Game.storage_exists?
@@ -36,9 +40,14 @@ module CodebreakerGame
36
40
 
37
41
  def create_user(name:, difficulty:)
38
42
  @user = User.new(name, difficulty)
43
+ sample_hints(difficulty.hints)
39
44
  @user
40
45
  end
41
46
 
47
+ def sample_hints(hints)
48
+ @hints = @hints.sample(hints)
49
+ end
50
+
42
51
  def create_difficulty(difficulty:)
43
52
  @difficulty_factory.difficulty_by_name(difficulty)
44
53
  end
@@ -58,10 +67,7 @@ module CodebreakerGame
58
67
  end
59
68
 
60
69
  def hint
61
- return 'You have no hints!' unless user.hints?
62
-
63
- user.hint
64
- @secret_number.to_s.chars[rand(CodebreakerGame::Random::RANDOM_LENGTH)]
70
+ @hints.pop
65
71
  end
66
72
 
67
73
  private
@@ -82,7 +88,7 @@ module CodebreakerGame
82
88
  user_digits = number_two.to_s.chars
83
89
  response = pluses(secret_digits, user_digits)
84
90
  response += minuses(secret_digits, user_digits)
85
- win if response == '++++'
91
+ win if response == STRONG_INTERSECTION * SECRET_LENGTH
86
92
  response
87
93
  end
88
94
 
@@ -91,7 +97,7 @@ module CodebreakerGame
91
97
  secret_digits.each_with_index do |digit, index|
92
98
  next if digit != user_digits[index]
93
99
 
94
- response += '+'
100
+ response += STRONG_INTERSECTION
95
101
  secret_digits[index] = nil
96
102
  user_digits[index] = nil
97
103
  end
@@ -103,7 +109,7 @@ module CodebreakerGame
103
109
  secret_digits.each_with_index do |digit, index|
104
110
  next unless digit != user_digits[index] && user_digits.include?(digit)
105
111
 
106
- response += '-'
112
+ response += NOT_STRONG_INTERSECTION
107
113
  end
108
114
  response
109
115
  end
@@ -1,10 +1,11 @@
1
1
  module CodebreakerGame
2
2
  module Random
3
- RANDOM_MIN = 1
4
- RANDOM_MAX = 6
5
- RANDOM_LENGTH = 4
3
+ DEFAULT_MIN = 1
4
+ DEFAULT_MAX = 6
5
+ DEFAULT_LENGTH = 4
6
+ ORDER_AMOUNT = 10
6
7
 
7
- def generate_secret(length = RANDOM_LENGTH)
8
+ def generate_secret(length = DEFAULT_LENGTH)
8
9
  number = 0
9
10
  length.times do |degree|
10
11
  number += generate_random * order(degree)
@@ -15,10 +16,10 @@ module CodebreakerGame
15
16
  private
16
17
 
17
18
  def order(degree)
18
- 10**degree
19
+ ORDER_AMOUNT**degree
19
20
  end
20
21
 
21
- def generate_random(min = RANDOM_MIN, max = RANDOM_MAX)
22
+ def generate_random(min = DEFAULT_MIN, max = DEFAULT_MAX)
22
23
  rand(min..max)
23
24
  end
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module CodebreakerGame
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2019-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler