icodebreaker_gem 0.2.0 → 0.3.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: 81410c33cbc0dc012c0fca624f320dd2226d3e2d27fd7b895574b41f0e515c58
4
- data.tar.gz: 9fba309cb3b44264fec79ac56867cb8fd207146c4d4bb99a338769e6692d193d
3
+ metadata.gz: 7ec00c184eee22be479150d458bd2e837d1389a781e329871b602a7fae6d372a
4
+ data.tar.gz: b2e5a88f71f41108dbd41eb57cedc617c8da2c1b477968ca53583db505737632
5
5
  SHA512:
6
- metadata.gz: daca3955624651895da909066c8407f47752c267c8899a1c31d15a07ede51252e13be20ac249cd761b0094c97ef20e3e5dfdb9b5b479178b46f767d63f4ea3c3
7
- data.tar.gz: d533c05f39c0b4b396bde249fdfd9957db7f288c346bce35aaad0d0a0bbfa447fc601abed93b1688fc32af4ca96f725fae289c112c6699d99ad3888b6b909c64
6
+ metadata.gz: ee4e2181cfe8dce5f2a084c85e7830631c3e9c34983af65ce1fd6302f356454c11fb61a6f03e42b77247c819206073df3b4092699cc5cc1696eb0f7865539105
7
+ data.tar.gz: cb30f180e4f4d41031f6b5849f57c63291481fc36623302971d0fbb2a194f835c2fbd49abb7c6d47df141cf8e7f4662bac607a2a6b2aecc8d2d64f2a47023c3a
data/.rspec_status CHANGED
@@ -1,30 +1,30 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------ | ------ | --------------- |
3
- ./spec/game_core_spec.rb[1:1] | passed | 0.00038 seconds |
4
- ./spec/game_core_spec.rb[1:2] | passed | 0.00089 seconds |
5
- ./spec/game_core_spec.rb[1:3:1] | passed | 0.00064 seconds |
6
- ./spec/game_core_spec.rb[1:4:1] | passed | 0.00078 seconds |
7
- ./spec/game_core_spec.rb[1:5:1:1] | passed | 0.00011 seconds |
8
- ./spec/game_core_spec.rb[1:5:1:2] | passed | 0.0001 seconds |
9
- ./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00011 seconds |
10
- ./spec/game_core_spec.rb[1:5:1:4] | passed | 0.00015 seconds |
11
- ./spec/game_core_spec.rb[1:5:1:5] | passed | 0.00005 seconds |
12
- ./spec/game_core_spec.rb[1:5:1:6] | passed | 0.00007 seconds |
13
- ./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00004 seconds |
3
+ ./spec/game_core_spec.rb[1:1] | passed | 0.00023 seconds |
4
+ ./spec/game_core_spec.rb[1:2] | passed | 0.00074 seconds |
5
+ ./spec/game_core_spec.rb[1:3:1] | passed | 0.00038 seconds |
6
+ ./spec/game_core_spec.rb[1:4:1] | passed | 0.00054 seconds |
7
+ ./spec/game_core_spec.rb[1:5:1:1] | passed | 0.00006 seconds |
8
+ ./spec/game_core_spec.rb[1:5:1:2] | passed | 0.00007 seconds |
9
+ ./spec/game_core_spec.rb[1:5:1:3] | passed | 0.0001 seconds |
10
+ ./spec/game_core_spec.rb[1:5:1:4] | passed | 0.00006 seconds |
11
+ ./spec/game_core_spec.rb[1:5:1:5] | passed | 0.00006 seconds |
12
+ ./spec/game_core_spec.rb[1:5:1:6] | passed | 0.00006 seconds |
13
+ ./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00008 seconds |
14
14
  ./spec/game_core_spec.rb[1:5:2:1] | passed | 0.00005 seconds |
15
15
  ./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00005 seconds |
16
- ./spec/game_core_spec.rb[1:5:3:1] | passed | 0.00005 seconds |
17
- ./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00006 seconds |
16
+ ./spec/game_core_spec.rb[1:5:3:1] | passed | 0.00007 seconds |
17
+ ./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00005 seconds |
18
18
  ./spec/game_core_spec.rb[1:5:3:3] | passed | 0.00004 seconds |
19
19
  ./spec/game_spec.rb[1:1:1] | passed | 0.00012 seconds |
20
- ./spec/game_spec.rb[1:2:1] | passed | 0.00025 seconds |
21
- ./spec/game_spec.rb[1:2:2] | passed | 0.00007 seconds |
22
- ./spec/game_spec.rb[1:2:3] | passed | 0.00008 seconds |
23
- ./spec/game_spec.rb[1:2:4] | passed | 0.00007 seconds |
24
- ./spec/game_spec.rb[1:2:5] | passed | 0.00008 seconds |
25
- ./spec/game_spec.rb[1:3:1] | passed | 0.00058 seconds |
26
- ./spec/game_spec.rb[1:3:2] | passed | 0.0002 seconds |
27
- ./spec/game_spec.rb[1:3:3] | passed | 0.00014 seconds |
28
- ./spec/game_spec.rb[1:4:1] | passed | 0.00012 seconds |
29
- ./spec/game_spec.rb[1:5:1] | passed | 0.0014 seconds |
30
- ./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.0001 seconds |
20
+ ./spec/game_spec.rb[1:2:1] | passed | 0.00019 seconds |
21
+ ./spec/game_spec.rb[1:2:2] | passed | 0.00008 seconds |
22
+ ./spec/game_spec.rb[1:2:3] | passed | 0.00007 seconds |
23
+ ./spec/game_spec.rb[1:2:4] | passed | 0.00009 seconds |
24
+ ./spec/game_spec.rb[1:2:5] | passed | 0.00005 seconds |
25
+ ./spec/game_spec.rb[1:3:1] | passed | 0.00039 seconds |
26
+ ./spec/game_spec.rb[1:3:2] | passed | 0.00015 seconds |
27
+ ./spec/game_spec.rb[1:3:3] | passed | 0.00015 seconds |
28
+ ./spec/game_spec.rb[1:4:1] | passed | 0.00268 seconds |
29
+ ./spec/game_spec.rb[1:5:1] | passed | 0.0009 seconds |
30
+ ./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.00014 seconds |
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icodebreaker_gem (0.2.0)
4
+ icodebreaker_gem (0.3.1)
5
5
  rake (~> 13.0)
6
6
 
7
7
  GEM
@@ -10,11 +10,14 @@ GEM
10
10
  ast (2.4.2)
11
11
  coderay (1.1.3)
12
12
  colorize (0.8.1)
13
+ concurrent-ruby (1.1.9)
13
14
  diff-lcs (1.4.4)
14
15
  docile (1.4.0)
15
16
  fasterer (0.9.0)
16
17
  colorize (~> 0.7)
17
18
  ruby_parser (>= 3.14.1)
19
+ i18n (1.8.10)
20
+ concurrent-ruby (~> 1.0)
18
21
  method_source (1.0.0)
19
22
  parallel (1.21.0)
20
23
  parser (3.0.2.0)
@@ -66,12 +69,13 @@ PLATFORMS
66
69
  x86_64-linux
67
70
 
68
71
  DEPENDENCIES
69
- fasterer
72
+ fasterer (>= 0.9.0)
73
+ i18n
70
74
  icodebreaker_gem!
71
- pry
75
+ pry (>= 0.14.1)
72
76
  rspec (~> 3.0)
73
77
  rubocop (~> 1.7)
74
- simplecov
78
+ simplecov (>= 0.21.2)
75
79
 
76
80
  BUNDLED WITH
77
81
  2.2.26
@@ -0,0 +1,4 @@
1
+ en:
2
+ message:
3
+ lose: "The game is over."
4
+ no_hints: "No hints left."
data/lib/config.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  require 'yaml'
5
-
4
+ require 'i18n'
5
+ require 'psych'
6
6
  require_relative 'modules/validation'
7
7
  require_relative 'modules/storage'
8
8
 
@@ -10,4 +10,5 @@ require_relative 'game_core'
10
10
  require_relative 'game'
11
11
  require_relative 'icodebreaker_gem/version'
12
12
  require_relative 'icodebreaker_gem'
13
- require_relative 'constants'
13
+
14
+ I18n.load_path << Dir[['config', 'locales', '**', '*.yml'].join('/')]
data/lib/game.rb CHANGED
@@ -5,6 +5,23 @@ module IcodebreakerGem
5
5
  include Validation
6
6
  include Storage
7
7
 
8
+ STATUS = %i[go_on over].freeze
9
+ RESULT = %i[win lose].freeze
10
+ DIFFICULTIES = {
11
+ easy: {
12
+ attempts_total: 15,
13
+ hints_total: 2
14
+ },
15
+ medium: {
16
+ attempts_total: 10,
17
+ hints_total: 1
18
+ },
19
+ hell: {
20
+ attempts_total: 5,
21
+ hints_total: 1
22
+ }
23
+ }.freeze
24
+
8
25
  attr_reader :name, :difficulty, :attempts_used, :hints_used, :status, :result
9
26
 
10
27
  def initialize(name = 'User1', difficulty = :easy, secret = GameCore.random)
@@ -40,19 +57,19 @@ module IcodebreakerGem
40
57
  check_lose
41
58
  answer
42
59
  when :over
43
- 'The game is over.'
60
+ I18n.t('message.lose')
44
61
  end
45
62
  end
46
63
 
47
64
  def hint
48
65
  case @status
49
66
  when :go_on
50
- return 'No hints left.' if @hints_used >= hints_total
67
+ return I18n.t('message.no_hints') if @hints_used >= hints_total
51
68
 
52
69
  @hints_used += 1
53
70
  @code.hint
54
71
  when :over
55
- 'The game is over.'
72
+ I18n.t('message.lose')
56
73
  end
57
74
  end
58
75
 
data/lib/game_core.rb CHANGED
@@ -4,19 +4,16 @@ module IcodebreakerGem
4
4
  class GameCore
5
5
  include Validation
6
6
 
7
- attr_reader :secret
8
-
9
7
  def initialize(secret)
10
8
  validate_code secret
11
9
 
12
10
  @secret = secret.to_s
13
- @shuffle = @secret.each_char.to_a.shuffle
14
- @hint_idx = 0
11
+ @shuffle = @secret.chars.shuffle
15
12
  end
16
13
 
17
14
  def compare(guess)
18
15
  return '++++' if @secret == guess
19
- return '' if (@secret.each_char.to_a & guess.each_char.to_a).empty?
16
+ return '' if (@secret.chars & guess.chars).empty?
20
17
 
21
18
  pluses1, minuses1 = pluses_and_minuses(@secret, guess)
22
19
 
@@ -26,24 +23,21 @@ module IcodebreakerGem
26
23
  end
27
24
 
28
25
  def hint
29
- result = @shuffle[@hint_idx]
30
- @hint_idx += 1
31
- @hint_idx = 0 if @hint_idx >= @shuffle.size
32
- result
26
+ @shuffle.pop
33
27
  end
34
28
 
35
29
  def self.random
36
- (0..3).map { rand(1..6) }.map(&:to_s).join
30
+ (0..3).map { rand(1..6) }.join
37
31
  end
38
32
 
39
33
  private
40
34
 
41
- def pluses_and_minuses(word1, word2)
35
+ def pluses_and_minuses(guess_secret, secret_guess)
42
36
  pluses = minuses = 0
43
- word1.each_char.to_a.each_index do |index|
44
- if word2[index] == word1[index]
37
+ guess_secret.chars.each_index do |index|
38
+ if secret_guess[index] == guess_secret[index]
45
39
  pluses += 1
46
- elsif word2.include? word1[index]
40
+ elsif secret_guess.include? guess_secret[index]
47
41
  minuses += 1
48
42
  end
49
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IcodebreakerGem
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'icodebreaker_gem/version'
4
-
5
- module IcodebreakerGem
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
4
+ require_relative 'config'
5
+ module IcodebreakerGem end
@@ -12,27 +12,28 @@ module IcodebreakerGem
12
12
  YAML.dump(games, file)
13
13
  end
14
14
  end
15
+ class << self
16
+ def load_storage
17
+ create_storage
18
+ YAML.safe_load(File.read(data_path)) || []
19
+ end
15
20
 
16
- def load_storage
17
- create_storage
18
- YAML.load(File.read(data_path)) || []
19
- end
20
-
21
- def sort_codebreakers
22
- load_storage.sort_by do |statistic|
23
- [statistic[:attempts_total], statistic[:attempts_used], statistic[:hints_used]]
21
+ def sort_codebreakers
22
+ load_storage.sort_by do |statistic|
23
+ [statistic[:attempts_total], statistic[:attempts_used], statistic[:hints_used]]
24
+ end
24
25
  end
25
- end
26
26
 
27
- private
27
+ private
28
28
 
29
- def data_path
30
- STORAGE_PATH + DATA_FILE
31
- end
29
+ def data_path
30
+ STORAGE_PATH + DATA_FILE
31
+ end
32
32
 
33
- def create_storage
34
- Dir.mkdir(STORAGE_PATH) unless File.exist?(STORAGE_PATH)
35
- File.open(data_path, 'w') unless File.exist?(data_path)
33
+ def create_storage
34
+ Dir.mkdir(STORAGE_PATH) unless File.exist?(STORAGE_PATH)
35
+ File.open(data_path, 'w') unless File.exist?(data_path)
36
+ end
36
37
  end
37
38
  end
38
39
  end
@@ -2,12 +2,15 @@
2
2
 
3
3
  module IcodebreakerGem
4
4
  module Validation
5
+ USERNAME = /^[0-9a-zA-Z]{3,20}$/.freeze
6
+ CODE = /^[1-6]{4}$/.freeze
7
+
5
8
  def validate_name(name)
6
- raise ArgumentError, 'Incorrect username' unless name.to_s.match?(/^[0-9a-zA-Z]{3,20}$/)
9
+ raise ArgumentError, 'Incorrect username' unless name.to_s.match?(USERNAME)
7
10
  end
8
11
 
9
12
  def validate_code(code)
10
- raise ArgumentError, 'Incorrect code' unless code.to_s.match?(/^[1-6]{4}$/)
13
+ raise ArgumentError, 'Incorrect code' unless code.to_s.match?(CODE)
11
14
  end
12
15
 
13
16
  def validate_difficulty(difficulty)
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icodebreaker_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnnyGsy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -26,6 +26,20 @@ dependencies:
26
26
  version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fasterer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 0.14.1
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 0.14.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: 0.21.2
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: 0.21.2
97
111
  description: Guess the secret code
98
112
  email:
99
113
  - vanstrelok@gmail.com
@@ -115,8 +129,8 @@ files:
115
129
  - Rakefile
116
130
  - bin/console
117
131
  - bin/setup
132
+ - config/locales/en.yml
118
133
  - lib/config.rb
119
- - lib/constants.rb
120
134
  - lib/game.rb
121
135
  - lib/game_core.rb
122
136
  - lib/icodebreaker_gem.rb
@@ -124,6 +138,7 @@ files:
124
138
  - lib/modules/storage.rb
125
139
  - lib/modules/validation.rb
126
140
  - reek.yml
141
+ - storage/codebreakers.yml
127
142
  homepage: https://github.com/JohnnyGsy/icodebreaker_gem
128
143
  licenses:
129
144
  - MIT
data/lib/constants.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IcodebreakerGem
4
- STATUS = %i[go_on over].freeze
5
- RESULT = %i[win lose].freeze
6
- DIFFICULTIES = {
7
- easy: {
8
- attempts_total: 15,
9
- hints_total: 2
10
- },
11
- medium: {
12
- attempts_total: 10,
13
- hints_total: 1
14
- },
15
- hell: {
16
- attempts_total: 5,
17
- hints_total: 1
18
- }
19
- }.freeze
20
- end