new_super_codebreaker_2021 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f04d8ae5feef7d24c5a9e19807862533b20d81d89f8add312b9294b08d5e3d48
4
- data.tar.gz: 952c0e201aaaa71784777d75c0ddfaa27d4734fb3cb9b142b518ae7ca09e420b
3
+ metadata.gz: 1a82b958460bacd3f2058c0358f7d03934b817439cb09a35ce7afd9665cd579a
4
+ data.tar.gz: fa3eb2c2f1f60f4a3005c6aa3c91b9cfe01e189794ddc0372264234862855718
5
5
  SHA512:
6
- metadata.gz: d423c510b3020a843d42de8d56f474aafae891247c1840578724642243462bff795600525a10b2c1dde0d32b10fff5ac497bfaa577736e0e3db7dc76d6085e77
7
- data.tar.gz: 34923426b438428203010aa4283df19b39da947d45f36894bb7265b1017806f684c0e7278b972efe33ba438d64f8338cab4e486920daaa281bed38898c5617ab
6
+ metadata.gz: 313ff20be1e825b6665c27e2faccf4285a4b24fe7f69bb63b7fed3b703f3e36767c9d5e9d5bee94a318debb68fd7393b3c52107d28b5c5a9d0bae78027070ded
7
+ data.tar.gz: d2fdecb7035dec146a97fe2faa0d931a53d6154063f9733c9ba88cdcafc721e70aa6321569f1033b3149fe214dd14909e5a5ff34ca072834fdc8371c2504733d
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at dakhnonazar@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in new_super_codebreaker_2021.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ new_super_codebreaker_2021 (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ colorize (0.8.1)
11
+ diff-lcs (1.4.4)
12
+ docile (1.4.0)
13
+ fasterer (0.9.0)
14
+ colorize (~> 0.7)
15
+ ruby_parser (>= 3.14.1)
16
+ parallel (1.20.1)
17
+ parser (3.0.2.0)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
20
+ rake (13.0.6)
21
+ regexp_parser (2.1.1)
22
+ rexml (3.2.5)
23
+ rspec (3.10.0)
24
+ rspec-core (~> 3.10.0)
25
+ rspec-expectations (~> 3.10.0)
26
+ rspec-mocks (~> 3.10.0)
27
+ rspec-core (3.10.1)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-expectations (3.10.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-mocks (3.10.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-support (3.10.2)
36
+ rubocop (1.19.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.0.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.9.1, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.10.0)
46
+ parser (>= 3.0.1.1)
47
+ ruby-progressbar (1.11.0)
48
+ ruby_parser (3.17.0)
49
+ sexp_processor (~> 4.15, >= 4.15.1)
50
+ sexp_processor (4.15.3)
51
+ simplecov (0.21.2)
52
+ docile (~> 1.1)
53
+ simplecov-html (~> 0.11)
54
+ simplecov_json_formatter (~> 0.1)
55
+ simplecov-html (0.12.3)
56
+ simplecov_json_formatter (0.1.3)
57
+ unicode-display_width (2.0.0)
58
+
59
+ PLATFORMS
60
+ x86_64-linux
61
+
62
+ DEPENDENCIES
63
+ fasterer (~> 0.9.0)
64
+ new_super_codebreaker_2021!
65
+ rake (~> 13.0)
66
+ rspec (~> 3.10.0)
67
+ rubocop (~> 1.7)
68
+ simplecov
69
+
70
+ BUNDLED WITH
71
+ 2.2.26
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # NewSuperCodebreaker2021
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/new_super_codebreaker_2021`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'new_super_codebreaker_2021'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install new_super_codebreaker_2021
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/new_super_codebreaker_2021. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/new_super_codebreaker_2021/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the NewSuperCodebreaker2021 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/new_super_codebreaker_2021/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ rescue LoadError
8
+ # Ignored
9
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'new_super_codebreaker_2021'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/db_methods.rb ADDED
@@ -0,0 +1,15 @@
1
+ module DBMethods
2
+ def save(user, file)
3
+ rating = load_file(file)
4
+ rating.push(user)
5
+ File.open(file, 'w') do |filename|
6
+ YAML.dump(rating, filename)
7
+ end
8
+ end
9
+
10
+ def load_file(file)
11
+ YAML.load_file(file)
12
+ rescue Errno::ENOENT
13
+ []
14
+ end
15
+ end
data/lib/game.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'yaml'
2
+ require_relative 'validate'
3
+ require_relative 'show_content'
4
+ require_relative 'db_methods'
5
+ require_relative 'user'
6
+ module NewSuperCodebreaker2021
7
+ class Game
8
+ include Validate
9
+ include ShowContent
10
+ include DBMethods
11
+
12
+ START_COMMANDS = %i[start rules stats exit].freeze
13
+ DIFFICULTY_COMMANDS = %i[easy medium hell exit].freeze
14
+ GUESS_COMMANDS = %i[hint rules exit].freeze
15
+ AFTER_GAME_COMMANDS = %i[start save exit].freeze
16
+ YES_NO_COMMANDS = %i[yes no].freeze
17
+
18
+ def chose_command(command)
19
+ START_COMMANDS.include?(command.to_sym) ? command.to_sym : false
20
+ end
21
+
22
+ def take_name(input_name)
23
+ if input_name == 'exit'
24
+ :exit
25
+ else
26
+ validate_name(input_name)
27
+ end
28
+ end
29
+
30
+ def chose_difficulty(difficulty)
31
+ DIFFICULTY_COMMANDS.include?(difficulty.to_sym) ? difficulty.to_sym : false
32
+ end
33
+
34
+ def generate_code
35
+ Array.new(4) { rand(1..6) }
36
+ end
37
+
38
+ def user_guess(code)
39
+ if code.to_i != 0
40
+ validate_user_code(code)
41
+ elsif GUESS_COMMANDS.include?(code.to_sym)
42
+ code.to_sym
43
+ else false
44
+ end
45
+ end
46
+
47
+ def take_hint(user, code, used_hints)
48
+ if user.hints_total > user.hints_used
49
+ user.hints_used += 1
50
+ used_hints.each { |hint| code.delete(hint) }
51
+ code.sample
52
+ else
53
+ false
54
+ end
55
+ end
56
+
57
+ def after_game_commands(command)
58
+ if command.to_i.zero? && AFTER_GAME_COMMANDS.include?(command.to_sym)
59
+ command.to_sym
60
+ else false
61
+ end
62
+ end
63
+
64
+ def attempt_to_start(command)
65
+ if command.to_i.zero? && YES_NO_COMMANDS.include?(command.to_sym)
66
+ command.to_sym
67
+ else false
68
+ end
69
+ end
70
+
71
+ def compare_codes(secret_code, user_code)
72
+ matches, u_char = number_on_right_place(secret_code, user_code)
73
+ number_in_secret_code(secret_code, user_code, matches, u_char)
74
+ end
75
+
76
+ private
77
+
78
+ def number_on_right_place(secret_code, user_code)
79
+ matches = []
80
+ u_char = []
81
+ user_code.each_index do |i|
82
+ if secret_code[i] == user_code[i]
83
+ matches.unshift('+')
84
+ u_char << user_code[i]
85
+ end
86
+ end
87
+ [matches, u_char]
88
+ end
89
+
90
+ def number_in_secret_code(secret_code, user_code, matches, u_char)
91
+ user_code.each do |element|
92
+ matches.push('-') if secret_code.include?(element) && !u_char.include?(element)
93
+ end
94
+ matches
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NewSuperCodebreaker2021
4
+ VERSION = '0.3.5'
5
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'new_super_codebreaker_2021/version'
2
+ require 'game'
3
+
4
+ module NewSuperCodebreaker2021
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,8 @@
1
+ module ShowContent
2
+ def show_stats(file)
3
+ data = YAML.load_file(file) || []
4
+ data.sort_by(&:hints_used).sort_by(&:attempts_used).sort_by { |game| -game.difficulty }
5
+ rescue Errno::ENOENT
6
+ []
7
+ end
8
+ end
data/lib/user.rb ADDED
@@ -0,0 +1,32 @@
1
+ class User
2
+ attr_reader :name, :difficulty, :hints_total, :attempts_total
3
+ attr_accessor :hints_used, :attempts_used
4
+
5
+ def initialize(name, difficulty)
6
+ @name = name
7
+ @difficulty = difficulty
8
+ @hints_used = 0
9
+ @attempts_used = 0
10
+ check_difficulty(difficulty)
11
+ end
12
+
13
+ private
14
+
15
+ def check_difficulty(difficulty)
16
+ case difficulty
17
+ when 0
18
+ set_total_fields(2, 15)
19
+ when 1
20
+ set_total_fields(1, 10)
21
+ when 2
22
+ set_total_fields(1, 5)
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ def set_total_fields(hints_total, attempts_total)
29
+ @hints_total = hints_total
30
+ @attempts_total = attempts_total
31
+ end
32
+ end
data/lib/validate.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Validate
2
+ def validate_name(name)
3
+ if name.length >= 3 && name.length <= 20
4
+ name
5
+ else
6
+ false
7
+ end
8
+ end
9
+
10
+ def validate_user_code(us_code)
11
+ arr_code = check_splitting(us_code)
12
+ if valid_number?(arr_code)
13
+ arr_code
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def valid_number?(arr_code)
22
+ arr_code && check_length?(arr_code) && check_numbers?(arr_code)
23
+ end
24
+
25
+ def check_splitting(code)
26
+ code.chars.map!(&:to_i) if integer?(code)
27
+ end
28
+
29
+ def integer?(code)
30
+ code.to_i.to_s == code
31
+ end
32
+
33
+ def check_length?(code)
34
+ code.length == 4
35
+ end
36
+
37
+ def check_numbers?(code)
38
+ code.each do |number|
39
+ return if number < 1 || number > 6
40
+ end
41
+ true
42
+ end
43
+ end
metadata CHANGED
@@ -1,22 +1,107 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_super_codebreaker_2021
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nazar Dakhno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fasterer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.10.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.21.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.21.2
13
83
  description: Game where you need to guess the secret code
14
84
  email:
15
85
  - dakhnonazar@gmail.com
16
86
  executables: []
17
87
  extensions: []
18
88
  extra_rdoc_files: []
19
- files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/db_methods.rb
99
+ - lib/game.rb
100
+ - lib/new_super_codebreaker_2021.rb
101
+ - lib/new_super_codebreaker_2021/version.rb
102
+ - lib/show_content.rb
103
+ - lib/user.rb
104
+ - lib/validate.rb
20
105
  homepage: https://rubygems.org/gems/new_super_codebreaker_2021
21
106
  licenses:
22
107
  - MIT