codebreaker_kub 0.2.3 → 0.2.4
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/lib/codebreaker/game.rb +2 -1
- data/lib/codebreaker/guess_checker.rb +34 -0
- data/lib/codebreaker/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b0615cbf8d40317a2e5352dab95e976cdd1e573520751ed35fcda4d231ce983
|
4
|
+
data.tar.gz: bbccf67ba8e10d137208430b08402099781b77ed0556230993b8d54393ed5628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd86ab7a4a57953649870cb06af1acd31981fe5f5969b376a30766a67fe1abf5286b228b4acc148ebbd2608e96f54f9c468fb40934ebcf5f990a116f43f9242
|
7
|
+
data.tar.gz: 6395a16dc75d491deb9bc770c12c074a1bb45a6b2070a3b2ee5c766e17c25359d42160a4527e7cbdb200e0c395de808bcfc337f9fbd4e18cf20c53c080fc19d9
|
data/lib/codebreaker/game.rb
CHANGED
@@ -5,7 +5,7 @@ module Codebreaker
|
|
5
5
|
include Codebreaker::GuessChecker
|
6
6
|
|
7
7
|
attr_accessor :input_code, :code, :name, :difficulties, :difficulty, :hints_left, :attempts_left
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :hints_code
|
9
9
|
|
10
10
|
CODE_LENGTH = 4
|
11
11
|
CODE_RANGE = (1..6).freeze
|
@@ -36,6 +36,7 @@ module Codebreaker
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def input_operation(input_code)
|
39
|
+
@input_code = input_code
|
39
40
|
return unless attempts_left?
|
40
41
|
|
41
42
|
@attempts_left -= 1
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
module GuessChecker
|
5
|
+
MINUSE = '-'
|
6
|
+
PLUS = '+'
|
7
|
+
NONE = ''
|
8
|
+
|
9
|
+
def symbols(inexact = MINUSE, exact = PLUS, none = NONE)
|
10
|
+
@inexact = inexact
|
11
|
+
@exact = exact
|
12
|
+
@none = none
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_input(code, input)
|
16
|
+
raw_result = inexact(code.chars, input.chars)
|
17
|
+
exact(code.chars, input.chars, raw_result)
|
18
|
+
end
|
19
|
+
|
20
|
+
def inexact(code, input)
|
21
|
+
inexact = (code & input).map { |element| [code.count(element), input.count(element)].min }.sum
|
22
|
+
@inexact * inexact
|
23
|
+
end
|
24
|
+
|
25
|
+
def exact(code, input, result)
|
26
|
+
input.each.with_index do |element, index|
|
27
|
+
result.sub!(@inexact, @exact) if element == code[index]
|
28
|
+
end
|
29
|
+
return result unless result.empty?
|
30
|
+
|
31
|
+
@none
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/codebreaker/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_kub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- katia kub
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/codebreaker/data/difficulties.yml
|
121
121
|
- lib/codebreaker/data/locales/en.yml
|
122
122
|
- lib/codebreaker/game.rb
|
123
|
+
- lib/codebreaker/guess_checker.rb
|
123
124
|
- lib/codebreaker/loader.rb
|
124
125
|
- lib/codebreaker/output.rb
|
125
126
|
- lib/codebreaker/validation.rb
|