codebreaker_mats 0.1.6 → 0.1.7
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 +4 -4
- data/{.faterer.yml → .fasterer.yml} +0 -0
- data/.gitignore +1 -1
- data/.ruby-version +1 -0
- data/.vscode/settings.json +3 -0
- data/Gemfile.lock +1 -1
- data/lib/codebreaker_mats.rb +1 -0
- data/lib/codebreaker_mats/game.rb +10 -11
- data/lib/codebreaker_mats/matcher.rb +6 -11
- data/lib/codebreaker_mats/stats.rb +7 -0
- data/lib/codebreaker_mats/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74b59c5dab491b3c3d84f1ae88fb51125d1f33772914105c1fda51eae0d7d51b
|
|
4
|
+
data.tar.gz: 4a61c0f3769f633a0f773f832f627c3a32b18b49b9b44ad13e69a629a1eedd6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a30146aef88d4aa563079006a768575849321b6379a12b961a3216b250339a5f6e2073dc8abc8004059d5c5abb1a5116dff6b3a4a70a953a7619c5a81000433
|
|
7
|
+
data.tar.gz: a0e84a3c8fe6f4136f69dd790b3ee5f42cc711ab3b756c953d5e29027fd28d99f86e30e71f94154a2fdd21fa48b169f0816f01eb830ff6a6e6160e2a934df2db
|
|
File without changes
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby 2.7.1
|
data/Gemfile.lock
CHANGED
data/lib/codebreaker_mats.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
module Codebreaker
|
|
2
2
|
class Game
|
|
3
|
+
include Stats
|
|
3
4
|
CODE_RANGE_MIN = 1
|
|
4
5
|
CODE_RANGE_MAX = 6
|
|
5
6
|
COUNT_OF_NUMBER = 4
|
|
@@ -50,19 +51,17 @@ module Codebreaker
|
|
|
50
51
|
status == :lost
|
|
51
52
|
end
|
|
52
53
|
|
|
53
|
-
def
|
|
54
|
-
|
|
54
|
+
def save_stat(stat_file)
|
|
55
|
+
save_stat_in_file(stat_file, stats_hash)
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
def
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
hints_used: @number_of_hints - @hints_left }.to_yaml)
|
|
65
|
-
end
|
|
58
|
+
def stats_hash
|
|
59
|
+
{ user: @user,
|
|
60
|
+
difficulty: @difficulty,
|
|
61
|
+
attempts: @number_of_attempts,
|
|
62
|
+
attempts_used: @number_of_attempts - @attempts_left,
|
|
63
|
+
hints: @number_of_hints,
|
|
64
|
+
hints_used: @number_of_hints - @hints_left }
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
def set_difficulty(diff, attempts, hints)
|
|
@@ -5,10 +5,8 @@ module Codebreaker
|
|
|
5
5
|
# of bulls and cows in the guess.
|
|
6
6
|
class Matcher
|
|
7
7
|
attr_reader :marker, :secret_code_hash
|
|
8
|
-
attr_reader :exact_matches, :all_matches, :bulls, :cows
|
|
9
8
|
def initialize(marker = Markers::PlusMinusMarker.new)
|
|
10
9
|
@marker = marker
|
|
11
|
-
@secret_code_hash = hash_with_default_array_value
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def secret_code=(secret_code)
|
|
@@ -18,11 +16,11 @@ module Codebreaker
|
|
|
18
16
|
def match?(guess)
|
|
19
17
|
match(array_to_hash_of_positions(unify_code(guess)))
|
|
20
18
|
|
|
21
|
-
bulls == 4
|
|
19
|
+
@bulls == 4
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
def marks
|
|
25
|
-
marker.mark(bulls, cows)
|
|
23
|
+
marker.mark(@bulls, @cows)
|
|
26
24
|
end
|
|
27
25
|
|
|
28
26
|
private
|
|
@@ -33,17 +31,14 @@ module Codebreaker
|
|
|
33
31
|
|
|
34
32
|
def array_to_hash_of_positions(array)
|
|
35
33
|
array
|
|
36
|
-
.each_with_object(
|
|
34
|
+
.each_with_object({})
|
|
37
35
|
.with_index do |(digit, hash), position|
|
|
36
|
+
hash[digit] ||= []
|
|
38
37
|
hash[digit].push(position)
|
|
39
38
|
hash
|
|
40
39
|
end
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
def hash_with_default_array_value
|
|
44
|
-
Hash.new { |h, digit| h[digit] = [] }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
42
|
def match(guess_hash)
|
|
48
43
|
@exact_matches = 0
|
|
49
44
|
@all_matches = 0
|
|
@@ -55,8 +50,8 @@ module Codebreaker
|
|
|
55
50
|
add_all_matches(digit, positions)
|
|
56
51
|
end
|
|
57
52
|
|
|
58
|
-
@bulls = exact_matches
|
|
59
|
-
@cows = all_matches - exact_matches
|
|
53
|
+
@bulls = @exact_matches
|
|
54
|
+
@cows = @all_matches - @exact_matches
|
|
60
55
|
end
|
|
61
56
|
|
|
62
57
|
def digit_is_not_present_in_the_secret_code(digit)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: codebreaker_mats
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: The app provides core for codebreaker game
|
|
14
14
|
email:
|
|
@@ -18,10 +18,12 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- ".circleci/config.yml"
|
|
21
|
-
- ".
|
|
21
|
+
- ".fasterer.yml"
|
|
22
22
|
- ".gitignore"
|
|
23
23
|
- ".rspec"
|
|
24
24
|
- ".rubocop.yml"
|
|
25
|
+
- ".ruby-version"
|
|
26
|
+
- ".vscode/settings.json"
|
|
25
27
|
- CODE_OF_CONDUCT.md
|
|
26
28
|
- Gemfile
|
|
27
29
|
- Gemfile.lock
|
|
@@ -36,6 +38,7 @@ files:
|
|
|
36
38
|
- lib/codebreaker_mats/game.rb
|
|
37
39
|
- lib/codebreaker_mats/markers/plus_minus_marker.rb
|
|
38
40
|
- lib/codebreaker_mats/matcher.rb
|
|
41
|
+
- lib/codebreaker_mats/stats.rb
|
|
39
42
|
- lib/codebreaker_mats/version.rb
|
|
40
43
|
homepage: https://github.com/Swooty18/codebreaker_mats.git
|
|
41
44
|
licenses:
|