GemCodebreaker 0.1.4 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16e8e3dbf49182224e2127be71cd4b430e55a8817ae112fd50d55c3d7285ad45
4
- data.tar.gz: 7d7ebf51ddae2e20888007f15d0bc378aeeeab190b96fff5c6f198d5f95f32c8
3
+ metadata.gz: d387ad1e4ffd7b5f742c61768832b940267eabd5ffbfb920acb57debc5c84492
4
+ data.tar.gz: e8faf1b025e53f99585212d4264d99296d008b3696b96f8df3b8053a993b9c52
5
5
  SHA512:
6
- metadata.gz: 6d544d9801d2e5fd6255b2510267f31e6d2c3458e0aa5a3e65a62476a608f19a823d6ac0e516a30bedc5da7ff0a50fe5071bd879525609d306550235b6aecbb9
7
- data.tar.gz: b8b738055dc4869d91fb39235c17a03d61cc5c5e435a6d779a2100fd3f177ad405e98484aeb307690e4c8c795282994bdff655cd96ed11de4f7e269a1ddaebf2
6
+ metadata.gz: a2faa57d32240522392f40efe51240956609e36253142163d71ca2d7625711a1c460a8e82ed8a02734b48c0a1cd83d9bd69c67ebd8c4248f39b8fa2d5424cc9f
7
+ data.tar.gz: 26b9a4e0280a7ef4e0580c0139e086d8433cfb5a9e9ff6b5293ab327841c73495411fcd3a8832b22096f4634530772e5ffa097fbcdb97b174264afde19d4aed1
@@ -3,7 +3,7 @@ version: 2.1
3
3
  executors:
4
4
  default:
5
5
  working_directory: ~/codebreaker
6
- description: Gem for codebreaker game
6
+ description: Gem for game codebreaker
7
7
  docker:
8
8
  - image: circleci/ruby:2.7.1
9
9
 
@@ -30,6 +30,9 @@ commands:
30
30
  - run:
31
31
  name: rubocop
32
32
  command: bundle exec rubocop
33
+ - run:
34
+ name: fasterer
35
+ command: bundle exec fasterer
33
36
  run_specs:
34
37
  description: Run specs
35
38
  steps:
@@ -0,0 +1,21 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
20
+ exclude_paths:
21
+ - 'vendor/**/*.rb'
data/.gitignore CHANGED
@@ -8,5 +8,4 @@
8
8
  /tmp/
9
9
 
10
10
  .rspec_status
11
- Gemfile.lock
12
11
  .idea
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ GemCodebreaker (0.1.8)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ colorize (0.8.1)
11
+ concurrent-ruby (1.1.6)
12
+ diff-lcs (1.3)
13
+ docile (1.3.2)
14
+ fasterer (0.8.3)
15
+ colorize (~> 0.7)
16
+ ruby_parser (>= 3.14.1)
17
+ i18n (1.8.3)
18
+ concurrent-ruby (~> 1.0)
19
+ parallel (1.19.2)
20
+ parser (2.7.1.3)
21
+ ast (~> 2.4.0)
22
+ rainbow (3.0.0)
23
+ rake (13.0.1)
24
+ rexml (3.2.4)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.1)
38
+ rubocop (0.84.0)
39
+ parallel (~> 1.10)
40
+ parser (>= 2.7.0.1)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ rexml
43
+ rubocop-ast (>= 0.0.3)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (0.0.3)
47
+ parser (>= 2.7.0.1)
48
+ rubocop-rspec (1.41.0)
49
+ rubocop (>= 0.68.1)
50
+ ruby-progressbar (1.10.1)
51
+ ruby_parser (3.14.2)
52
+ sexp_processor (~> 4.9)
53
+ sexp_processor (4.15.0)
54
+ simplecov (0.18.5)
55
+ docile (~> 1.1)
56
+ simplecov-html (~> 0.11)
57
+ simplecov-html (0.12.2)
58
+ unicode-display_width (1.7.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ GemCodebreaker!
65
+ fasterer (~> 0.8.3)
66
+ i18n (~> 1.8.3)
67
+ rake (~> 13.0.1)
68
+ rspec (~> 3.7.0)
69
+ rubocop (~> 0.84.0)
70
+ rubocop-rspec (~> 1.41.0)
71
+ simplecov (~> 0.18.5)
72
+
73
+ BUNDLED WITH
74
+ 2.1.4
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
1
+ #!/usr/bin/env ruby
2
2
 
3
- # !/usr/bin/env ruby
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'bundler/setup'
6
- require 'GemCodebreaker'
6
+ require 'GemCodebreaker/gem_codebreaker'
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
@@ -32,7 +32,7 @@ module GemCodebreaker
32
32
  @game_code.each do |secret_code_item|
33
33
  if @user_code.include?(secret_code_item)
34
34
  @minus_match += 1
35
- @user_code.delete(secret_code_item)
35
+ @user_code.delete_at(@user_code.index(secret_code_item))
36
36
  else
37
37
  @empty_match += 1
38
38
  end
@@ -3,18 +3,16 @@
3
3
  module GemCodebreaker
4
4
  # Game class
5
5
  class Game
6
- LENGTH_OF_SECRET_CODE = (1..4).freeze
6
+ LENGTH_OF_SECRET_CODE = 4
7
7
  DIGIT_RANGE = (1..6).freeze
8
8
 
9
9
  include GameConfigurations
10
10
  include Validator
11
- attr_reader :attempts, :hints, :secrete_code, :statistic, :matcher_hash
11
+ attr_reader :secrete_code, :statistic, :matcher_hash
12
12
  attr_accessor :config
13
13
 
14
14
  def initialize(user, level)
15
15
  @config = GameConfig.new(user, level.to_sym)
16
- @attempts = @config.user_attempts
17
- @hints = @config.user_hints
18
16
  @statistic = []
19
17
  end
20
18
 
@@ -23,20 +21,20 @@ module GemCodebreaker
23
21
  end
24
22
 
25
23
  def generate_secret_code
26
- @secrete_code = LENGTH_OF_SECRET_CODE.map { rand DIGIT_RANGE }
24
+ @secrete_code = (1..LENGTH_OF_SECRET_CODE).map { rand DIGIT_RANGE }
27
25
  end
28
26
 
29
27
  def guess_valid?(user_code)
30
28
  validate_string(user_code)
31
- validate_guess_length if user_code.length != LENGTH_OF_SECRET_CODE.to_a.length
29
+ validate_guess_length if user_code.length != LENGTH_OF_SECRET_CODE
32
30
  validate_chars_range unless user_code[/\A[1-6]{4}\z/]
33
31
  true
34
32
  end
35
33
 
36
34
  def guess_start(input_code)
37
- validate_number_of_attempts if @attempts >= @config.max_attempts
35
+ validate_number_of_attempts if @config.user_attempts >= @config.max_attempts
38
36
 
39
- @attempts += 1
37
+ @config.user_attempts += 1
40
38
  user_code = convert_string_to_array(input_code)
41
39
  code_marker = CodeMaker.new(@secrete_code, user_code)
42
40
  code_marker.calculate_result_code
@@ -44,27 +42,27 @@ module GemCodebreaker
44
42
  end
45
43
 
46
44
  def win_game?
47
- @matcher_hash[:plus] == LENGTH_OF_SECRET_CODE.to_a.last
45
+ @matcher_hash[:plus] == LENGTH_OF_SECRET_CODE
48
46
  end
49
47
 
50
48
  def game_over?
51
- (@attempts >= @config.max_attempts) && win_game? == false
49
+ (@config.user_attempts >= @config.max_attempts) && win_game? == false
52
50
  end
53
51
 
54
52
  def hints_used?
55
- @hints >= @config.max_hints
53
+ @config.user_hints >= @config.max_hints
56
54
  end
57
55
 
58
56
  def hint
59
57
  validate_number_of_hints if hints_used?
60
58
 
61
- @hints += 1
59
+ @config.user_hints += 1
62
60
  @secrete_code.sample
63
61
  end
64
62
 
65
63
  def reset
66
- @attempts = 0
67
- @hints = 0
64
+ @config.user_attempts = 0
65
+ @config.user_hints = 0
68
66
  generate_secret_code
69
67
  end
70
68
 
@@ -4,15 +4,13 @@ module GemCodebreaker
4
4
  # Configuration class for game
5
5
  class GameConfig
6
6
  include GameConfigurations
7
- attr_reader :user_attempts, :user_hints, :difficulty_priority
8
- attr_accessor :user_nick_name, :difficulty, :max_attempts, :max_hints
7
+ attr_accessor :user_nick_name, :difficulty, :max_attempts, :max_hints, :user_attempts, :user_hints
9
8
 
10
9
  def initialize(user, level)
11
10
  @user_nick_name = user.nick_name
12
11
  @difficulty = level
13
12
  @max_attempts = GAME_LEVEL[level][:attempts]
14
13
  @max_hints = GAME_LEVEL[level][:hints]
15
- @difficulty_priority = GAME_LEVEL_PRIORITY[level]
16
14
  @user_attempts = 0
17
15
  @user_hints = 0
18
16
  end
@@ -3,17 +3,15 @@
3
3
  module GemCodebreaker
4
4
  # Game statistic class
5
5
  class GameStatistic
6
- attr_reader :user_nickname, :difficulty, :attempts_total, :attempts_used, :hints_total, :hints_used,
7
- :difficulty_priority
6
+ attr_reader :user_nickname, :difficulty, :attempts_total, :attempts_used, :hints_total, :hints_used
8
7
 
9
8
  def initialize(game)
10
9
  @user_nickname = game.config.user_nick_name
11
10
  @difficulty = game.config.difficulty
12
11
  @attempts_total = game.config.max_attempts
13
- @attempts_used = game.attempts
12
+ @attempts_used = game.config.user_attempts
14
13
  @hints_total = game.config.max_hints
15
- @hints_used = game.hints
16
- @difficulty_priority = game.config.difficulty_priority
14
+ @hints_used = game.config.user_hints
17
15
  end
18
16
  end
19
17
  end
@@ -20,5 +20,4 @@ require 'GemCodebreaker/classes/game'
20
20
 
21
21
  module GemCodebreaker
22
22
  class Error < StandardError; end
23
- # Your code goes here...
24
23
  end
@@ -14,9 +14,5 @@ module GemCodebreaker
14
14
  strong_hell:
15
15
  { attempts: 1,
16
16
  hints: 0 } }.freeze
17
- GAME_LEVEL_PRIORITY = { easy: 4,
18
- medium: 3,
19
- hell: 2,
20
- strong_hell: 1 }.freeze
21
17
  end
22
18
  end
@@ -5,7 +5,7 @@ module GemCodebreaker
5
5
  module SerializerDeserializer
6
6
  FILE_NAME = 'game_statistic.yml'
7
7
  STATISTIC_DIR = 'data'
8
- STORAGE_PATH = File.expand_path("./#{STATISTIC_DIR}/#{FILE_NAME}", File.dirname(__FILE__))
8
+ STORAGE_PATH = File.expand_path("./#{STATISTIC_DIR}/#{FILE_NAME}")
9
9
 
10
10
  def data_dir_get
11
11
  data_directory = File.dirname(STORAGE_PATH)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemCodebreaker
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GemCodebreaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -116,14 +116,16 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".circleci/config.yml"
119
+ - ".fasterer.yml"
119
120
  - ".gitignore"
120
121
  - ".rspec"
121
122
  - ".rubocop.yml"
122
123
  - GemCodebreaker.gemspec
123
124
  - Gemfile
125
+ - Gemfile.lock
124
126
  - LICENSE.txt
125
127
  - README.md
126
- - bin/console.rb
128
+ - bin/console
127
129
  - bin/setup
128
130
  - lib/GemCodebreaker/classes/codemaker.rb
129
131
  - lib/GemCodebreaker/classes/game.rb