codebracker_simb 0.9.1 → 0.9.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/codebracker_simb.gemspec +0 -1
- data/lib/codebracker_simb/checker.rb +14 -15
- data/lib/codebracker_simb/game.rb +9 -30
- data/lib/codebracker_simb/validator.rb +0 -1
- data/lib/codebracker_simb/version.rb +1 -1
- data/lib/codebracker_simb.rb +6 -7
- data/lib/{codebracker_simb/errors → errors}/code_error.rb +0 -1
- data/lib/{codebracker_simb/errors → errors}/complexity_error.rb +0 -1
- data/lib/{codebracker_simb/errors → errors}/intro_error.rb +0 -1
- data/lib/{codebracker_simb/errors → errors}/name_error.rb +0 -1
- data/lib/{codebracker_simb/errors → errors}/no_hints_error.rb +0 -1
- metadata +7 -22
- 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: 2f7678ed8abd762f05a8ba2d5a91aaf57ee01408f18a579d5af8390a1361f152
|
4
|
+
data.tar.gz: fddc44923afee084191af5eacac028b01f2438a959ea0bf403ac30cec20a0a85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7248c95b565d857368fb249bba23b89929eff0efc0e3d8f370cd9539c1067ffe30e6c8d385f651b8e362a4fc233523f5eb634e7fbbf6e12dab4f00234fe7bca0
|
7
|
+
data.tar.gz: e99ba8b399bc2a261ae1c13e52d2dae43b8fc2a8a5e4bd004dd3084c4edf3cfecf465c44cea830d0f645d0f22d97e8ad4fb8281bd59a6b29d39b8de4c8ea38c7
|
data/codebracker_simb.gemspec
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module CodebrackerSimb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@ans = ans
|
4
|
+
class Checker
|
5
|
+
def initialize(code, answer)
|
6
|
+
@answer = answer
|
8
7
|
@code = code
|
9
8
|
@filled_column = []
|
10
|
-
|
9
|
+
@table = [[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]]
|
11
10
|
end
|
12
11
|
|
13
12
|
def compare
|
@@ -24,7 +23,7 @@ module CodebrackerSimb
|
|
24
23
|
|
25
24
|
def output
|
26
25
|
output = []
|
27
|
-
each do |line|
|
26
|
+
@table.each do |line|
|
28
27
|
output << '+' if line.include?(:plus)
|
29
28
|
output << '-' if line.include?(:minus) && !line.include?(:plus)
|
30
29
|
end
|
@@ -32,22 +31,22 @@ module CodebrackerSimb
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def fill_with_plus
|
35
|
-
each_with_index do |line,
|
36
|
-
if @code[
|
37
|
-
line[
|
38
|
-
@filled_column <<
|
34
|
+
@table.each_with_index do |line, index|
|
35
|
+
if @code[index] == @answer[index]
|
36
|
+
line[index] = :plus
|
37
|
+
@filled_column << index
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def fill_with_minus
|
44
|
-
each_with_index do |line,
|
45
|
-
line.each_with_index do |
|
46
|
-
next unless @code[
|
43
|
+
@table.each_with_index do |line, index|
|
44
|
+
line.each_with_index do |_, jndex|
|
45
|
+
next unless @code[index] == @answer[jndex] && !line[jndex] && !@filled_column.include?(jndex)
|
47
46
|
next if line.include? :minus
|
48
47
|
|
49
|
-
line[
|
50
|
-
@filled_column <<
|
48
|
+
line[jndex] = :minus
|
49
|
+
@filled_column << jndex
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -1,31 +1,15 @@
|
|
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'
|
7
6
|
require 'sqlite3'
|
8
7
|
|
9
8
|
module CodebrackerSimb
|
10
|
-
# game cl
|
11
9
|
class Game
|
12
10
|
attr_reader :code, :attempts, :player, :complexity
|
13
11
|
attr_accessor :answer, :hint_positions, :hints
|
14
12
|
|
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
13
|
def initialize(complexity, player)
|
30
14
|
@attempts = game_options(complexity)[:attempts]
|
31
15
|
@hints = game_options(complexity)[:hints]
|
@@ -36,10 +20,11 @@ module CodebrackerSimb
|
|
36
20
|
end
|
37
21
|
|
38
22
|
def input_answer(input)
|
39
|
-
@answer =
|
23
|
+
@answer = input.split('').map(&:to_i)
|
40
24
|
end
|
41
25
|
|
42
26
|
def check_answer
|
27
|
+
refresh_attempts_quantity
|
43
28
|
Checker.new(@code, @answer).compare
|
44
29
|
end
|
45
30
|
|
@@ -54,37 +39,31 @@ module CodebrackerSimb
|
|
54
39
|
def refresh_attempts_quantity
|
55
40
|
if @attempts.positive?
|
56
41
|
@attempts -= 1
|
57
|
-
"#{@attempts} left"
|
58
42
|
end
|
59
43
|
end
|
60
44
|
|
61
45
|
def hint
|
62
|
-
|
46
|
+
position = nil
|
63
47
|
loop do
|
64
|
-
|
65
|
-
break unless hint_positions.include?
|
48
|
+
position = rand(0..3)
|
49
|
+
break unless hint_positions.include? position
|
66
50
|
end
|
67
51
|
if @hints.positive?
|
68
|
-
hint_positions <<
|
52
|
+
hint_positions << position
|
69
53
|
@hints -= 1
|
70
|
-
code[
|
54
|
+
code[position]
|
71
55
|
else
|
72
56
|
raise NoHintsError
|
73
57
|
end
|
74
58
|
end
|
75
59
|
|
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
60
|
def params
|
83
61
|
total_attempts = game_options(complexity)[:attempts]
|
84
62
|
total_hints = game_options(complexity)[:hints]
|
85
63
|
used_hints = total_hints - hints
|
86
64
|
used_attempts = total_attempts - attempts
|
87
|
-
|
65
|
+
{ player: player, complexity: complexity, total_attempts: total_attempts,
|
66
|
+
used_attempts: used_attempts, total_hints: total_hints, used_hints: used_hints] }
|
88
67
|
end
|
89
68
|
|
90
69
|
private
|
data/lib/codebracker_simb.rb
CHANGED
@@ -3,14 +3,13 @@
|
|
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
|
-
# gem module
|
14
13
|
module CodebrackerSimb
|
15
|
-
|
14
|
+
|
16
15
|
end
|
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.4
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
description: Write a longer description or delete this line.
|
84
70
|
email:
|
85
71
|
- laterty@gmail.com
|
@@ -91,16 +77,15 @@ files:
|
|
91
77
|
- codebracker_simb.gemspec
|
92
78
|
- lib/codebracker_simb.rb
|
93
79
|
- 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
80
|
- lib/codebracker_simb/game.rb
|
101
81
|
- lib/codebracker_simb/text.rb
|
102
82
|
- lib/codebracker_simb/validator.rb
|
103
83
|
- lib/codebracker_simb/version.rb
|
84
|
+
- lib/errors/code_error.rb
|
85
|
+
- lib/errors/complexity_error.rb
|
86
|
+
- lib/errors/intro_error.rb
|
87
|
+
- lib/errors/name_error.rb
|
88
|
+
- lib/errors/no_hints_error.rb
|
104
89
|
homepage:
|
105
90
|
licenses:
|
106
91
|
- MIT
|