codebreaker_kirill 0.2.8 → 0.2.11

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: fc99a59caa2ac9204b1db2281df81f876303fdb07e42cf33d145429ee99c2317
4
- data.tar.gz: d46b4c5fae6deb50e731f408cc151d1a0c18106508e4544887770fee17ea0072
3
+ metadata.gz: b56e6128500cf9b60f533450600297dd84435d87473fa09a932d17c53ca0df10
4
+ data.tar.gz: cc1517ccf27ea8e363a1250d8ee07f47dc4004c1a9ad25777f2812fe0dbbd9d8
5
5
  SHA512:
6
- metadata.gz: d301643f3c55fad4348ffec3a29ad93ebccf4d21c87a5882137fdc082c0d1a4dc9507422bc81546d48034b37dd1f7c4b7c3cf1d8ea82ea7471671d4ef47be724
7
- data.tar.gz: a5d113f63237f04e343cb9339b28dcfda3b9f398bbf781673b9e848d977335cc3c884a38c077b827daef97b94df96e918e446daea63fdc50f31a18943ca41c3d
6
+ metadata.gz: 37d10f8888309fdda4b16e4b2d621482ec0880c35e5226d31b2cbad4a59332d8587b59a422eae818afb3da765be73535044b960c181f97c84167775710565aa3
7
+ data.tar.gz: cfef8bdb0e0d66b00b1fdb982567f4c574988279c1e51aeafd5e00773839517476fb2de51be67441ceb0da6ce7410c5c28703dadc621d7d536e1030e98371242
@@ -11,15 +11,15 @@ class Game
11
11
  def initialize(user, difficulty)
12
12
  @secret_code = (1..4).to_a.map { |_num| rand(1..6) }
13
13
  @hint_counter = 0
14
- @attempts = { available: difficulty[:attempts], used: 0 }
15
- @hints = { available: difficulty[:hints], used: 0 }
14
+ @attempts = { all: difficulty[:attempts], used: 0 }
15
+ @hints = { all: difficulty[:hints], used: 0 }
16
16
  @name = user.name
17
17
  end
18
18
 
19
19
  def give_a_hint
20
20
  return 0 if @hints[:available].zero?
21
21
 
22
- @hints[:available] -= 1
22
+ @hints[:all] -= 1
23
23
  @hints[:used] += 1
24
24
  @secret_code[@hints[:used]]
25
25
  end
@@ -2,22 +2,21 @@
2
2
 
3
3
  module GuessHandler
4
4
  def respond_to_guess(game, input, code)
5
- result = []
6
- numbers = input.split('').map(&:to_i)
7
- return 'win' if numbers == code
5
+ @result = []
6
+ @numbers = input.split('').map(&:to_i)
7
+ return 'win' if @numbers == code
8
8
 
9
- game.assess_guess(numbers, code, result)
10
- game.attempts[:available] -= 1
9
+ assess_guess(code, @numbers)
11
10
  game.attempts[:used] += 1
12
- game.attempts[:available].zero? ? 'loss' : result
11
+ game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort
13
12
  end
14
13
 
15
- def assess_guess(numbers, code, result)
16
- numbers.each_with_index do |element, index|
17
- if element == code[index]
18
- result << '+'
19
- elsif code.include?(element)
20
- result << '-'
14
+ def assess_guess(code, input)
15
+ input.each_with_index { |element, index| code[index] = '+' if element == code[index] }
16
+ @result = code.each_with_index do |el, index|
17
+ if input.include?(el)
18
+ code[index] = '-'
19
+ input.slice!(@numbers.index(el))
21
20
  end
22
21
  end
23
22
  end
@@ -3,5 +3,5 @@
3
3
  require_relative 'game'
4
4
 
5
5
  module CodebreakerKirill
6
- VERSION = '0.2.8'
6
+ VERSION = '0.2.11'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kirill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Dudchenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-15 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: