icodebreaker_gem 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +22 -22
- data/Gemfile.lock +1 -1
- data/lib/config.rb +7 -8
- data/lib/game_core.rb +8 -14
- data/lib/icodebreaker_gem/version.rb +1 -1
- data/lib/icodebreaker_gem.rb +2 -5
- data/lib/modules/storage.rb +17 -16
- data/storage/codebreakers.yml +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77686e016570a9a327c2588bdfc2d36d0a09b418b58081e827b2dd671058fe6a
|
4
|
+
data.tar.gz: 41071cc2d0f4fba6a345b0f9bab8cab982d45c7b91817514e1cfd3828d7865aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ac145ebb5fb673c36f6bf801d4e638d6fbc24550ccc5ee5442e65576ece7ce4332ec8fa74cc721cba6fdef4c8c1e878aacdddb4cebda5f63b03b192ae964eae
|
7
|
+
data.tar.gz: d9c6fcf607a08a56433888bec900a0af213a6f3adb6cb176a5737fe34623ae1fe3e5f0ae5148dbc00d45c6d267829e47fb6af452c74f8fcf30fe57816d2095e3
|
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.
|
3
|
+
./spec/game_core_spec.rb[1:1] | passed | 0.00023 seconds |
|
4
|
+
./spec/game_core_spec.rb[1:2] | passed | 0.00066 seconds |
|
5
|
+
./spec/game_core_spec.rb[1:3:1] | passed | 0.00034 seconds |
|
6
|
+
./spec/game_core_spec.rb[1:4:1] | passed | 0.00053 seconds |
|
7
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.
|
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.
|
8
|
+
./spec/game_core_spec.rb[1:5:1:2] | passed | 0.00006 seconds |
|
9
|
+
./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00006 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.00008 seconds |
|
12
|
+
./spec/game_core_spec.rb[1:5:1:6] | passed | 0.00006 seconds |
|
13
13
|
./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00004 seconds |
|
14
14
|
./spec/game_core_spec.rb[1:5:2:1] | passed | 0.00005 seconds |
|
15
|
-
./spec/game_core_spec.rb[1:5:2:2] | passed | 0.
|
15
|
+
./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00006 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.00004 seconds |
|
18
18
|
./spec/game_core_spec.rb[1:5:3:3] | passed | 0.00004 seconds |
|
19
|
-
./spec/game_spec.rb[1:1:1] | passed | 0.
|
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.
|
19
|
+
./spec/game_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
20
|
+
./spec/game_spec.rb[1:2:1] | passed | 0.0002 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.00008 seconds |
|
24
|
+
./spec/game_spec.rb[1:2:5] | passed | 0.00005 seconds |
|
25
|
+
./spec/game_spec.rb[1:3:1] | passed | 0.00034 seconds |
|
26
|
+
./spec/game_spec.rb[1:3:2] | passed | 0.00017 seconds |
|
27
27
|
./spec/game_spec.rb[1:3:3] | passed | 0.00014 seconds |
|
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.
|
28
|
+
./spec/game_spec.rb[1:4:1] | passed | 0.00014 seconds |
|
29
|
+
./spec/game_spec.rb[1:5:1] | passed | 0.00104 seconds |
|
30
|
+
./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.00007 seconds |
|
data/Gemfile.lock
CHANGED
data/lib/config.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
3
|
require 'yaml'
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
require_relative 'modules/validation'
|
6
|
+
require_relative 'modules/storage'
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
require_relative 'game_core'
|
9
|
+
require_relative 'game'
|
10
|
+
require_relative 'icodebreaker_gem/version'
|
11
|
+
require_relative 'icodebreaker_gem'
|
12
|
+
require_relative 'constants'
|
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).blank?
|
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.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
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/modules/storage.rb
|
125
125
|
- lib/modules/validation.rb
|
126
126
|
- reek.yml
|
127
|
+
- storage/codebreakers.yml
|
127
128
|
homepage: https://github.com/JohnnyGsy/icodebreaker_gem
|
128
129
|
licenses:
|
129
130
|
- MIT
|