codebreaker_kirill 0.2.10 → 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: af1666a292ec206089afd76d62df9ca9b4a808d366c3360b2d216fed2f282b69
4
- data.tar.gz: 2570c12fb14811a32b990e7787be4109e6e7af285e6b78b33a873ea4f22840b1
3
+ metadata.gz: b56e6128500cf9b60f533450600297dd84435d87473fa09a932d17c53ca0df10
4
+ data.tar.gz: cc1517ccf27ea8e363a1250d8ee07f47dc4004c1a9ad25777f2812fe0dbbd9d8
5
5
  SHA512:
6
- metadata.gz: b36e0486cb83cf459a26f5410ceb04967a16ea8f807d5fde3e22ad4fdec7681692a6971a1827a8489287e88ebba33469ac51453c517c77067c7c8999018e9b03
7
- data.tar.gz: 209f9e5d54879b496cf69ff12f638f464ae0e85b89b1b999d06c56ad1c2bf026daaff1f3e4305fc72f16a169db135a34f32f3ace6a138551d2e8efba7e06b2fa
6
+ metadata.gz: 37d10f8888309fdda4b16e4b2d621482ec0880c35e5226d31b2cbad4a59332d8587b59a422eae818afb3da765be73535044b960c181f97c84167775710565aa3
7
+ data.tar.gz: cfef8bdb0e0d66b00b1fdb982567f4c574988279c1e51aeafd5e00773839517476fb2de51be67441ceb0da6ce7410c5c28703dadc621d7d536e1030e98371242
@@ -11,25 +11,16 @@ 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
26
26
  end
27
-
28
- # game = Game.new(User.new("kirill"), { attempts: 5, hints: 1 })
29
- # print game.respond_to_guess(game, "2211", [1,2,3,4])
30
- # print game.respond_to_guess(game, "2222", [2,2,2,4])
31
- # print game.respond_to_guess(game, "2221", [1,2,3,2])
32
- # print game.respond_to_guess(game, "1212", [2,1,2,1])
33
- # print game.respond_to_guess(game, "6666", [1,1,1,1])
34
- # print game.respond_to_guess(game, "6666", [6,6,6,6])
35
- # print game.respond_to_guess(game, "2222", [1,2,3,4])
@@ -4,23 +4,19 @@ module GuessHandler
4
4
  def respond_to_guess(game, input, code)
5
5
  @result = []
6
6
  @numbers = input.split('').map(&:to_i)
7
- @code_clone = code.clone
8
-
9
7
  return 'win' if @numbers == code
10
8
 
11
- assess_guess(code, @numbers, '+')
12
- assess_guess(@code_clone.sort, @numbers.sort, '-')
13
-
14
- game.attempts[:available] -= 1
9
+ assess_guess(code, @numbers)
15
10
  game.attempts[:used] += 1
16
- game.attempts[:available].zero? ? 'loss' : @result.sort
11
+ game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort
17
12
  end
18
13
 
19
- def assess_guess(code, input, method)
20
- input.each_with_index do |element, index|
21
- if element == code[index]
22
- @result << method
23
- @code_clone[index] = 7
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))
24
20
  end
25
21
  end
26
22
  end
@@ -3,5 +3,5 @@
3
3
  require_relative 'game'
4
4
 
5
5
  module CodebreakerKirill
6
- VERSION = '0.2.10'
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.10
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-16 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: