codebreaker_manfly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1bf5a2d407b3dfe6aa376b4b1ee2898aff5218f029ed50431f923da3dc995f64
4
+ data.tar.gz: 76af7bcf0724470479f18b0311d0c2a766daf16755395c50d4c46276102ce7f8
5
+ SHA512:
6
+ metadata.gz: e809f5396db417e025168bfae271c4d2cf4bb571685e68b1e90444e022f5e80e8aabb04e8abf97179e0c450a0277d576972e5cd4c5213c56912f8ccb44e112af
7
+ data.tar.gz: '0193faae4c52a1264d6b322607e9f226463e6b69cefc6ab9966b4664d757633bfde8f318c963931e34f717e153824f8f73b537a17dde13518dbaedf58d49c0ab'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,56 @@
1
+ example_id | status | run_time |
2
+ -------------------------------------------- | ------ | --------------- |
3
+ ./spec/codebreaker/game_spec.rb[1:1:1:1] | passed | 0.00042 seconds |
4
+ ./spec/codebreaker/game_spec.rb[1:1:2:1] | passed | 0.00097 seconds |
5
+ ./spec/codebreaker/game_spec.rb[1:1:3:1] | passed | 0.00035 seconds |
6
+ ./spec/codebreaker/game_spec.rb[1:1:3:2] | passed | 0.00045 seconds |
7
+ ./spec/codebreaker/game_spec.rb[1:1:3:3] | passed | 0.00015 seconds |
8
+ ./spec/codebreaker/game_spec.rb[1:2:1:1] | passed | 0.00013 seconds |
9
+ ./spec/codebreaker/game_spec.rb[1:2:1:2] | passed | 0.00086 seconds |
10
+ ./spec/codebreaker/game_spec.rb[1:2:1:3] | passed | 0.00151 seconds |
11
+ ./spec/codebreaker/game_spec.rb[1:3:1:1] | passed | 0.0002 seconds |
12
+ ./spec/codebreaker/game_spec.rb[1:3:1:2] | passed | 0.00015 seconds |
13
+ ./spec/codebreaker/game_spec.rb[1:3:2:1] | passed | 0.00016 seconds |
14
+ ./spec/codebreaker/game_spec.rb[1:3:2:2] | passed | 0.00014 seconds |
15
+ ./spec/codebreaker/game_spec.rb[1:3:2:3] | passed | 0.00014 seconds |
16
+ ./spec/codebreaker/game_spec.rb[1:3:3:1] | passed | 0.00017 seconds |
17
+ ./spec/codebreaker/game_spec.rb[1:3:3:2] | passed | 0.00015 seconds |
18
+ ./spec/codebreaker/game_spec.rb[1:3:4:1] | passed | 0.00022 seconds |
19
+ ./spec/codebreaker/game_spec.rb[1:4:1:1] | passed | 0.00016 seconds |
20
+ ./spec/codebreaker/gameload_spec.rb[1:1:1:1] | passed | 0.0001 seconds |
21
+ ./spec/codebreaker/gameload_spec.rb[1:1:2:1] | passed | 0.00009 seconds |
22
+ ./spec/codebreaker/gameload_spec.rb[1:1:3:1] | passed | 0.00009 seconds |
23
+ ./spec/codebreaker/gameload_spec.rb[1:1:4:1] | passed | 0.00007 seconds |
24
+ ./spec/codebreaker/gameload_spec.rb[1:1:5:1] | passed | 0.00009 seconds |
25
+ ./spec/codebreaker/gameload_spec.rb[1:1:6:1] | passed | 0.00008 seconds |
26
+ ./spec/codebreaker/save_res_spec.rb[1:1:1:1] | passed | 0.00144 seconds |
27
+ ./spec/codebreaker/save_res_spec.rb[1:1:2:1] | passed | 0.00068 seconds |
28
+ ./spec/codebreaker/user_spec.rb[1:1:1:1] | passed | 0.00016 seconds |
29
+ ./spec/codebreaker/user_spec.rb[1:1:2:1] | passed | 0.00022 seconds |
30
+ ./spec/codebreaker/game_spec.rb[1:1:1:1] | passed | 0.00043 seconds |
31
+ ./spec/codebreaker/game_spec.rb[1:1:2:1] | passed | 0.00089 seconds |
32
+ ./spec/codebreaker/game_spec.rb[1:1:3:1] | passed | 0.00033 seconds |
33
+ ./spec/codebreaker/game_spec.rb[1:1:3:2] | passed | 0.00043 seconds |
34
+ ./spec/codebreaker/game_spec.rb[1:1:3:3] | passed | 0.00012 seconds |
35
+ ./spec/codebreaker/game_spec.rb[1:2:1:1] | passed | 0.00012 seconds |
36
+ ./spec/codebreaker/game_spec.rb[1:2:1:2] | passed | 0.00086 seconds |
37
+ ./spec/codebreaker/game_spec.rb[1:2:1:3] | passed | 0.00147 seconds |
38
+ ./spec/codebreaker/game_spec.rb[1:3:1:1] | passed | 0.0002 seconds |
39
+ ./spec/codebreaker/game_spec.rb[1:3:1:2] | passed | 0.00014 seconds |
40
+ ./spec/codebreaker/game_spec.rb[1:3:2:1] | passed | 0.00016 seconds |
41
+ ./spec/codebreaker/game_spec.rb[1:3:2:2] | passed | 0.00012 seconds |
42
+ ./spec/codebreaker/game_spec.rb[1:3:2:3] | passed | 0.00012 seconds |
43
+ ./spec/codebreaker/game_spec.rb[1:3:3:1] | passed | 0.00017 seconds |
44
+ ./spec/codebreaker/game_spec.rb[1:3:3:2] | passed | 0.00013 seconds |
45
+ ./spec/codebreaker/game_spec.rb[1:3:4:1] | passed | 0.00022 seconds |
46
+ ./spec/codebreaker/game_spec.rb[1:4:1:1] | passed | 0.00015 seconds |
47
+ ./spec/codebreaker/gameload_spec.rb[1:1:1:1] | passed | 0.00009 seconds |
48
+ ./spec/codebreaker/gameload_spec.rb[1:1:2:1] | passed | 0.00008 seconds |
49
+ ./spec/codebreaker/gameload_spec.rb[1:1:3:1] | passed | 0.00007 seconds |
50
+ ./spec/codebreaker/gameload_spec.rb[1:1:4:1] | passed | 0.00007 seconds |
51
+ ./spec/codebreaker/gameload_spec.rb[1:1:5:1] | passed | 0.00008 seconds |
52
+ ./spec/codebreaker/gameload_spec.rb[1:1:6:1] | passed | 0.00007 seconds |
53
+ ./spec/codebreaker/save_res_spec.rb[1:1:1:1] | passed | 0.00213 seconds |
54
+ ./spec/codebreaker/save_res_spec.rb[1:1:2:1] | passed | 0.00104 seconds |
55
+ ./spec/codebreaker/user_spec.rb[1:1:1:1] | passed | 0.00018 seconds |
56
+ ./spec/codebreaker/user_spec.rb[1:1:2:1] | passed | 0.00016 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/Documentation:
9
+ Enabled: false
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - spec/game_spec.rb
14
+ Max: 50
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - spec/codebreaker/game_spec.rb
19
+ Max: 50
20
+
21
+ Style/StringLiteralsInInterpolation:
22
+ Enabled: true
23
+ EnforcedStyle: double_quotes
24
+
25
+ Layout/LineLength:
26
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-28
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 aivanuyk0@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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in codebreaker.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.10"
10
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codebreaker_manfly (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.21.0)
12
+ parser (3.0.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
+ rubocop (1.22.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.12.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.12.0)
41
+ parser (>= 3.0.1.1)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.1.0)
44
+
45
+ PLATFORMS
46
+ x86_64-linux
47
+
48
+ DEPENDENCIES
49
+ codebreaker_manfly!
50
+ rake (~> 13.0)
51
+ rspec (~> 3.10)
52
+ rubocop (~> 1.7)
53
+
54
+ BUNDLED WITH
55
+ 2.2.28
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Manfly1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Codebreaker
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/codebreaker`. 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 'codebreaker_manfly'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install codebreaker
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]/codebreaker. 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]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Codebreaker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
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 "codebreaker"
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
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Codebreaker::Game
2
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
3
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
4
+ const_name: User
5
+ __expired: false
6
+ name:
7
+ __sending_message:
8
+ difficulty: :easy
9
+ date: 2021-10-08
10
+ attempts: 15
11
+ number_of_hints: 2
12
+ --- !ruby/object:Codebreaker::Game
13
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
14
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
15
+ const_name: User
16
+ __expired: false
17
+ name:
18
+ __sending_message:
19
+ difficulty: :easy
20
+ date: 2021-10-08
21
+ attempts: 15
22
+ number_of_hints: 2
23
+ --- !ruby/object:Codebreaker::Game
24
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
25
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
26
+ const_name: User
27
+ __expired: false
28
+ name:
29
+ __sending_message:
30
+ difficulty: :easy
31
+ date: 2021-10-08
32
+ attempts: 15
33
+ number_of_hints: 2
34
+ --- !ruby/object:Codebreaker::Game
35
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
36
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
37
+ const_name: User
38
+ __expired: false
39
+ name:
40
+ __sending_message:
41
+ difficulty: :easy
42
+ date: 2021-10-08
43
+ attempts: 15
44
+ number_of_hints: 2
45
+ --- !ruby/object:Codebreaker::Game
46
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
47
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
48
+ const_name: User
49
+ __expired: false
50
+ name:
51
+ __sending_message:
52
+ difficulty: :easy
53
+ date: 2021-10-08
54
+ attempts: 15
55
+ number_of_hints: 2
56
+ --- !ruby/object:Codebreaker::Game
57
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
58
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
59
+ const_name: User
60
+ __expired: false
61
+ name:
62
+ __sending_message:
63
+ difficulty: :easy
64
+ date: 2021-10-08
65
+ attempts: 15
66
+ number_of_hints: 2
67
+ --- !ruby/object:Codebreaker::Game
68
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
69
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
70
+ const_name: User
71
+ __expired: false
72
+ name:
73
+ __sending_message:
74
+ difficulty: :easy
75
+ date: 2021-10-08
76
+ attempts: 15
77
+ number_of_hints: 2
78
+ --- !ruby/object:Codebreaker::Game
79
+ user: !ruby/object:RSpec::Mocks::InstanceVerifyingDouble
80
+ doubled_module: !ruby/object:RSpec::Mocks::NamedObjectReference
81
+ const_name: User
82
+ __expired: false
83
+ name:
84
+ __sending_message:
85
+ difficulty: :easy
86
+ date: 2021-10-08
87
+ attempts: 15
88
+ number_of_hints: 2
data/entity.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml/store"
4
+ require "date"
5
+
6
+ require_relative "lib/codebreaker/module/validation"
7
+ require_relative "lib/codebreaker/gameload"
8
+ require_relative "lib/codebreaker/user"
9
+ require_relative "lib/codebreaker/game"
10
+ require_relative "lib/codebreaker/save_res"
11
+ require_relative "lib/codebreaker/module/save_res"
12
+ require_relative "lib/codebreaker"
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class Game
5
+ include Validation
6
+
7
+ attr_reader :clues, :user, :difficulty,
8
+ :attempts_used, :hints_used, :very_secret_code,
9
+ :date
10
+
11
+ DIFFICULTIES = {
12
+ easy: { attempts: 15, hints: 2 },
13
+ medium: { attempts: 10, hints: 1 },
14
+ hell: { attempts: 5, hints: 1 }
15
+ }.freeze
16
+
17
+ CODE_LENGTH = 4
18
+ RANGE_GUESS_CODE = (1..6).freeze
19
+
20
+ def initialize(difficulty:, user:, date: Date.today)
21
+ validate_difficulty(difficulty, DIFFICULTIES)
22
+
23
+ @user = user
24
+ @difficulty = difficulty
25
+ @date = date
26
+
27
+ attempts
28
+ number_of_hints
29
+ end
30
+
31
+ def start_new_game
32
+ @very_secret_code = generate_random_code
33
+ @hints = @very_secret_code.clone
34
+ @attempts_used = 0
35
+ @hints_used = 0
36
+ @user_guess = []
37
+ @clues = []
38
+ end
39
+
40
+ def guess(user_guess)
41
+ guess = user_guess.each_char.map(&:to_i)
42
+ validate_guess(guess, CODE_LENGTH, RANGE_GUESS_CODE)
43
+ check_guess(guess, very_secret_code)
44
+
45
+ increase_attempts
46
+ end
47
+
48
+ def show_hint
49
+ validate_hints(hints_used, number_of_hints)
50
+
51
+ @hints_used += 1
52
+ @hints.shuffle!.pop
53
+ end
54
+
55
+ def won?
56
+ @user_guess.nil?
57
+ end
58
+
59
+ def lost?
60
+ @attempts_used >= @attempts
61
+ end
62
+
63
+ def save_game
64
+ SaveRes.new.save(self)
65
+ end
66
+
67
+ def attempts
68
+ @attempts ||= DIFFICULTIES[difficulty.to_sym][:attempts]
69
+ end
70
+
71
+ def number_of_hints
72
+ @number_of_hints ||= DIFFICULTIES[difficulty.to_sym][:hints]
73
+ end
74
+
75
+ private
76
+
77
+ def generate_random_code
78
+ Array.new(CODE_LENGTH) { rand(RANGE_GUESS_CODE) }
79
+ end
80
+
81
+ def check_guess(guess, secret_code)
82
+ gameload = Codebreaker::Gameload.new(guess, secret_code)
83
+ @user_guess = gameload.match
84
+ @clues = gameload.clues
85
+ end
86
+
87
+ def increase_attempts
88
+ @attempts_used += 1
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class Gameload
5
+ attr_reader :clues
6
+
7
+ CLUES = {
8
+ exact: :exact,
9
+ non_exact: :non_exact
10
+ }.freeze
11
+
12
+ def initialize(guess, secret_code)
13
+ @secret_code = secret_code
14
+ @guess = guess
15
+ @clues = []
16
+ end
17
+
18
+ def match
19
+ collected = @secret_code.zip(@guess).delete_if { |code, guess| write_to_clues(CLUES[:exact]) if code == guess }
20
+ @secret_code, @guess = collected.transpose
21
+ return unless @guess
22
+
23
+ non_exact_match
24
+ end
25
+
26
+ def non_exact_match
27
+ @guess.compact.each do |num|
28
+ next unless @secret_code.any?(num)
29
+
30
+ write_to_clues(CLUES[:non_exact])
31
+ @secret_code[@secret_code.index(num)] = nil
32
+ end
33
+ end
34
+
35
+ def write_to_clues(clue)
36
+ @clues.push(clue)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class SaveRes
5
+ include Validation
6
+
7
+ FILE_PATH = "#{ENV["DB_PATH"]}#{ENV["DB_FILE"]}"
8
+
9
+ def initialize(db_file_path = FILE_PATH)
10
+ @db_file_path = db_file_path
11
+ end
12
+
13
+ def load
14
+ validate_file_existens(FILE_PATH)
15
+
16
+ File.open(FILE_PATH, "r") do |file|
17
+ YAML.load_stream(file)
18
+ end
19
+ end
20
+
21
+ def save(object)
22
+ create_directory("DB_PATH") unless Dir.exist?(ENV["DB_PATH"])
23
+ File.open(FILE_PATH, "a") { |file| file.write(object.to_yaml) }
24
+ end
25
+
26
+ def create_directory(path)
27
+ Dir.mkdir(ENV[path])
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ module Validation
5
+ ERROR_MESSAGES = {
6
+ invalid_name: "Name should be of 3 to 20 characters",
7
+ invalid_guess: "Expect 4 digits from 1 to 6",
8
+ no_hints_left: "No hints left, mate",
9
+ no_difficulty: "No such difficulty",
10
+ no_save_data: "No saved data is found"
11
+ }.freeze
12
+
13
+ class GameError < StandardError; end
14
+
15
+ class NoSavedData < GameError; end
16
+
17
+ class UnknownDifficulty < GameError; end
18
+
19
+ class InvalidGuess < GameError; end
20
+
21
+ class NoHintsLeft < GameError; end
22
+
23
+ class InvalidName < GameError; end
24
+
25
+ def validate_user_name(name, length)
26
+ raise_error(InvalidName, :invalid_name) unless length.cover?(name.length)
27
+ end
28
+
29
+ def validate_difficulty(difficulty, difficulties)
30
+ raise_error(UnknownDifficulty, :no_difficulty) unless difficulties.keys.any?(difficulty.to_sym)
31
+ end
32
+
33
+ def validate_guess(guess, length, range)
34
+ raise_error(InvalidGuess, :invalid_guess) unless guess.compact.length == length
35
+ raise_error(InvalidGuess, :invalid_guess) if guess.compact.any? { |num| !range.cover? num }
36
+ end
37
+
38
+ def validate_hints(hints_used, hints_total)
39
+ raise_error(NoHintsLeft, :no_hints_left) if hints_used >= hints_total
40
+ end
41
+
42
+ def validate_file_existens(file_path)
43
+ raise_error(NoSavedData, :no_save_data) unless File.exist?(file_path)
44
+ end
45
+
46
+ def raise_error(error_class, error_message)
47
+ raise error_class, ERROR_MESSAGES[error_message]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class SaveRes
5
+ include Validation
6
+
7
+ FILE_PATH = "#{ENV["DB_PATH"]}#{ENV["DB_FILE"]}"
8
+
9
+ def initialize(db_file_path = FILE_PATH)
10
+ @db_file_path = db_file_path
11
+ end
12
+
13
+ def load
14
+ validate_file_existens(FILE_PATH)
15
+
16
+ File.open(FILE_PATH, "r") do |file|
17
+ YAML.load_stream(file)
18
+ end
19
+ end
20
+
21
+ def save(object)
22
+ create_directory("DB_PATH") unless Dir.exist?(ENV["DB_PATH"])
23
+ File.open(FILE_PATH, "a") { |file| file.write(object.to_yaml) }
24
+ end
25
+
26
+ def create_directory(path)
27
+ Dir.mkdir(ENV[path])
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ class User
5
+ include Validation
6
+
7
+ attr_reader :name
8
+
9
+ NAME_LENGTH = (3..20).freeze
10
+
11
+ def initialize(name:)
12
+ validate_user_name(name, NAME_LENGTH)
13
+ @name = name
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreaker
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../entity"
4
+ require_relative "codebreaker/version"
5
+
6
+ module Codebreaker
7
+ class Error < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker_manfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrii Ivaniuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Longer description or delete this line.
14
+ email:
15
+ - aivanuyk0@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rspec_status"
22
+ - ".rubocop.yml"
23
+ - ".ruby-version"
24
+ - CHANGELOG.md
25
+ - CODE_OF_CONDUCT.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - db/results_test.yml
34
+ - entity.rb
35
+ - lib/codebreaker.rb
36
+ - lib/codebreaker/game.rb
37
+ - lib/codebreaker/gameload.rb
38
+ - lib/codebreaker/module/save_res.rb
39
+ - lib/codebreaker/module/validation.rb
40
+ - lib/codebreaker/save_res.rb
41
+ - lib/codebreaker/user.rb
42
+ - lib/codebreaker/version.rb
43
+ homepage:
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.7.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.2.28
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Short summary, because RubyGems requires one.
66
+ test_files: []