codebracker_simb 0.9.0 → 0.9.3
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/codebracker_simb.gemspec +1 -1
- data/lib/codebracker_simb/checker.rb +14 -14
- data/lib/codebracker_simb/game.rb +7 -28
- data/lib/codebracker_simb/version.rb +1 -1
- data/lib/codebracker_simb.rb +6 -5
- data/lib/{codebracker_simb/errors → errors}/code_error.rb +0 -0
- data/lib/{codebracker_simb/errors → errors}/complexity_error.rb +0 -0
- data/lib/{codebracker_simb/errors → errors}/intro_error.rb +0 -0
- data/lib/{codebracker_simb/errors → errors}/name_error.rb +0 -0
- data/lib/{codebracker_simb/errors → errors}/no_hints_error.rb +0 -0
- metadata +7 -8
- data/lib/codebracker_simb/code.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3356bb3020b49ba5a2c23e81b1b37b5773b75f7e3c3acf21e6cd03723f6f631
|
4
|
+
data.tar.gz: f26790bfc8279ed403c9dc9cd90cc3bab95fde60650baa2991ac08d7ce3371cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d83b7aa808c6df1eb0dfb99f38884900306dc089de22a083699e1ed916e62e80b47c6f0a3428f9165e0e3fe68074e047c5ccf4c346e60265a9027bccbeb2012b
|
7
|
+
data.tar.gz: 5f29919e84d4f5675a65da7f1484938b0262ff586462092966650013a5d7385f42620b13f8c6e9b77571f95a3ef437cbbb0d0c0ac89b1e615a23e6ab802b3ed7
|
data/codebracker_simb.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
-
spec.files = Dir['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.rake', 'Gemfile', 'Rakefile',
|
20
|
+
spec.files = Dir['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/**/*.rb', 'lib/codebracker_simb.rb', 'lib/**/*.rake', 'Gemfile', 'Rakefile',
|
21
21
|
'codebracker_simb.gemspec', '.github/*.md', 'CHANGELOG.md']
|
22
22
|
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module CodebrackerSimb
|
4
4
|
# builds table of equality for answer and code and gives string result
|
5
|
-
class Checker
|
6
|
-
def initialize(code,
|
7
|
-
@
|
5
|
+
class Checker
|
6
|
+
def initialize(code, answer)
|
7
|
+
@answer = answer
|
8
8
|
@code = code
|
9
9
|
@filled_column = []
|
10
|
-
|
10
|
+
@table = [[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]]
|
11
11
|
end
|
12
12
|
|
13
13
|
def compare
|
@@ -24,7 +24,7 @@ module CodebrackerSimb
|
|
24
24
|
|
25
25
|
def output
|
26
26
|
output = []
|
27
|
-
each do |line|
|
27
|
+
@table.each do |line|
|
28
28
|
output << '+' if line.include?(:plus)
|
29
29
|
output << '-' if line.include?(:minus) && !line.include?(:plus)
|
30
30
|
end
|
@@ -32,22 +32,22 @@ module CodebrackerSimb
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def fill_with_plus
|
35
|
-
each_with_index do |line,
|
36
|
-
if @code[
|
37
|
-
line[
|
38
|
-
@filled_column <<
|
35
|
+
@table.each_with_index do |line, index|
|
36
|
+
if @code[index] == @answer[index]
|
37
|
+
line[index] = :plus
|
38
|
+
@filled_column << index
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def fill_with_minus
|
44
|
-
each_with_index do |line,
|
45
|
-
line.each_with_index do |
|
46
|
-
next unless @code[
|
44
|
+
@table.each_with_index do |line, index|
|
45
|
+
line.each_with_index do |_, jndex|
|
46
|
+
next unless @code[index] == @answer[jndex] && !line[jndex] && !@filled_column.include?(jndex)
|
47
47
|
next if line.include? :minus
|
48
48
|
|
49
|
-
line[
|
50
|
-
@filled_column <<
|
49
|
+
line[jndex] = :minus
|
50
|
+
@filled_column << jndex
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './code'
|
4
3
|
require_relative './checker'
|
5
4
|
require 'rspec'
|
6
5
|
require 'pry'
|
@@ -12,20 +11,6 @@ module CodebrackerSimb
|
|
12
11
|
attr_reader :code, :attempts, :player, :complexity
|
13
12
|
attr_accessor :answer, :hint_positions, :hints
|
14
13
|
|
15
|
-
IS_OVER = 'Game is over, you lose'
|
16
|
-
GREETING = 'Hello! Welcome to CodeBracker Game! Have fun!'
|
17
|
-
CONGRATULATIONS = 'Congratulations! You broked a code, master!'
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def scores
|
21
|
-
db.execute 'select * from scores order by attempts_total asc, attempts_used asc, hints_used asc'
|
22
|
-
end
|
23
|
-
|
24
|
-
def db
|
25
|
-
SQLite3::Database.new 'score.db'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
14
|
def initialize(complexity, player)
|
30
15
|
@attempts = game_options(complexity)[:attempts]
|
31
16
|
@hints = game_options(complexity)[:hints]
|
@@ -36,10 +21,11 @@ module CodebrackerSimb
|
|
36
21
|
end
|
37
22
|
|
38
23
|
def input_answer(input)
|
39
|
-
@answer =
|
24
|
+
@answer = input.split('').map(&:to_i)
|
40
25
|
end
|
41
26
|
|
42
27
|
def check_answer
|
28
|
+
refresh_attempts_quantity
|
43
29
|
Checker.new(@code, @answer).compare
|
44
30
|
end
|
45
31
|
|
@@ -54,31 +40,24 @@ module CodebrackerSimb
|
|
54
40
|
def refresh_attempts_quantity
|
55
41
|
if @attempts.positive?
|
56
42
|
@attempts -= 1
|
57
|
-
"#{@attempts} left"
|
58
43
|
end
|
59
44
|
end
|
60
45
|
|
61
46
|
def hint
|
62
|
-
|
47
|
+
position = nil
|
63
48
|
loop do
|
64
|
-
|
65
|
-
break unless hint_positions.include?
|
49
|
+
position = rand(0..3)
|
50
|
+
break unless hint_positions.include? position
|
66
51
|
end
|
67
52
|
if @hints.positive?
|
68
|
-
hint_positions <<
|
53
|
+
hint_positions << position
|
69
54
|
@hints -= 1
|
70
|
-
code[
|
55
|
+
code[position]
|
71
56
|
else
|
72
57
|
raise NoHintsError
|
73
58
|
end
|
74
59
|
end
|
75
60
|
|
76
|
-
def write_to_db
|
77
|
-
db = Game.db
|
78
|
-
db.execute 'insert into scores (name, difficulty, attempts_total, attempts_used, hints_total, hints_used) values (?,?,?,?,?,?)',
|
79
|
-
params
|
80
|
-
end
|
81
|
-
|
82
61
|
def params
|
83
62
|
total_attempts = game_options(complexity)[:attempts]
|
84
63
|
total_hints = game_options(complexity)[:hints]
|
data/lib/codebracker_simb.rb
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
require_relative 'codebracker_simb/version'
|
4
4
|
require_relative 'codebracker_simb/game'
|
5
5
|
require_relative 'codebracker_simb/validator'
|
6
|
-
require_relative '
|
7
|
-
require_relative '
|
8
|
-
require_relative '
|
9
|
-
require_relative '
|
10
|
-
require_relative '
|
6
|
+
require_relative 'errors/no_hints_error'
|
7
|
+
require_relative 'errors/code_error'
|
8
|
+
require_relative 'errors/name_error'
|
9
|
+
require_relative 'errors/complexity_error'
|
10
|
+
require_relative 'errors/intro_error'
|
11
11
|
require_relative 'codebracker_simb/text'
|
12
12
|
|
13
13
|
# gem module
|
14
14
|
module CodebrackerSimb
|
15
|
+
|
15
16
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebracker_simb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- max
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -91,16 +91,15 @@ files:
|
|
91
91
|
- codebracker_simb.gemspec
|
92
92
|
- lib/codebracker_simb.rb
|
93
93
|
- lib/codebracker_simb/checker.rb
|
94
|
-
- lib/codebracker_simb/code.rb
|
95
|
-
- lib/codebracker_simb/errors/code_error.rb
|
96
|
-
- lib/codebracker_simb/errors/complexity_error.rb
|
97
|
-
- lib/codebracker_simb/errors/intro_error.rb
|
98
|
-
- lib/codebracker_simb/errors/name_error.rb
|
99
|
-
- lib/codebracker_simb/errors/no_hints_error.rb
|
100
94
|
- lib/codebracker_simb/game.rb
|
101
95
|
- lib/codebracker_simb/text.rb
|
102
96
|
- lib/codebracker_simb/validator.rb
|
103
97
|
- lib/codebracker_simb/version.rb
|
98
|
+
- lib/errors/code_error.rb
|
99
|
+
- lib/errors/complexity_error.rb
|
100
|
+
- lib/errors/intro_error.rb
|
101
|
+
- lib/errors/name_error.rb
|
102
|
+
- lib/errors/no_hints_error.rb
|
104
103
|
homepage:
|
105
104
|
licenses:
|
106
105
|
- MIT
|