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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5435653ed5020dc12fce5f812025ca52ab4aa068d9835962d65ec735897d2b4f
4
- data.tar.gz: fe29d8332ca574cc900eb6f02e41408e1c03cf5e118bfbc072570733759740da
3
+ metadata.gz: a3356bb3020b49ba5a2c23e81b1b37b5773b75f7e3c3acf21e6cd03723f6f631
4
+ data.tar.gz: f26790bfc8279ed403c9dc9cd90cc3bab95fde60650baa2991ac08d7ce3371cc
5
5
  SHA512:
6
- metadata.gz: 322b9b991f70fb787cddde04d7192aefc91341c169669196dcf01c84fe728feb35444566faeaaca05342824da2f7111ec372196bf75657b071c4b2288526b271
7
- data.tar.gz: 25a6c510d2a31f5e9a752b30748feeb0a386beb8e2b5eacb5d7e7b6581ba88eeccb1c11981f4ce3178c4b070dd48caef33b55d5a5b22214c3e1f5b4aa559b0f7
6
+ metadata.gz: d83b7aa808c6df1eb0dfb99f38884900306dc089de22a083699e1ed916e62e80b47c6f0a3428f9165e0e3fe68074e047c5ccf4c346e60265a9027bccbeb2012b
7
+ data.tar.gz: 5f29919e84d4f5675a65da7f1484938b0262ff586462092966650013a5d7385f42620b13f8c6e9b77571f95a3ef437cbbb0d0c0ac89b1e615a23e6ab802b3ed7
@@ -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 < Array
6
- def initialize(code, ans)
7
- @ans = ans
5
+ class Checker
6
+ def initialize(code, answer)
7
+ @answer = answer
8
8
  @code = code
9
9
  @filled_column = []
10
- super([[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]])
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, i|
36
- if @code[i] == @ans[i]
37
- line[i] = :plus
38
- @filled_column << i
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, i|
45
- line.each_with_index do |_el, j|
46
- next unless @code[i] == @ans[j] && !line[j] && !@filled_column.include?(j)
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[j] = :minus
50
- @filled_column << j
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 = Code.new(input)
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
- pos = nil
47
+ position = nil
63
48
  loop do
64
- pos = rand(0..3)
65
- break unless hint_positions.include? pos
49
+ position = rand(0..3)
50
+ break unless hint_positions.include? position
66
51
  end
67
52
  if @hints.positive?
68
- hint_positions << pos
53
+ hint_positions << position
69
54
  @hints -= 1
70
- code[pos]
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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.3'
5
5
  end
@@ -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 '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
13
  # gem module
14
14
  module CodebrackerSimb
15
+
15
16
  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.0
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-01 00:00:00.000000000 Z
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
@@ -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