codebreaker_game 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rakeTasks +7 -0
- data/Gemfile.lock +1 -1
- data/lib/codebreaker_game.rb +16 -21
- data/lib/codebreaker_game/storage.rb +4 -0
- data/lib/codebreaker_game/version.rb +1 -1
- 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: f6fb4ec1bf52cb3b621494242b84d4403501a78caface7a7cbd641fe5a74af49
|
4
|
+
data.tar.gz: f1fc052e202d70a2871c6cbd7e307f1e45903e7ba8767aa47926aff7276ea764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f775d699bf37cabc345832703e01db4fc580f318ff4c08b86e25e34cc427f3da8f764ddd7c9c071a6b300add29da17e615ef0a821208877a14905d7cb73d285
|
7
|
+
data.tar.gz: 552b206fd062d4c309d2732335a723d9ef234008bb57c6ee69c3863ca252a10ed1b4db84509ccf5a17240d86abaf5d653e52b3f3b2297fdb872457fe819fc918
|
data/.gitignore
CHANGED
data/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build codebreaker_game-0.1.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install codebreaker_game-0.1.1.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install codebreaker_game-0.1.1.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.1 and build and push codebreaker_game-0.1.1.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/Gemfile.lock
CHANGED
data/lib/codebreaker_game.rb
CHANGED
@@ -24,8 +24,7 @@ module CodebreakerGame
|
|
24
24
|
@secret_number = generate_secret(SECRET_LENGTH)
|
25
25
|
@status = STATUS_IN_PROGRESS
|
26
26
|
@hints = @secret_number.to_s.chars.shuffle
|
27
|
-
@storage =
|
28
|
-
@difficulty_factory = CodebreakerGame::DifficultyFactory.new
|
27
|
+
@storage = CodebreakerGame::Game.new_store
|
29
28
|
save_storage unless CodebreakerGame::Game.storage_exists?
|
30
29
|
synchronize_storage
|
31
30
|
end
|
@@ -49,7 +48,7 @@ module CodebreakerGame
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def create_difficulty(difficulty:)
|
52
|
-
|
51
|
+
CodebreakerGame::DifficultyFactory.new.difficulty_by_name(difficulty)
|
53
52
|
end
|
54
53
|
|
55
54
|
def attempt(user_number)
|
@@ -70,11 +69,16 @@ module CodebreakerGame
|
|
70
69
|
@hints.pop
|
71
70
|
end
|
72
71
|
|
72
|
+
def save_storage
|
73
|
+
@storage.transaction do
|
74
|
+
@storage[:winners] = @winners || []
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
73
78
|
private
|
74
79
|
|
75
80
|
def win
|
76
81
|
@winners << user
|
77
|
-
save_storage
|
78
82
|
@status = STATUS_WIN
|
79
83
|
end
|
80
84
|
|
@@ -86,16 +90,16 @@ module CodebreakerGame
|
|
86
90
|
def compare_numbers(number, number_two)
|
87
91
|
secret_digits = number.to_s.chars
|
88
92
|
user_digits = number_two.to_s.chars
|
89
|
-
response =
|
90
|
-
response +=
|
93
|
+
response = strong_intersections(secret_digits, user_digits)
|
94
|
+
response += not_strong_intersections(secret_digits, user_digits)
|
91
95
|
win if response == STRONG_INTERSECTION * SECRET_LENGTH
|
92
96
|
response
|
93
97
|
end
|
94
98
|
|
95
|
-
def
|
99
|
+
def strong_intersections(secret_digits, user_digits)
|
96
100
|
response = ''
|
97
101
|
secret_digits.each_with_index do |digit, index|
|
98
|
-
next
|
102
|
+
next unless digit == user_digits[index]
|
99
103
|
|
100
104
|
response += STRONG_INTERSECTION
|
101
105
|
secret_digits[index] = nil
|
@@ -104,12 +108,13 @@ module CodebreakerGame
|
|
104
108
|
response
|
105
109
|
end
|
106
110
|
|
107
|
-
def
|
111
|
+
def not_strong_intersections(secret_digits, user_digits)
|
108
112
|
response = ''
|
109
|
-
secret_digits.
|
110
|
-
next
|
113
|
+
secret_digits.each do |digit|
|
114
|
+
next if digit.nil? || !user_digits.include?(digit)
|
111
115
|
|
112
116
|
response += NOT_STRONG_INTERSECTION
|
117
|
+
user_digits.delete_at(user_digits.index(digit))
|
113
118
|
end
|
114
119
|
response
|
115
120
|
end
|
@@ -119,15 +124,5 @@ module CodebreakerGame
|
|
119
124
|
@winners = @storage[:winners]
|
120
125
|
end
|
121
126
|
end
|
122
|
-
|
123
|
-
def save_storage
|
124
|
-
@storage.transaction do
|
125
|
-
@storage[:winners] = @winners || []
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def yaml_store
|
130
|
-
YAML::Store.new(CodebreakerGame::Game.storage_file)
|
131
|
-
end
|
132
127
|
end
|
133
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".circleci/config.yml"
|
105
105
|
- ".fasterer.yml"
|
106
106
|
- ".gitignore"
|
107
|
+
- ".rakeTasks"
|
107
108
|
- ".rspec"
|
108
109
|
- ".rubocop.yml"
|
109
110
|
- ".travis.yml"
|