codebreaker_kub 0.1.5 → 0.2.1
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/.circleci/config.yml +57 -0
- data/.gitignore +1 -2
- data/.rubocop.yml +0 -3
- data/Gemfile +2 -3
- data/Gemfile.lock +2 -2
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/codebreaker.gemspec +3 -0
- data/lib/codebreaker.rb +2 -0
- data/lib/codebreaker/data/locales/en.yml +2 -1
- data/lib/codebreaker/game.rb +23 -10
- data/lib/codebreaker/loader.rb +3 -1
- data/lib/codebreaker/output.rb +27 -8
- data/lib/codebreaker/validation.rb +5 -1
- data/lib/codebreaker/version.rb +3 -1
- data/pkg/codebreaker_kub-0.0.1.gem +0 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04c487aaa2731e942ffff6cb60ef16d1104251d00bb9983a6e7d91c103b7169
|
4
|
+
data.tar.gz: 4b505fe8bfe8a2e60e0f3915db5f3e4afe8175f06812602d4f1d972c9dcb31f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
codebreaker_kub (0.1.
|
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.
|
68
|
+
rspec (~> 3.9)
|
69
69
|
rubocop (~> 0.87)
|
70
70
|
simplecov (~> 0.18)
|
71
71
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/codebreaker.gemspec
CHANGED
@@ -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'
|
data/lib/codebreaker.rb
CHANGED
@@ -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
|
|
data/lib/codebreaker/game.rb
CHANGED
@@ -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, '
|
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 =
|
64
|
+
result = @minuse * minuses
|
54
65
|
input.each.with_index do |element, index|
|
55
|
-
result.sub!(
|
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(
|
74
|
+
Array.new(CODE_LENGTH) { rand(CODE_RANGE) }.join
|
62
75
|
end
|
63
76
|
|
64
77
|
def generate_hint
|
65
|
-
@code.chars.shuffle
|
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
|
-
|
80
|
-
|
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
|
data/lib/codebreaker/loader.rb
CHANGED
@@ -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'
|
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)
|
data/lib/codebreaker/output.rb
CHANGED
@@ -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
|
-
|
40
|
+
sort_stats
|
41
|
+
@stats.each_with_index do |game, index|
|
26
42
|
puts "Hey, #{game[:name]}
|
27
|
-
|
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?(
|
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)
|
data/lib/codebreaker/version.rb
CHANGED
Binary file
|
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
|
+
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-
|
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
|