codebreaker_kub 0.1.4 → 0.1.9

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: 103c3533b6fef9e09d8bc0a280e4fc1dcb297c0fb23e9c4a93d6c78c1be8f745
4
- data.tar.gz: 3efa75431774bc79977f5c7ff7a6c641ca0daed3ec670fe077965290e24528b6
3
+ metadata.gz: 785cfab5d2e074a0914b08aff16f83623f895eeaf4348bcc1e87c283b6b2d4da
4
+ data.tar.gz: 52cf47e5ea7c5c5421efa0b00d118f64db300e9a77b4c2002aecaa99a4d46ea7
5
5
  SHA512:
6
- metadata.gz: 6e6f8437d590d49ea4771525ec0de8db1e9ae68a773628bc1e9bee9e4f1bc0b456e5d4b600413cb404b27451c1c1552e39e94a8559306cdb149cc804778af06d
7
- data.tar.gz: 4702aaab9516a413e7211fe42954b458f9c83c46a19fc64297385bad449d52d5470d13acb2e9f7c2868ad0e07a03091ecaff096513a20b96f70355a890bf008f
6
+ metadata.gz: b01b8c3ccf2b578470405c70511f7f9d816f48f16a690cb44af0d05e4231268701021f0488909738a7893a4efe2cdab271e2f5aa12d079f032c9b7512d375523
7
+ data.tar.gz: 379731f286acf3d954d4c336acf7e1d72ba533102a548cbd7e7df66ff69bb100ec8363d9b5f722ff6c4fc1ec1dd26a8396adb776bb04bb7073cbb17a4585767a
@@ -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,2 +1,3 @@
1
1
  .rvmrc
2
2
  /coverage/
3
+ .rspec_status
@@ -5,7 +5,7 @@ Style/Documentation:
5
5
  Enabled: false
6
6
 
7
7
  Layout/LineLength:
8
- Max: 100
8
+ Max: 110
9
9
 
10
10
  Style/FrozenStringLiteralComment:
11
11
  Enabled: false
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in codebreaker.gemspec
4
4
  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.0.1)
4
+ codebreaker_kub (0.1.8)
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
 
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency 'fasterer', '~>0.8'
30
30
  spec.add_development_dependency 'i18n', '~>1.8'
31
+ spec.add_development_dependency 'rake', '~> 12.0'
31
32
  spec.add_development_dependency 'rspec', '~>3.9'
32
33
  spec.add_development_dependency 'rubocop', '~>0.87'
33
34
  spec.add_development_dependency 'simplecov', '~>0.18'
@@ -4,6 +4,4 @@ require_relative 'codebreaker/output'
4
4
  require_relative 'codebreaker/validation'
5
5
  require_relative 'codebreaker/version'
6
6
  require 'i18n'
7
- require 'open-uri'
8
7
  require 'yaml'
9
- game = Codebreaker::Output.new
@@ -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,17 @@
1
1
  module Codebreaker
2
2
  class Game
3
3
  attr_accessor :input_code, :code, :name, :difficulties, :difficulty, :hints_left, :attempts_left
4
-
4
+ attr_reader :minuse, :plus, :none
5
5
  def initialize
6
6
  @difficulties = Codebreaker::Loader.load('difficulties')
7
7
  @code = generate_code
8
+ symbols
9
+ end
10
+
11
+ def symbols(minuse = '-', plus = '+', none = '')
12
+ @minuse = minuse
13
+ @plus = plus
14
+ @none = none
8
15
  end
9
16
 
10
17
  def game_option(name, difficulty)
@@ -42,7 +49,7 @@ module Codebreaker
42
49
  end
43
50
 
44
51
  def save
45
- Codebreaker::Loader.save(to_h, 'stat')
52
+ Codebreaker::Loader.save(to_h, 'stats')
46
53
  end
47
54
 
48
55
  private
@@ -50,11 +57,13 @@ module Codebreaker
50
57
  def check_input(code = @code.chars)
51
58
  input = @input_code.chars
52
59
  minuses = (code & input).map { |element| [code.count(element), input.count(element)].min }.sum
53
- result = '-' * minuses
60
+ result = @minuse * minuses
54
61
  input.each.with_index do |element, index|
55
- result.sub!('-', '+') if element == code[index]
62
+ result.sub!(@minuse, @plus) if element == code[index]
56
63
  end
57
- result
64
+ return result unless result.empty?
65
+
66
+ @none
58
67
  end
59
68
 
60
69
  def generate_code
@@ -76,8 +85,8 @@ module Codebreaker
76
85
  attempts: difficulty_option[:attempts],
77
86
  hints: difficulty_option[:hints],
78
87
  code: @code,
79
- attempts_left: @attempts_left,
80
- hints_left: @hints_left,
88
+ used_attempts: difficulty_option[:attempts] - @attempts_left,
89
+ used_hints: difficulty_option[:hints] - @hints_left,
81
90
  win: win?
82
91
  }
83
92
  end
@@ -1,14 +1,20 @@
1
1
  module Codebreaker
2
2
  class Output
3
+ attr_reader :stats
3
4
  def initialize
4
5
  I18n.load_path << Dir[File.expand_path(File.join(File.dirname(__FILE__), 'data/locales/')) + '/*.yml']
5
6
  I18n.config.available_locales = :en
7
+ @stats = Codebreaker::Loader.load('stats')
6
8
  end
7
9
 
8
10
  def greeting
9
11
  puts I18n.t(:hey)
10
12
  end
11
13
 
14
+ def available_commands
15
+ puts I18n.t(:available_commands)
16
+ end
17
+
12
18
  def choose_name
13
19
  puts I18n.t(:choose_name)
14
20
  end
@@ -21,12 +27,23 @@ module Codebreaker
21
27
  puts I18n.t(:rules)
22
28
  end
23
29
 
30
+ def sort_stats
31
+ @stats = @stats.sort_by do |game|
32
+ [game[:attempts], game[:used_attempts],
33
+ game[:used_hints]]
34
+ end
35
+ end
36
+
24
37
  def show_stats
25
- stats.each do |game|
38
+ sort_stats
39
+ @stats.each_with_index do |game, index|
26
40
  puts "Hey, #{game[:name]}
27
- Chosen difficulty: #{game[:difficulty]}
41
+ Rating: #{index + 1}
28
42
  Attempts: #{game[:attempts]}
29
- Hints: #{game[:hints]}"
43
+ Hints: #{game[:hints]}
44
+ Chosen difficulty: #{game[:difficulty]}
45
+ Used attempts: #{game[:used_attempts]}
46
+ Used hints: #{game[:used_hints]}"
30
47
  end
31
48
  end
32
49
 
@@ -40,7 +57,6 @@ module Codebreaker
40
57
 
41
58
  def no_hints
42
59
  puts I18n.t(:no_hints)
43
- puts I18n.t(:code)
44
60
  end
45
61
 
46
62
  def choose_difficulty
@@ -51,6 +67,10 @@ module Codebreaker
51
67
  puts I18n.t(:wrong_difficulty)
52
68
  end
53
69
 
70
+ def enter_guess
71
+ puts I18n.t(:enter_guess)
72
+ end
73
+
54
74
  def wrong_input
55
75
  puts I18n.t(:wrong_input)
56
76
  end
@@ -61,6 +81,7 @@ module Codebreaker
61
81
 
62
82
  def lose
63
83
  puts I18n.t(:lose)
84
+ puts I18n.t(:code)
64
85
  end
65
86
 
66
87
  def save_result
@@ -70,9 +91,5 @@ module Codebreaker
70
91
  def goodbye
71
92
  puts I18n.t(:goodbye)
72
93
  end
73
-
74
- def game_over
75
- puts I18n.t(:game_over)
76
- end
77
94
  end
78
95
  end
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  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.4
4
+ version: 0.1.9
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-13 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
@@ -1,30 +0,0 @@
1
- example_id | status | run_time |
2
- ------------------------------------------ | ------ | --------------- |
3
- ./spec/codebreaker/game_spec.rb[1:1] | passed | 0.00066 seconds |
4
- ./spec/codebreaker/game_spec.rb[1:2] | passed | 0.00069 seconds |
5
- ./spec/codebreaker/game_spec.rb[1:3] | passed | 0.00095 seconds |
6
- ./spec/codebreaker/game_spec.rb[1:4] | passed | 0.00124 seconds |
7
- ./spec/codebreaker/game_spec.rb[1:5] | passed | 0.00033 seconds |
8
- ./spec/codebreaker/game_spec.rb[1:6] | passed | 0.0052 seconds |
9
- ./spec/codebreaker/game_spec.rb[1:7] | passed | 0.00059 seconds |
10
- ./spec/codebreaker/game_spec.rb[1:8] | passed | 0.00034 seconds |
11
- ./spec/codebreaker/game_spec.rb[1:9] | passed | 0.00029 seconds |
12
- ./spec/codebreaker/game_spec.rb[1:10:1] | passed | 0.00059 seconds |
13
- ./spec/codebreaker/game_spec.rb[1:10:2] | passed | 0.00028 seconds |
14
- ./spec/codebreaker/game_spec.rb[1:10:3] | passed | 0.00026 seconds |
15
- ./spec/codebreaker/game_spec.rb[1:10:4] | passed | 0.00025 seconds |
16
- ./spec/codebreaker/game_spec.rb[1:10:5] | passed | 0.00027 seconds |
17
- ./spec/codebreaker/game_spec.rb[1:10:6] | passed | 0.00026 seconds |
18
- ./spec/codebreaker/game_spec.rb[1:10:7] | passed | 0.00026 seconds |
19
- ./spec/codebreaker/game_spec.rb[1:10:8] | passed | 0.00027 seconds |
20
- ./spec/codebreaker/game_spec.rb[1:10:9] | passed | 0.00038 seconds |
21
- ./spec/codebreaker/game_spec.rb[1:10:10] | passed | 0.00036 seconds |
22
- ./spec/codebreaker/game_spec.rb[1:10:11] | passed | 0.00034 seconds |
23
- ./spec/codebreaker/loader_spec.rb[1:1] | passed | 0.00079 seconds |
24
- ./spec/codebreaker/validation_spec.rb[1:1] | passed | 0.00023 seconds |
25
- ./spec/codebreaker/validation_spec.rb[1:2] | passed | 0.00014 seconds |
26
- ./spec/codebreaker/validation_spec.rb[1:3] | passed | 0.00013 seconds |
27
- ./spec/codebreaker/validation_spec.rb[1:4] | passed | 0.00008 seconds |
28
- ./spec/codebreaker/validation_spec.rb[1:5] | passed | 0.00009 seconds |
29
- ./spec/codebreaker/validation_spec.rb[1:6] | passed | 0.00013 seconds |
30
- ./spec/codebreaker_spec.rb[1:1] | passed | 0.00009 seconds |