new_super_codebreaker_2021 0.3.1 → 0.3.3

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: fd386dbc10a479c2ef3009c011023e62302ddca4e3acff8673582ba96b73e508
4
+ data.tar.gz: 3a597039a82a4e78bc29b8bb41c01133a785bbf958bf208cb2be4707ae86d3d7
5
5
  SHA512:
6
- metadata.gz: 1f2c86b8cdea8f60694eb0ad82178f0b50a122cdf2dcd13d8bcbd17326f698eb2a7c9d3b245e6694d5291355e52a00fc0a8c58b9a73a1425d6c2126a8ad4aa86
7
- data.tar.gz: 565c869bd29485d62dc7705807239d93345c026f8aa6ae2ba1b5a76dbeb7c40f35a99515b8b2bbe576ad0faedd69e56968b8e6d7b79d4b7ea410ba3674f64211
6
+ metadata.gz: a8222847fefd1c56e9b0de5d945c0a18af5ee1f02fa33583b5c3ff1ccdaa17aa4314e38dc501a6a0d57425224cd9512c686b014056e08ec6e31f541ed424c2b6
7
+ data.tar.gz: 33b13a1bf320dc6b9c5a349365246ebb1a17c647c1ecca6887aa836588a5cd8d1a8a7e94f7b33f83e140703f803a080d644940178c9b2d8e36cd9a8126864618
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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ begin
7
+ require "rspec/core/rake_task"
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ rescue LoadError
10
+ # Ignored
11
+ 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,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DBMethods
4
+ def save(user, file)
5
+ rating = load_file(file)
6
+ rating.push(user)
7
+ File.open(file, "w") do |filename|
8
+ YAML.dump(rating, filename)
9
+ end
10
+ end
11
+
12
+ def load_file(file)
13
+ YAML.load_file(file) || []
14
+ rescue Errno::ENOENT
15
+ []
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NewSuperCodebreaker2021
4
+ VERSION = "0.3.3"
5
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require_relative "new_super_codebreaker_2021/version"
5
+ require_relative "validate"
6
+ require_relative "show_content"
7
+ require_relative "db_methods"
8
+ require_relative "user"
9
+
10
+ module NewSuperCodebreaker2021
11
+ class Error < StandardError; end
12
+
13
+ class Game
14
+ include Validate
15
+ include ShowContent
16
+ include DBMethods
17
+ def chose_com(command)
18
+ case command
19
+ when "start" then :start
20
+ when "rules" then :rules
21
+ when "stats" then :stats
22
+ when "exit" then :exit
23
+ else false
24
+ end
25
+ end
26
+
27
+ def take_name(input_name)
28
+ if input_name == "exit"
29
+ :exit
30
+ else
31
+ validate_name(input_name)
32
+ end
33
+ end
34
+
35
+ def chose_difficulty(difficulty)
36
+ case difficulty
37
+ when "easy" then :easy
38
+ when "medium" then :medium
39
+ when "hell" then :hell
40
+ when "exit" then :exit
41
+ else
42
+ false
43
+ end
44
+ end
45
+
46
+ def generate_code
47
+ Array.new(4) { rand(1..6) }
48
+ end
49
+
50
+ def user_guess(code)
51
+ case code
52
+ when "exit" then :exit
53
+ when "hint" then :hint
54
+ when "rules" then :rules
55
+ else validate_user_code(code)
56
+ end
57
+ end
58
+
59
+ def take_hint(user, code, used_hints)
60
+ if user.hints_total > user.hints_used
61
+ user.hints_used += 1
62
+ used_hints.each { |hint| code.delete(hint) }
63
+ code.sample
64
+ else
65
+ false
66
+ end
67
+ end
68
+
69
+ def after_game_commands(command)
70
+ case command
71
+ when "start" then :start
72
+ when "save" then :save
73
+ when "exit" then :exit
74
+ else false
75
+ end
76
+ end
77
+
78
+ def attempt_to_start(command)
79
+ case command
80
+ when "yes" then :yes
81
+ when "no" then :no
82
+ else false
83
+ end
84
+ end
85
+
86
+ def compare_codes(secret_code, user_code)
87
+ matches, u_char = number_on_right_place(secret_code, user_code)
88
+ number_in_secret_code(secret_code, user_code, matches, u_char)
89
+ end
90
+
91
+ private
92
+
93
+ def number_on_right_place(secret_code, user_code)
94
+ matches = []
95
+ u_char = []
96
+ user_code.each_index do |i|
97
+ if secret_code[i] == user_code[i]
98
+ matches.unshift("+")
99
+ u_char << user_code[i]
100
+ end
101
+ end
102
+ [matches, u_char]
103
+ end
104
+
105
+ def number_in_secret_code(secret_code, user_code, matches, u_char)
106
+ user_code.each do |element|
107
+ matches.push("-") if secret_code.include?(element) && !u_char.include?(element)
108
+ end
109
+ matches
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,20 @@
1
+ module ShowContent
2
+ def show_rules(rules)
3
+ rules
4
+ end
5
+
6
+ def show_stats(file)
7
+ data = YAML.load_file(file) || []
8
+ data.sort_by(&:hints_used).sort_by(&:attempts_used).sort_by { |game| -game.difficulty }
9
+ rescue Errno::ENOENT
10
+ []
11
+ end
12
+
13
+ def show_goodbye(goodbye)
14
+ goodbye
15
+ end
16
+
17
+ def show_error(error)
18
+ error
19
+ end
20
+ 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,39 @@
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 arr_code && check_length?(arr_code) && check_numbers?(arr_code)
13
+ arr_code
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def check_splitting(code)
22
+ code.chars.map!(&:to_i) if integer?(code)
23
+ end
24
+
25
+ def integer?(code)
26
+ code.to_i.to_s == code
27
+ end
28
+
29
+ def check_length?(code)
30
+ code.length == 4
31
+ end
32
+
33
+ def check_numbers?(code)
34
+ code.each do |number|
35
+ return false if number < 1 || number > 6
36
+ end
37
+ true
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
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.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nazar Dakhno
@@ -70,23 +70,37 @@ 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/new_super_codebreaker_2021.rb
100
+ - lib/new_super_codebreaker_2021/version.rb
101
+ - lib/show_content.rb
102
+ - lib/user.rb
103
+ - lib/validate.rb
90
104
  homepage: https://rubygems.org/gems/new_super_codebreaker_2021
91
105
  licenses:
92
106
  - MIT