new_super_codebreaker_2021 0.3.1 → 0.4.0

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: 7a2446930a89506fc1834022af7909727ed28e8c4ff8d014904e0a8fc172dc4a
4
- data.tar.gz: 86774aed2abcfaaf2910e2465f5353942f61ac8790aef87604a52534c72fa181
3
+ metadata.gz: 4fd40fec8111c449a529cb09ab6f8e530543d6ac1cdfc2ef23705ae42c8bfb4b
4
+ data.tar.gz: '084d4e637ece18072729939fe48befc743b34c1218d40f76e5e88508a88fd63e'
5
5
  SHA512:
6
- metadata.gz: 1f2c86b8cdea8f60694eb0ad82178f0b50a122cdf2dcd13d8bcbd17326f698eb2a7c9d3b245e6694d5291355e52a00fc0a8c58b9a73a1425d6c2126a8ad4aa86
7
- data.tar.gz: 565c869bd29485d62dc7705807239d93345c026f8aa6ae2ba1b5a76dbeb7c40f35a99515b8b2bbe576ad0faedd69e56968b8e6d7b79d4b7ea410ba3674f64211
6
+ metadata.gz: 7508f41c83260082bc6cb212ce85ded613637b48c8842040d4c363aa6a0ae7f535958781f8efc6938312e867eda165c71eb7773864c91a8989febf73dda3f9ef
7
+ data.tar.gz: 7d6ed122984525a2262bcc66aca2844723da9ecefb83976a09a9ac323e7cf062f6386fbfebc06cfd8971f0ca319d80a027ee18f5d9b1bf2c7fb5f0ecaed97ce8
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,95 @@
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
+ def initialize
13
+ @code = generate_code
14
+ end
15
+
16
+ GUESS_COMMANDS = %i[hint rules exit].freeze
17
+ START_COMMANDS = %i[start rules stats exit].freeze
18
+ DIFFICULTY_COMMANDS = %i[easy medium hell exit].freeze
19
+ AFTER_GAME_COMMANDS = %i[start save exit].freeze
20
+ YES_NO_COMMANDS = %i[yes no].freeze
21
+
22
+ def chose_command(command)
23
+ check_input(command, START_COMMANDS)
24
+ end
25
+
26
+ def take_name(input_name)
27
+ if input_name == 'exit'
28
+ :exit
29
+ else
30
+ validate_name(input_name)
31
+ end
32
+ end
33
+
34
+ def chose_difficulty(difficulty)
35
+ check_input(difficulty, DIFFICULTY_COMMANDS)
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
+ check_input(command, AFTER_GAME_COMMANDS)
59
+ end
60
+
61
+ def attempt_to_start(command)
62
+ check_input(command, YES_NO_COMMANDS)
63
+ end
64
+
65
+ def compare_codes(user_code)
66
+ matches, u_char = number_on_right_place(user_code)
67
+ number_in_secret_code(user_code, matches, u_char)
68
+ end
69
+
70
+ private
71
+
72
+ def number_on_right_place(user_code)
73
+ matches = []
74
+ u_char = []
75
+ user_code.each_index do |i|
76
+ if @code[i] == user_code[i]
77
+ matches.unshift('+')
78
+ u_char << user_code[i]
79
+ end
80
+ end
81
+ [matches, u_char]
82
+ end
83
+
84
+ def number_in_secret_code(user_code, matches, u_char)
85
+ user_code.each do |element|
86
+ matches.push('-') if @code.include?(element) && !u_char.include?(element)
87
+ end
88
+ matches
89
+ end
90
+
91
+ def generate_code
92
+ Array.new(4) { rand(1..6) }
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NewSuperCodebreaker2021
4
+ VERSION = '0.4.0'
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,50 @@
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
+ def check_input(input, command_list)
20
+ if input.to_i.zero? && command_list.include?(input.to_sym)
21
+ input.to_sym
22
+ else false
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def valid_number?(arr_code)
29
+ arr_code && check_length?(arr_code) && check_numbers?(arr_code)
30
+ end
31
+
32
+ def check_splitting(code)
33
+ code.chars.map!(&:to_i) if integer?(code)
34
+ end
35
+
36
+ def integer?(code)
37
+ code.to_i.to_s == code
38
+ end
39
+
40
+ def check_length?(code)
41
+ code.length == 4
42
+ end
43
+
44
+ def check_numbers?(code)
45
+ code.each do |number|
46
+ return if number < 1 || number > 6
47
+ end
48
+ true
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_super_codebreaker_2021
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
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-23 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -70,23 +70,38 @@ dependencies:
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.21.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.21.2
83
83
  description: Game where you need to guess the secret code
84
84
  email:
85
85
  - dakhnonazar@gmail.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
- 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
90
105
  homepage: https://rubygems.org/gems/new_super_codebreaker_2021
91
106
  licenses:
92
107
  - MIT