codebreaker_kub 0.1.5 → 0.2.1

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: 6aa6161d8be7c590c8a807a683156215848be657e0c20c26910800cb45ccb7c4
4
- data.tar.gz: 6363e20f9c4e98ae178abcaf645e0a419fdb100df9b94ed8e643752d9d0a0cda
3
+ metadata.gz: f04c487aaa2731e942ffff6cb60ef16d1104251d00bb9983a6e7d91c103b7169
4
+ data.tar.gz: 4b505fe8bfe8a2e60e0f3915db5f3e4afe8175f06812602d4f1d972c9dcb31f4
5
5
  SHA512:
6
- metadata.gz: 5430b81b877be660d4df7d348b5ff5c48716ea842cdad4c663c894ed6f8f34e41add7a6887b9e9163df18ed6050bcf20d0de126585359fac7c3313d29d2cc1f3
7
- data.tar.gz: 5e0e9ba6eebc83565d0295adee5a481b49852237662796e920cbe3fa8ad5e9ceb015e6a5bf9f241e7c5cbbfad7e826ad1c10288d91df1df7eb824327a5d2e3d9
6
+ metadata.gz: f4479ce9fa5fc088e8acdacc83756ea2842711fcc410f7885df6a70461906df3d9bbad0c0fe8f54df0ec98afe14d83f7574fbdd9d2b77c7ab7644da3f56481d9
7
+ data.tar.gz: 24ef175cf81346eb5a3eb83553ac0e31ea77cb95e09502c3428e4cba77413d1ec55eeb578502bcd1b423d3e02fc9cceac6f622f15ed7fdfc19c77ce7af205141
@@ -0,0 +1,57 @@
1
+ version: 2.1
2
+
3
+ executors:
4
+ default:
5
+ working_directory: ~/repo
6
+ description: The official CircleCI Ruby Docker image
7
+ docker:
8
+ - image: circleci/ruby:2.7.0
9
+ caches:
10
+ - &bundle_cache v1-repo-{{ checksum "Gemfile.lock" }}
11
+ commands:
12
+ run_linters:
13
+ description: command to start linters
14
+ steps:
15
+ - run:
16
+ name: rubocop
17
+ command: bundle exec rubocop
18
+ run_specs:
19
+ steps:
20
+ - run:
21
+ name: run specs
22
+ command: |
23
+ mkdir /tmp/test-results
24
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
25
+ bundle exec rspec --format progress \
26
+ --out /tmp/test-results/rspec.xml \
27
+ $TEST_FILES
28
+ setup_environment:
29
+ steps:
30
+ - checkout
31
+ - restore_cache:
32
+ key: *bundle_cache
33
+ - run: bundle install --path vendor/bundle
34
+ - save_cache:
35
+ key: *bundle_cache
36
+ paths:
37
+ - vendor/bundle
38
+ jobs:
39
+ lintering:
40
+ executor: default
41
+ steps:
42
+ - setup_environment
43
+ - run_linters
44
+ run_specs:
45
+ executor: default
46
+ steps:
47
+ - setup_environment
48
+ - run_specs
49
+
50
+ workflows:
51
+ version: 2
52
+ build:
53
+ jobs:
54
+ - lintering
55
+ - run_specs:
56
+ requires:
57
+ - lintering
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  .rvmrc
2
- .rspec_status
3
2
  /coverage/
4
- /pkg/
3
+ .rspec_status
@@ -7,9 +7,6 @@ Style/Documentation:
7
7
  Layout/LineLength:
8
8
  Max: 110
9
9
 
10
- Style/FrozenStringLiteralComment:
11
- Enabled: false
12
-
13
10
  Metrics/BlockLength:
14
11
  Enabled: false
15
12
 
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in codebreaker.gemspec
4
6
  gemspec
5
-
6
- gem 'rake', '~> 12.0'
7
- gem 'rspec', '~> 3.0'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_kub (0.1.5)
4
+ codebreaker_kub (0.1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -65,7 +65,7 @@ DEPENDENCIES
65
65
  fasterer (~> 0.8)
66
66
  i18n (~> 1.8)
67
67
  rake (~> 12.0)
68
- rspec (~> 3.0)
68
+ rspec (~> 3.9)
69
69
  rubocop (~> 0.87)
70
70
  simplecov (~> 0.18)
71
71
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'codebreaker'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/codebreaker/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -28,6 +30,7 @@ Gem::Specification.new do |spec|
28
30
 
29
31
  spec.add_development_dependency 'fasterer', '~>0.8'
30
32
  spec.add_development_dependency 'i18n', '~>1.8'
33
+ spec.add_development_dependency 'rake', '~> 12.0'
31
34
  spec.add_development_dependency 'rspec', '~>3.9'
32
35
  spec.add_development_dependency 'rubocop', '~>0.87'
33
36
  spec.add_development_dependency 'simplecov', '~>0.18'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'codebreaker/game'
2
4
  require_relative 'codebreaker/loader'
3
5
  require_relative 'codebreaker/output'
@@ -5,6 +5,7 @@
5
5
  - Load game statistics - puts 'stats'\n
6
6
  - Exit from game - puts 'exit'\n"
7
7
  goodbye: "Bye bye!\n"
8
+ available_commands: "Enter 'start', 'rules', 'stats' or 'exit'"
8
9
  rules: "GAME RULES:\n
9
10
  # Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. The\n codemaker, which will be played by the application we’re going to write, creates a secret code.\n
10
11
  # The codebreaker gets some number of chances to break the code (depends on chosen difficulty). In each turn, the\n codebreaker makes a guess. The codemaker then marks the guess with special symbols.\n
@@ -18,11 +19,11 @@
18
19
  wrong_difficulty: "There is no such level. Select from available, please"
19
20
  get_hint: "You can choose get hint - puts 'hint'"
20
21
  no_hints: "You have no hints"
22
+ enter_guess: "Enter your guess, please"
21
23
  wrong_input: "Your input is invalid or there is no such command."
22
24
  win: "YOU WIN!"
23
25
  lose: "You lose, sorry("
24
26
  code: "The code was: "
25
27
  no_stats: "Sorry, you have not any statistic yet"
26
28
  save_result: "Do you want to save result y/n"
27
- game_over: "GAME OVER"
28
29
 
@@ -1,10 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Codebreaker
2
4
  class Game
5
+ CODE_LENGTH = 4
6
+ CODE_RANGE = (1..6).freeze
3
7
  attr_accessor :input_code, :code, :name, :difficulties, :difficulty, :hints_left, :attempts_left
4
-
8
+ attr_reader :minuse, :plus, :none
5
9
  def initialize
6
10
  @difficulties = Codebreaker::Loader.load('difficulties')
7
11
  @code = generate_code
12
+ symbols
13
+ end
14
+
15
+ def symbols(minuse = '-', plus = '+', none = '')
16
+ @minuse = minuse
17
+ @plus = plus
18
+ @none = none
8
19
  end
9
20
 
10
21
  def game_option(name, difficulty)
@@ -42,7 +53,7 @@ module Codebreaker
42
53
  end
43
54
 
44
55
  def save
45
- Codebreaker::Loader.save(to_h, 'stat')
56
+ Codebreaker::Loader.save(to_h, 'stats')
46
57
  end
47
58
 
48
59
  private
@@ -50,19 +61,22 @@ module Codebreaker
50
61
  def check_input(code = @code.chars)
51
62
  input = @input_code.chars
52
63
  minuses = (code & input).map { |element| [code.count(element), input.count(element)].min }.sum
53
- result = '-' * minuses
64
+ result = @minuse * minuses
54
65
  input.each.with_index do |element, index|
55
- result.sub!('-', '+') if element == code[index]
66
+ result.sub!(@minuse, @plus) if element == code[index]
56
67
  end
57
- result
68
+ return result unless result.empty?
69
+
70
+ @none
58
71
  end
59
72
 
60
73
  def generate_code
61
- Array.new(4) { rand(1..6) }.join
74
+ Array.new(CODE_LENGTH) { rand(CODE_RANGE) }.join
62
75
  end
63
76
 
64
77
  def generate_hint
65
- @code.chars.shuffle.pop
78
+ hint_code = @code.chars.shuffle
79
+ hint_code.pop
66
80
  end
67
81
 
68
82
  def difficulty_option
@@ -76,9 +90,8 @@ module Codebreaker
76
90
  attempts: difficulty_option[:attempts],
77
91
  hints: difficulty_option[:hints],
78
92
  code: @code,
79
- attempts_left: @attempts_left,
80
- hints_left: @hints_left,
81
- win: win?
93
+ used_attempts: difficulty_option[:attempts] - @attempts_left,
94
+ used_hints: difficulty_option[:hints] - @hints_left
82
95
  }
83
96
  end
84
97
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Codebreaker
2
4
  module Loader
3
5
  PATH = File.join(File.dirname(__FILE__), 'data/').freeze
4
- EXTENCTION = '.yml'.freeze
6
+ EXTENCTION = '.yml'
5
7
  def self.load(file_name)
6
8
  file_name = PATH + file_name + EXTENCTION.to_s
7
9
  if File.exist?(file_name)
@@ -1,14 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Codebreaker
2
4
  class Output
5
+ attr_reader :stats
3
6
  def initialize
4
7
  I18n.load_path << Dir[File.expand_path(File.join(File.dirname(__FILE__), 'data/locales/')) + '/*.yml']
5
8
  I18n.config.available_locales = :en
9
+ @stats = Codebreaker::Loader.load('stats')
6
10
  end
7
11
 
8
12
  def greeting
9
13
  puts I18n.t(:hey)
10
14
  end
11
15
 
16
+ def available_commands
17
+ puts I18n.t(:available_commands)
18
+ end
19
+
12
20
  def choose_name
13
21
  puts I18n.t(:choose_name)
14
22
  end
@@ -21,12 +29,23 @@ module Codebreaker
21
29
  puts I18n.t(:rules)
22
30
  end
23
31
 
32
+ def sort_stats
33
+ @stats = @stats.sort_by do |game|
34
+ [game[:attempts], game[:used_attempts],
35
+ game[:used_hints]]
36
+ end
37
+ end
38
+
24
39
  def show_stats
25
- stats.each do |game|
40
+ sort_stats
41
+ @stats.each_with_index do |game, index|
26
42
  puts "Hey, #{game[:name]}
27
- Chosen difficulty: #{game[:difficulty]}
43
+ Rating: #{index + 1}
28
44
  Attempts: #{game[:attempts]}
29
- Hints: #{game[:hints]}"
45
+ Hints: #{game[:hints]}
46
+ Chosen difficulty: #{game[:difficulty]}
47
+ Used attempts: #{game[:used_attempts]}
48
+ Used hints: #{game[:used_hints]}"
30
49
  end
31
50
  end
32
51
 
@@ -40,7 +59,6 @@ module Codebreaker
40
59
 
41
60
  def no_hints
42
61
  puts I18n.t(:no_hints)
43
- puts I18n.t(:code)
44
62
  end
45
63
 
46
64
  def choose_difficulty
@@ -51,6 +69,10 @@ module Codebreaker
51
69
  puts I18n.t(:wrong_difficulty)
52
70
  end
53
71
 
72
+ def enter_guess
73
+ puts I18n.t(:enter_guess)
74
+ end
75
+
54
76
  def wrong_input
55
77
  puts I18n.t(:wrong_input)
56
78
  end
@@ -61,6 +83,7 @@ module Codebreaker
61
83
 
62
84
  def lose
63
85
  puts I18n.t(:lose)
86
+ puts I18n.t(:code)
64
87
  end
65
88
 
66
89
  def save_result
@@ -70,9 +93,5 @@ module Codebreaker
70
93
  def goodbye
71
94
  puts I18n.t(:goodbye)
72
95
  end
73
-
74
- def game_over
75
- puts I18n.t(:game_over)
76
- end
77
96
  end
78
97
  end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Codebreaker
2
4
  module Validation
5
+ MIN_NAME_LENGTH = 3
6
+ MAX_NAME_LENGTH = 20
3
7
  def name_is_valid?(name)
4
- name.instance_of?(String) && name.length.between?(3, 20)
8
+ name.instance_of?(String) && name.length.between?(MIN_NAME_LENGTH, MAX_NAME_LENGTH)
5
9
  end
6
10
 
7
11
  def input_is_valid?(input)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Codebreaker
2
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.2.1'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - katia kub
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +101,10 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
104
+ - ".circleci/config.yml"
90
105
  - ".fasterer.yml"
91
106
  - ".gitignore"
92
107
  - ".overcommit.yml"
93
- - ".rspec_status"
94
108
  - ".rubocop.yml"
95
109
  - ".ruby-version"
96
110
  - CODE_OF_CONDUCT.md