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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 507c25bcdf25b4b0fb5681407f6988a624f08ee2af4edeca36059f184589c5c2
4
- data.tar.gz: 561816aac6a2a523f90a727e756801a1ac7c0ac343e54c5a9fefaaa4f889d960
3
+ metadata.gz: 2f7678ed8abd762f05a8ba2d5a91aaf57ee01408f18a579d5af8390a1361f152
4
+ data.tar.gz: fddc44923afee084191af5eacac028b01f2438a959ea0bf403ac30cec20a0a85
5
5
  SHA512:
6
- metadata.gz: 66834bb9e38c34d12acb547733c77abede7f52fdcee0a827922a052a1355969d10eb7ed7bd3bf05606f0b4e6c982bd3323bc2844cf9f4c4136a8b3ab0e17151b
7
- data.tar.gz: a91977fef08f6802389bf5500ab40c747a94b7a4fa934716acffdce2fd02898ce57097d57a494b826dcf7d79a5850f0916e5a2bf060b762607bfbbde11b03057
6
+ metadata.gz: 7248c95b565d857368fb249bba23b89929eff0efc0e3d8f370cd9539c1067ffe30e6c8d385f651b8e362a4fc233523f5eb634e7fbbf6e12dab4f00234fe7bca0
7
+ data.tar.gz: e99ba8b399bc2a261ae1c13e52d2dae43b8fc2a8a5e4bd004dd3084c4edf3cfecf465c44cea830d0f645d0f22d97e8ad4fb8281bd59a6b29d39b8de4c8ea38c7
@@ -26,5 +26,4 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'fasterer'
27
27
  spec.add_development_dependency 'rubocop-rspec'
28
28
  spec.add_development_dependency 'simplecov'
29
- spec.add_runtime_dependency 'sqlite3'
30
29
  end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- # builds table of equality for answer and code and gives string result
5
- class Checker < Array
6
- def initialize(code, ans)
7
- @ans = ans
4
+ class Checker
5
+ def initialize(code, answer)
6
+ @answer = answer
8
7
  @code = code
9
8
  @filled_column = []
10
- super([[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]])
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, i|
36
- if @code[i] == @ans[i]
37
- line[i] = :plus
38
- @filled_column << i
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, i|
45
- line.each_with_index do |_el, j|
46
- next unless @code[i] == @ans[j] && !line[j] && !@filled_column.include?(j)
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[j] = :minus
50
- @filled_column << j
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 = Code.new(input)
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
- pos = nil
46
+ position = nil
63
47
  loop do
64
- pos = rand(0..3)
65
- break unless hint_positions.include? pos
48
+ position = rand(0..3)
49
+ break unless hint_positions.include? position
66
50
  end
67
51
  if @hints.positive?
68
- hint_positions << pos
52
+ hint_positions << position
69
53
  @hints -= 1
70
- code[pos]
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
- [player, complexity, total_attempts, used_attempts, total_hints, used_hints]
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
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- # validator class
5
4
  class Validator
6
5
  def self.valid_name?(name)
7
6
  name.is_a?(String) && name.length > 3 && name.length < 20
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.4'
5
5
  end
@@ -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 'codebracker_simb/errors/no_hints_error'
7
- require_relative 'codebracker_simb/errors/code_error'
8
- require_relative 'codebracker_simb/errors/name_error'
9
- require_relative 'codebracker_simb/errors/complexity_error'
10
- require_relative 'codebracker_simb/errors/intro_error'
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
- YOLO = 'YOLO'
14
+
16
15
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # error when answer isn't valid
4
3
  class CodeError < StandardError
5
4
  def initialize(msg = "\nCode must include only four digits from 1 to 6\n\n")
6
5
  super
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # error when user inputs unexpected complexity
4
3
  class ComplexityError < StandardError
5
4
  def initialize(msg = "\nIt could be easy, medium or hard!\n\n")
6
5
  super
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # error when user inputs unexpected command
4
3
  class IntroError < StandardError
5
4
  def initialize(msg = "\nIt could be start, rules, stats or exit!\n\n")
6
5
  super
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # error when name isn't valid
4
3
  class NameError < StandardError
5
4
  def initialize(msg = "\nName should be longer than 3 chars and shorter than 20 chars!\n\n")
6
5
  super
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # error when hints are over
4
3
  class NoHintsError < StandardError
5
4
  def initialize(msg = "\nYou used all your hints!\n\n")
6
5
  super
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.1
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-01 00:00:00.000000000 Z
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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CodebrackerSimb
4
- # return array from users input
5
- class Code < Array
6
- def initialize(str)
7
- arr = str.split('').map(&:to_i)
8
- super(arr)
9
- end
10
- end
11
- end