icodebreaker_gem 0.2.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +24 -24
- data/Gemfile.lock +8 -4
- data/config/locales/en.yml +4 -0
- data/lib/config.rb +4 -3
- data/lib/game.rb +21 -4
- data/lib/game_core.rb +8 -14
- data/lib/icodebreaker_gem/version.rb +1 -1
- data/lib/icodebreaker_gem.rb +1 -4
- data/lib/modules/storage.rb +17 -16
- data/lib/modules/validation.rb +5 -2
- data/storage/codebreakers.yml +0 -0
- metadata +22 -7
- data/lib/constants.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b2eff0c20aa4a4d7a24da6bf94c18c0b8df5c81a960fa7fa9d089ac9135c1d
|
4
|
+
data.tar.gz: 21cc8e1fc06aed15fd8b196bb5773ef4f91b5b1d1cf0eaf219442b0d9c9b9107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07e6d6f78658a5db43ddcbf916eb0b3bdcb75084f43e42930496297ecaeae81aed63ca61b1bc8f2a05b7772b84a1e3be2aaca350b29edae5304bf96d19d69cbe
|
7
|
+
data.tar.gz: 51e79e88826032591096f97bd6dbb6d4c4234e2644388c8bed6325fa51515d45d19199b0c66df0e2991552a76ae7954cc53da1b6a0cedce812667146a723ae35
|
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.
|
4
|
-
./spec/game_core_spec.rb[1:2] | passed | 0.
|
5
|
-
./spec/game_core_spec.rb[1:3:1] | passed | 0.
|
6
|
-
./spec/game_core_spec.rb[1:4:1] | passed | 0.
|
7
|
-
./spec/game_core_spec.rb[1:5:1:1] | passed | 0.
|
8
|
-
./spec/game_core_spec.rb[1:5:1:2] | passed | 0.
|
9
|
-
./spec/game_core_spec.rb[1:5:1:3] | passed | 0.
|
10
|
-
./spec/game_core_spec.rb[1:5:1:4] | passed | 0.
|
11
|
-
./spec/game_core_spec.rb[1:5:1:5] | passed | 0.
|
12
|
-
./spec/game_core_spec.rb[1:5:1:6] | passed | 0.
|
13
|
-
./spec/game_core_spec.rb[1:5:1:7] | passed | 0.
|
14
|
-
./spec/game_core_spec.rb[1:5:2:1] | passed | 0.
|
3
|
+
./spec/game_core_spec.rb[1:1] | passed | 0.00027 seconds |
|
4
|
+
./spec/game_core_spec.rb[1:2] | passed | 0.00075 seconds |
|
5
|
+
./spec/game_core_spec.rb[1:3:1] | passed | 0.00043 seconds |
|
6
|
+
./spec/game_core_spec.rb[1:4:1] | passed | 0.00065 seconds |
|
7
|
+
./spec/game_core_spec.rb[1:5:1:1] | passed | 0.00008 seconds |
|
8
|
+
./spec/game_core_spec.rb[1:5:1:2] | passed | 0.00008 seconds |
|
9
|
+
./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00009 seconds |
|
10
|
+
./spec/game_core_spec.rb[1:5:1:4] | passed | 0.00009 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.00008 seconds |
|
13
|
+
./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00007 seconds |
|
14
|
+
./spec/game_core_spec.rb[1:5:2:1] | passed | 0.00008 seconds |
|
15
15
|
./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00005 seconds |
|
16
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.
|
17
|
+
./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00007 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.
|
21
|
-
./spec/game_spec.rb[1:2:2] | passed | 0.
|
22
|
-
./spec/game_spec.rb[1:2:3] | passed | 0.
|
23
|
-
./spec/game_spec.rb[1:2:4] | passed | 0.
|
24
|
-
./spec/game_spec.rb[1:2:5] | passed | 0.
|
25
|
-
./spec/game_spec.rb[1:3:1] | passed | 0.
|
26
|
-
./spec/game_spec.rb[1:3:2] | passed | 0.
|
27
|
-
./spec/game_spec.rb[1:3:3] | passed | 0.
|
28
|
-
./spec/game_spec.rb[1:4:1] | passed | 0.
|
29
|
-
./spec/game_spec.rb[1:5:1] | passed | 0.
|
30
|
-
./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.
|
20
|
+
./spec/game_spec.rb[1:2:1] | passed | 0.00018 seconds |
|
21
|
+
./spec/game_spec.rb[1:2:2] | passed | 0.00006 seconds |
|
22
|
+
./spec/game_spec.rb[1:2:3] | passed | 0.00006 seconds |
|
23
|
+
./spec/game_spec.rb[1:2:4] | passed | 0.00006 seconds |
|
24
|
+
./spec/game_spec.rb[1:2:5] | passed | 0.00005 seconds |
|
25
|
+
./spec/game_spec.rb[1:3:1] | passed | 0.00045 seconds |
|
26
|
+
./spec/game_spec.rb[1:3:2] | passed | 0.00016 seconds |
|
27
|
+
./spec/game_spec.rb[1:3:3] | passed | 0.00012 seconds |
|
28
|
+
./spec/game_spec.rb[1:4:1] | passed | 0.00272 seconds |
|
29
|
+
./spec/game_spec.rb[1:5:1] | passed | 0.001 seconds |
|
30
|
+
./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.00006 seconds |
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
icodebreaker_gem (0.2
|
4
|
+
icodebreaker_gem (0.3.2)
|
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
|
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
|
-
|
13
|
+
|
14
|
+
I18n.load_path << Dir[['config', 'locales', '**', '*.yml'].join('/')]
|
data/lib/game.rb
CHANGED
@@ -5,7 +5,24 @@ module IcodebreakerGem
|
|
5
5
|
include Validation
|
6
6
|
include Storage
|
7
7
|
|
8
|
-
|
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
|
+
|
25
|
+
attr_reader :name, :difficulty, :attempts_used, :hints_used, :status, :result, :code
|
9
26
|
|
10
27
|
def initialize(name = 'User1', difficulty = :easy, secret = GameCore.random)
|
11
28
|
validate_name name
|
@@ -40,19 +57,19 @@ module IcodebreakerGem
|
|
40
57
|
check_lose
|
41
58
|
answer
|
42
59
|
when :over
|
43
|
-
'
|
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 '
|
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
|
-
'
|
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.
|
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.
|
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
|
-
|
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) }.
|
30
|
+
(0..3).map { rand(1..6) }.join
|
37
31
|
end
|
38
32
|
|
39
33
|
private
|
40
34
|
|
41
|
-
def pluses_and_minuses(
|
35
|
+
def pluses_and_minuses(guess_secret, secret_guess)
|
42
36
|
pluses = minuses = 0
|
43
|
-
|
44
|
-
if
|
37
|
+
guess_secret.chars.each_index do |index|
|
38
|
+
if secret_guess[index] == guess_secret[index]
|
45
39
|
pluses += 1
|
46
|
-
elsif
|
40
|
+
elsif secret_guess.include? guess_secret[index]
|
47
41
|
minuses += 1
|
48
42
|
end
|
49
43
|
end
|
data/lib/icodebreaker_gem.rb
CHANGED
data/lib/modules/storage.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
27
|
+
private
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def data_path
|
30
|
+
STORAGE_PATH + DATA_FILE
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
data/lib/modules/validation.rb
CHANGED
@@ -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?(
|
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?(
|
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
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JohnnyGsy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-04 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:
|
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:
|
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:
|
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:
|
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
|