codebreaker_artem 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd99d3fb633085334c68785632f6767c2a168744
|
4
|
+
data.tar.gz: e55b8e107182619e3526d7bde7df41b731ba7e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32a7e7611a3f35650065cf0d1adc6b1a2f6a913daed4f6b816f38c12ac0333315ea6fdb6130570ac77165570a9d71617eb169e0085710c4bb46bcde8c623b3cf
|
7
|
+
data.tar.gz: 24ade59249028cc2e1ed52e04fed85f0cbf29a8af699ba3f452ba9de7576d7cf9aaf89b0a44b125380cd4296317a335131c20cadc06484dc6f25c17bc179eed8
|
@@ -31,7 +31,7 @@ module CodebreakerArtem
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def show_mark(mark)
|
34
|
-
puts mark
|
34
|
+
puts "Mark corresponding your guess: #{mark}"
|
35
35
|
end
|
36
36
|
|
37
37
|
def win(code, score)
|
@@ -49,7 +49,7 @@ module CodebreakerArtem
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def lose_msg(max_guess_number)
|
52
|
-
puts "
|
52
|
+
puts "\nGAME OVER. You've used all #{max_guess_number} attempts\n"
|
53
53
|
end
|
54
54
|
|
55
55
|
def finish_game(code, score)
|
@@ -7,11 +7,12 @@ module CodebreakerArtem
|
|
7
7
|
attr_reader :secret_code, :guess_count, :score
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
|
10
|
+
@guess_count = 0
|
11
|
+
@score = 0
|
12
|
+
@hint_available = true
|
11
13
|
end
|
12
14
|
|
13
15
|
def start
|
14
|
-
initial_values_set
|
15
16
|
generate_secret_code
|
16
17
|
end
|
17
18
|
|
@@ -19,8 +20,8 @@ module CodebreakerArtem
|
|
19
20
|
return false unless Validator.code_valid? guess
|
20
21
|
@guess_count += 1
|
21
22
|
counts = plus_minus_count(guess)
|
22
|
-
score_set(counts[
|
23
|
-
'' << ('+' * counts[
|
23
|
+
score_set(counts[:pluses], counts[:minuses])
|
24
|
+
'' << ('+' * counts[:pluses]) << ('-' * counts[:minuses])
|
24
25
|
end
|
25
26
|
|
26
27
|
def hint
|
@@ -32,23 +33,16 @@ module CodebreakerArtem
|
|
32
33
|
|
33
34
|
private
|
34
35
|
|
35
|
-
def initial_values_set
|
36
|
-
@guess_count = 0
|
37
|
-
@score = 0
|
38
|
-
@hint_available = true
|
39
|
-
end
|
40
|
-
|
41
36
|
def generate_secret_code
|
42
|
-
@secret_code =
|
43
|
-
4.times { @secret_code << rand(1..6).to_s }
|
37
|
+
@secret_code = Array.new(4) { rand(1..6) }.join
|
44
38
|
end
|
45
39
|
|
46
40
|
def plus_minus_count(guess)
|
41
|
+
return { pluses: 4, minuses: 0 } if @secret_code == guess
|
47
42
|
zipped = @secret_code.split('').zip(guess.split(''))
|
48
43
|
not_plus = zipped.delete_if { |item| item.uniq.one? }
|
49
|
-
return [4, 0] if not_plus.empty?
|
50
44
|
plus_count = 4 - not_plus.count
|
51
|
-
|
45
|
+
{ pluses: plus_count, minuses: minus_count(not_plus) }
|
52
46
|
end
|
53
47
|
|
54
48
|
def minus_count(not_plus)
|
@@ -3,7 +3,7 @@ require_relative 'cli'
|
|
3
3
|
|
4
4
|
module CodebreakerArtem
|
5
5
|
class Starter
|
6
|
-
MAX =
|
6
|
+
MAX = Game::MAX_GUESS_NUMBER
|
7
7
|
|
8
8
|
def self.start
|
9
9
|
game = CodebreakerArtem::Game.new
|
@@ -22,7 +22,7 @@ module CodebreakerArtem
|
|
22
22
|
else
|
23
23
|
mark = game.mark_guess(input)
|
24
24
|
CLI.show_mark(mark)
|
25
|
-
return CLI.win(input, game.score) if mark
|
25
|
+
return CLI.win(input, game.score) if Validator.win_mark?(mark)
|
26
26
|
end
|
27
27
|
return CLI.lose(game.secret_code, game.score, MAX) if game.guess_count >= MAX
|
28
28
|
end
|
data/lib/codebreaker_artem.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_artem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- b-artem
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|