codebreaker_kirill 0.2.11 → 0.2.12

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: b56e6128500cf9b60f533450600297dd84435d87473fa09a932d17c53ca0df10
4
- data.tar.gz: cc1517ccf27ea8e363a1250d8ee07f47dc4004c1a9ad25777f2812fe0dbbd9d8
3
+ metadata.gz: 0ec08f93cc594d4d2bba8f889b64239f032cc6a4c80fb9dab8b662937da56db0
4
+ data.tar.gz: 937f0f2cbec8314935a1a08f856b9d965fb86b83541d7f2b183f2f3fa1c90247
5
5
  SHA512:
6
- metadata.gz: 37d10f8888309fdda4b16e4b2d621482ec0880c35e5226d31b2cbad4a59332d8587b59a422eae818afb3da765be73535044b960c181f97c84167775710565aa3
7
- data.tar.gz: cfef8bdb0e0d66b00b1fdb982567f4c574988279c1e51aeafd5e00773839517476fb2de51be67441ceb0da6ce7410c5c28703dadc621d7d536e1030e98371242
6
+ metadata.gz: 730e044734ce4b4308a00f426b0c17081a98e7b86d894257350863ca6c234ab191bf5723e8b3fcd49a6881f33571324d6063f81ab68c8ad55ea40c1d9563d6d4
7
+ data.tar.gz: 92e0936a01317cfe7452e6c6c97c89c44ef53e2c56d82e8946e3e947ce57f0378fe8364a39940b00cc9dec0458479e77cfe63d47f58e299c7768f367577aee5b
@@ -24,3 +24,14 @@ class Game
24
24
  @secret_code[@hints[:used]]
25
25
  end
26
26
  end
27
+
28
+ game = Game.new(User.new("kirill"), { attempts: 10, hints: 2 })
29
+ print game.respond_to_guess(game, "2222", [1,2,3,4]) # +
30
+ print game.respond_to_guess(game, "2222", [2,2,2,4]) # +++
31
+ print game.respond_to_guess(game, "2211", [1,2,3,4]) # +-
32
+ print game.respond_to_guess(game, "2221", [1,2,3,2]) # +--
33
+ print game.respond_to_guess(game, "1212", [2,1,2,1]) # ----
34
+ print game.respond_to_guess(game, "6666", [1,1,1,1]) # []
35
+ print game.respond_to_guess(game, "6666", [6,6,6,6]) # win
36
+ print game.respond_to_guess(game, "1234", [5,3,6,3]) # -
37
+ print game.respond_to_guess(game, "5363", [1,2,3,4]) # -
@@ -3,19 +3,20 @@
3
3
  module GuessHandler
4
4
  def respond_to_guess(game, input, code)
5
5
  @result = []
6
+ @code_clone = code.clone
6
7
  @numbers = input.split('').map(&:to_i)
7
8
  return 'win' if @numbers == code
8
9
 
9
- assess_guess(code, @numbers)
10
+ assess_guess(@code_clone, @numbers)
10
11
  game.attempts[:used] += 1
11
12
  game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort
12
13
  end
13
14
 
14
15
  def assess_guess(code, input)
15
- input.each_with_index { |element, index| code[index] = '+' if element == code[index] }
16
+ input.each_with_index { |element, index| @code_clone[index] = '+' if element == @code_clone[index] }
16
17
  @result = code.each_with_index do |el, index|
17
18
  if input.include?(el)
18
- code[index] = '-'
19
+ @code_clone[index] = '-'
19
20
  input.slice!(@numbers.index(el))
20
21
  end
21
22
  end
@@ -3,5 +3,5 @@
3
3
  require_relative 'game'
4
4
 
5
5
  module CodebreakerKirill
6
- VERSION = '0.2.11'
6
+ VERSION = '0.2.12'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kirill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Dudchenko