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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ff4627a58b422bfa3ddb12eb95895884b4ba4825f5902bc8d3120a94048ab5e
4
- data.tar.gz: e290744852397fdc2d76c1490beb37946f2ce881b0e2d48f078b46e98eb68e14
3
+ metadata.gz: 74b59c5dab491b3c3d84f1ae88fb51125d1f33772914105c1fda51eae0d7d51b
4
+ data.tar.gz: 4a61c0f3769f633a0f773f832f627c3a32b18b49b9b44ad13e69a629a1eedd6e
5
5
  SHA512:
6
- metadata.gz: 4483a224c17951f96461b18f6b76740889a88e1bffc648cd001039df5dc33ef40e8c3910a09085854f6a95e643d5b506f2605710fe80823b5ccda3d2058c6304
7
- data.tar.gz: 4186fd5aedc97d2d626ad70072262b6487db3dc65268c8823b6188d14964678c52de4ada457f50ff68e8c92c556a8dbfca3cdc1ac0f3909d6e1326ae8176dce1
6
+ metadata.gz: 7a30146aef88d4aa563079006a768575849321b6379a12b961a3216b250339a5f6e2073dc8abc8004059d5c5abb1a5116dff6b3a4a70a953a7619c5a81000433
7
+ data.tar.gz: a0e84a3c8fe6f4136f69dd790b3ee5f42cc711ab3b756c953d5e29027fd28d99f86e30e71f94154a2fdd21fa48b169f0816f01eb830ff6a6e6160e2a934df2db
File without changes
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/
1
+ j/.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
@@ -0,0 +1 @@
1
+ ruby 2.7.1
@@ -0,0 +1,3 @@
1
+ {
2
+ "liveServer.settings.port": 5501
3
+ }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_mats (0.1.6)
4
+ codebreaker_mats (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
+ require_relative 'codebreaker_mats/stats'
3
4
  require_relative 'codebreaker_mats/version'
4
5
  require_relative 'codebreaker_mats/matcher'
5
6
  require_relative 'codebreaker_mats/game'
@@ -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 in_progress?
54
- status == :in_progress
54
+ def save_stat(stat_file)
55
+ save_stat_in_file(stat_file, stats_hash)
55
56
  end
56
57
 
57
- def save_stat(stat_file)
58
- File.open(stat_file, 'a+') do |f|
59
- f.write({ 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 }.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(hash_with_default_array_value)
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)
@@ -0,0 +1,7 @@
1
+ module Stats
2
+ def save_stat_in_file(stat_file, stats)
3
+ File.open(stat_file, 'a+') do |f|
4
+ f.write(stats.to_yaml)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module CodebreakerMats
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
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.6
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-07-31 00:00:00.000000000 Z
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
- - ".faterer.yml"
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: