codebreaker_al 0.1.0
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 +7 -0
- data/.circleci/config.yml +59 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +91 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +40 -0
- data/connection.rb +12 -0
- data/lib/codebreaker/version.rb +5 -0
- data/lib/codebreaker.rb +17 -0
- data/lib/game.rb +92 -0
- data/lib/locales/config.rb +4 -0
- data/lib/locales/en.yml +6 -0
- data/lib/modules/storage.rb +43 -0
- data/lib/modules/valid.rb +12 -0
- data/lib/modules/validation.rb +19 -0
- data/lib/rubocop/.rubocop_todo.yml +8 -0
- data/lib/secret_code.rb +17 -0
- data/lib/user.rb +17 -0
- data/storage.yml +11 -0
- metadata +211 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 482ee02c47ee2c5a1af1be440fc1f0a668148e8a433cb56dfb07cfc82af980d2
         | 
| 4 | 
            +
              data.tar.gz: cfffa4d027a45d974bcad52c7619c5373b4fdb412bda5960fabe7942f9e97457
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: d50bae6d5082eb46e4ae92816f2497e3c561cd16ec86c7414c9a3e493d7b6a9c36385a04a8c28ff726427ef405a859cac38329061e9899f52523c834747bdfcc
         | 
| 7 | 
            +
              data.tar.gz: 66223c9de3acda91d999d5a5a8e477f558379d58d7321cc2c29f04f74aeded8cd5a83a324382db083576d8ac9fb415a95c24ff2c53df46f77c0e9089c6e538d9
         | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            version: 2.1
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            executors:
         | 
| 4 | 
            +
              default:
         | 
| 5 | 
            +
                working_directory: ~/codebraker
         | 
| 6 | 
            +
                docker:
         | 
| 7 | 
            +
                  - image: circleci/ruby:2.7.2
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            caches:
         | 
| 10 | 
            +
              - &bundle_cache_full v2-repo-{{ checksum "Gemfile.lock" }}
         | 
| 11 | 
            +
              - &bundle_cache v2-repo-
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            commands:
         | 
| 14 | 
            +
              defaults:
         | 
| 15 | 
            +
                steps:
         | 
| 16 | 
            +
                  - checkout
         | 
| 17 | 
            +
                  - restore_cache:
         | 
| 18 | 
            +
                      keys:
         | 
| 19 | 
            +
                        - *bundle_cache_full
         | 
| 20 | 
            +
                        - *bundle_cache
         | 
| 21 | 
            +
                  - run: bundle install --path vendor/bundle
         | 
| 22 | 
            +
                  - save_cache:
         | 
| 23 | 
            +
                      key: *bundle_cache_full
         | 
| 24 | 
            +
                      paths:
         | 
| 25 | 
            +
                        - vendor/bundle
         | 
| 26 | 
            +
              run_linters:
         | 
| 27 | 
            +
                steps:
         | 
| 28 | 
            +
                  - run:
         | 
| 29 | 
            +
                      name: rubocop
         | 
| 30 | 
            +
                      command: bundle exec rubocop
         | 
| 31 | 
            +
              run_specs:
         | 
| 32 | 
            +
                steps:
         | 
| 33 | 
            +
                  - run:
         | 
| 34 | 
            +
                      name: run specs
         | 
| 35 | 
            +
                      command: |
         | 
| 36 | 
            +
                        mkdir /tmp/test-results
         | 
| 37 | 
            +
                        TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
         | 
| 38 | 
            +
                        bundle exec rspec --format progress \
         | 
| 39 | 
            +
                                          --out /tmp/test-results/rspec.xml \
         | 
| 40 | 
            +
                                          $TEST_FILES
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            jobs:
         | 
| 43 | 
            +
              lintering:
         | 
| 44 | 
            +
                executor: default
         | 
| 45 | 
            +
                steps:
         | 
| 46 | 
            +
                  - defaults
         | 
| 47 | 
            +
                  - run_linters
         | 
| 48 | 
            +
              run_specs:
         | 
| 49 | 
            +
                executor: default
         | 
| 50 | 
            +
                steps:
         | 
| 51 | 
            +
                  - defaults
         | 
| 52 | 
            +
                  - run_specs
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            workflows:
         | 
| 55 | 
            +
              version: 2.1
         | 
| 56 | 
            +
              build:
         | 
| 57 | 
            +
                jobs:
         | 
| 58 | 
            +
                  - lintering
         | 
| 59 | 
            +
                  - run_specs
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.rubocop.yml
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            inherit_from: lib/rubocop/.rubocop_todo.yml
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                codebreaker_al (0.1.0)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            GEM
         | 
| 7 | 
            +
              remote: https://rubygems.org/
         | 
| 8 | 
            +
              specs:
         | 
| 9 | 
            +
                ast (2.4.2)
         | 
| 10 | 
            +
                coderay (1.1.3)
         | 
| 11 | 
            +
                colorize (0.8.1)
         | 
| 12 | 
            +
                concurrent-ruby (1.1.10)
         | 
| 13 | 
            +
                diff-lcs (1.5.0)
         | 
| 14 | 
            +
                docile (1.4.0)
         | 
| 15 | 
            +
                fasterer (0.10.0)
         | 
| 16 | 
            +
                  colorize (~> 0.7)
         | 
| 17 | 
            +
                  ruby_parser (>= 3.19.1)
         | 
| 18 | 
            +
                i18n (1.10.0)
         | 
| 19 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 20 | 
            +
                json (2.6.2)
         | 
| 21 | 
            +
                method_source (1.0.0)
         | 
| 22 | 
            +
                parallel (1.22.1)
         | 
| 23 | 
            +
                parser (3.1.2.0)
         | 
| 24 | 
            +
                  ast (~> 2.4.1)
         | 
| 25 | 
            +
                pry (0.14.1)
         | 
| 26 | 
            +
                  coderay (~> 1.1)
         | 
| 27 | 
            +
                  method_source (~> 1.0)
         | 
| 28 | 
            +
                rainbow (3.1.1)
         | 
| 29 | 
            +
                rake (12.3.3)
         | 
| 30 | 
            +
                regexp_parser (2.5.0)
         | 
| 31 | 
            +
                rexml (3.2.5)
         | 
| 32 | 
            +
                rspec (3.11.0)
         | 
| 33 | 
            +
                  rspec-core (~> 3.11.0)
         | 
| 34 | 
            +
                  rspec-expectations (~> 3.11.0)
         | 
| 35 | 
            +
                  rspec-mocks (~> 3.11.0)
         | 
| 36 | 
            +
                rspec-core (3.11.0)
         | 
| 37 | 
            +
                  rspec-support (~> 3.11.0)
         | 
| 38 | 
            +
                rspec-expectations (3.11.0)
         | 
| 39 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 40 | 
            +
                  rspec-support (~> 3.11.0)
         | 
| 41 | 
            +
                rspec-mocks (3.11.1)
         | 
| 42 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 43 | 
            +
                  rspec-support (~> 3.11.0)
         | 
| 44 | 
            +
                rspec-support (3.11.0)
         | 
| 45 | 
            +
                rubocop (1.31.1)
         | 
| 46 | 
            +
                  json (~> 2.3)
         | 
| 47 | 
            +
                  parallel (~> 1.10)
         | 
| 48 | 
            +
                  parser (>= 3.1.0.0)
         | 
| 49 | 
            +
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 50 | 
            +
                  regexp_parser (>= 1.8, < 3.0)
         | 
| 51 | 
            +
                  rexml (>= 3.2.5, < 4.0)
         | 
| 52 | 
            +
                  rubocop-ast (>= 1.18.0, < 2.0)
         | 
| 53 | 
            +
                  ruby-progressbar (~> 1.7)
         | 
| 54 | 
            +
                  unicode-display_width (>= 1.4.0, < 3.0)
         | 
| 55 | 
            +
                rubocop-ast (1.18.0)
         | 
| 56 | 
            +
                  parser (>= 3.1.1.0)
         | 
| 57 | 
            +
                rubocop-rspec (2.12.1)
         | 
| 58 | 
            +
                  rubocop (~> 1.31)
         | 
| 59 | 
            +
                ruby-progressbar (1.11.0)
         | 
| 60 | 
            +
                ruby_parser (3.19.1)
         | 
| 61 | 
            +
                  sexp_processor (~> 4.16)
         | 
| 62 | 
            +
                sexp_processor (4.16.1)
         | 
| 63 | 
            +
                simplecov (0.21.2)
         | 
| 64 | 
            +
                  docile (~> 1.1)
         | 
| 65 | 
            +
                  simplecov-html (~> 0.11)
         | 
| 66 | 
            +
                  simplecov_json_formatter (~> 0.1)
         | 
| 67 | 
            +
                simplecov-html (0.12.3)
         | 
| 68 | 
            +
                simplecov_json_formatter (0.1.4)
         | 
| 69 | 
            +
                table_print (1.5.7)
         | 
| 70 | 
            +
                unicode-display_width (2.2.0)
         | 
| 71 | 
            +
                yaml (0.2.0)
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            PLATFORMS
         | 
| 74 | 
            +
              ruby
         | 
| 75 | 
            +
              x86_64-linux
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            DEPENDENCIES
         | 
| 78 | 
            +
              codebreaker_al!
         | 
| 79 | 
            +
              fasterer (~> 0.10.0)
         | 
| 80 | 
            +
              i18n (~> 1.10.0)
         | 
| 81 | 
            +
              pry (~> 0.14.1)
         | 
| 82 | 
            +
              rake (~> 12.0)
         | 
| 83 | 
            +
              rspec (~> 3.0)
         | 
| 84 | 
            +
              rubocop (~> 1.31.1)
         | 
| 85 | 
            +
              rubocop-rspec (~> 2.12.1)
         | 
| 86 | 
            +
              simplecov (~> 0.21.2)
         | 
| 87 | 
            +
              table_print (~> 1.5.7)
         | 
| 88 | 
            +
              yaml (~> 0.2.0)
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            BUNDLED WITH
         | 
| 91 | 
            +
               2.3.14
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2022 Anastasiia Losytska
         | 
| 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/Rakefile
    ADDED
    
    
    
        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
    
    
    
        data/codebreaker.gemspec
    ADDED
    
    | @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'lib/codebreaker/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name          = 'codebreaker_al'
         | 
| 7 | 
            +
              spec.version       = Codebreaker::VERSION
         | 
| 8 | 
            +
              spec.authors       = ['Anastasiia Losytska']
         | 
| 9 | 
            +
              spec.email         = ['alosytska@gmail.com']
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              spec.summary       = 'Logic game Codebreacker'
         | 
| 12 | 
            +
              spec.homepage      = 'https://github.com/anastasiialosytska/Codebreaker'
         | 
| 13 | 
            +
              spec.license       = 'MIT'
         | 
| 14 | 
            +
              spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.metadata['allowed_push_host'] = 'https://rubygems.org'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              spec.metadata['homepage_uri'] = spec.homepage
         | 
| 19 | 
            +
              spec.metadata['source_code_uri'] = 'https://github.com/anastasiialosytska/Codebreaker'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              # Specify which files should be added to the gem when it is released.
         | 
| 22 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 23 | 
            +
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         | 
| 24 | 
            +
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              spec.bindir        = 'exe'
         | 
| 27 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 28 | 
            +
              spec.require_paths = ['lib']
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              spec.add_development_dependency 'fasterer', '~> 0.10.0'
         | 
| 31 | 
            +
              spec.add_development_dependency 'i18n', '~> 1.10.0'
         | 
| 32 | 
            +
              spec.add_development_dependency 'pry', '~> 0.14.1'
         | 
| 33 | 
            +
              spec.add_development_dependency 'rake', '~> 13.0.6'
         | 
| 34 | 
            +
              spec.add_development_dependency 'rspec', '~> 3.11.0'
         | 
| 35 | 
            +
              spec.add_development_dependency 'rubocop', '~> 1.31.1'
         | 
| 36 | 
            +
              spec.add_development_dependency 'rubocop-rspec', '~> 2.12.1'
         | 
| 37 | 
            +
              spec.add_development_dependency 'simplecov', '~> 0.21.2'
         | 
| 38 | 
            +
              spec.add_development_dependency 'table_print', '~> 1.5.7'
         | 
| 39 | 
            +
              spec.add_development_dependency 'yaml', '~> 0.2.0'
         | 
| 40 | 
            +
            end
         | 
    
        data/connection.rb
    ADDED
    
    | @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'pry'
         | 
| 4 | 
            +
            require 'table_print'
         | 
| 5 | 
            +
            require 'yaml'
         | 
| 6 | 
            +
            require 'i18n'
         | 
| 7 | 
            +
            require_relative 'lib/modules/storage'
         | 
| 8 | 
            +
            require_relative 'lib/modules/valid'
         | 
| 9 | 
            +
            require_relative 'lib/modules/validation'
         | 
| 10 | 
            +
            require_relative 'lib/user'
         | 
| 11 | 
            +
            require_relative 'lib/secret_code'
         | 
| 12 | 
            +
            require_relative 'lib/game'
         | 
    
        data/lib/codebreaker.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'codebreaker/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Codebreaker
         | 
| 6 | 
            +
              require 'pry'
         | 
| 7 | 
            +
              require 'table_print'
         | 
| 8 | 
            +
              require 'yaml'
         | 
| 9 | 
            +
              require 'i18n'
         | 
| 10 | 
            +
              require_relative 'locales/config'
         | 
| 11 | 
            +
              require_relative 'modules/storage'
         | 
| 12 | 
            +
              require_relative 'modules/valid'
         | 
| 13 | 
            +
              require_relative 'modules/validation'
         | 
| 14 | 
            +
              require_relative 'user'
         | 
| 15 | 
            +
              require_relative 'secret_code'
         | 
| 16 | 
            +
              require_relative 'game'
         | 
| 17 | 
            +
            end
         | 
    
        data/lib/game.rb
    ADDED
    
    | @@ -0,0 +1,92 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Codebreaker
         | 
| 4 | 
            +
              class Game
         | 
| 5 | 
            +
                include Storage
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                private
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                attr_reader :secret_code
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                public
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                attr_reader :user, :attempts, :total_attempts, :hints, :total_hints, :level
         | 
| 14 | 
            +
                attr_accessor :status
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                GAME_DIFFICULTIES = { simple: { attempts: 15, hints: 2 }, medium: { attempts: 10, hints: 1 },
         | 
| 17 | 
            +
                                      hell: { attempts: 5, hints: 1 } }.freeze
         | 
| 18 | 
            +
                WIN = :win
         | 
| 19 | 
            +
                LOSS = :loss
         | 
| 20 | 
            +
                PLUS = '+'
         | 
| 21 | 
            +
                MINUS = '-'
         | 
| 22 | 
            +
                NUMBER_OF_ENCRYPTED_DIGITS = 4
         | 
| 23 | 
            +
                VALUES_FOR_ENCRYPTED_DIGITS = (1..6).to_a
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def initialize(user_name)
         | 
| 26 | 
            +
                  @user = User.new(user_name)
         | 
| 27 | 
            +
                  @secret_code = SecretCode.new(generate_secret_code).value
         | 
| 28 | 
            +
                  @status = nil
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def add_hints_attempts(level)
         | 
| 32 | 
            +
                  @level = level.to_sym
         | 
| 33 | 
            +
                  @total_attempts = Game::GAME_DIFFICULTIES[@level][:attempts]
         | 
| 34 | 
            +
                  @total_hints = Game::GAME_DIFFICULTIES[@level][:hints]
         | 
| 35 | 
            +
                  @attempts = @total_attempts
         | 
| 36 | 
            +
                  @hints = @total_hints
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def take_hint
         | 
| 40 | 
            +
                  raise I18n.t(:out_of_hints) if @hints.zero?
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  @hints -= 1
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  @secret_code.digits.shuffle.pop
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def guess(user_variant)
         | 
| 48 | 
            +
                  return @status = Game::LOSS if @attempts.zero?
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  answer = SecretCode.new(user_variant.to_i)
         | 
| 51 | 
            +
                  @attempts -= 1 if answer.valid?
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  if answer.value == @secret_code
         | 
| 54 | 
            +
                    store_game
         | 
| 55 | 
            +
                    return @status = Game::WIN
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  check_user_answer(answer.value)
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                private
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def generate_secret_code
         | 
| 64 | 
            +
                  VALUES_FOR_ENCRYPTED_DIGITS.sample(NUMBER_OF_ENCRYPTED_DIGITS).join.to_i
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                def check_user_answer(answer)
         | 
| 68 | 
            +
                  answer_array = answer.digits
         | 
| 69 | 
            +
                  secret_code_array = @secret_code.digits
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  pros = answer_array.zip(secret_code_array).count { |x, y| x == y }
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  answer_array.each_index do |i|
         | 
| 74 | 
            +
                    answer_array.delete_at(i) && secret_code_array.delete_at(i) if answer_array[i] == secret_code_array[i]
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  cons = secret_code_array.select { |x| answer_array.include?(x) }.count
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  generate_response(pros, cons)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def generate_response(pros, cons)
         | 
| 83 | 
            +
                  response = []
         | 
| 84 | 
            +
                  return response.join if pros.zero? && cons.zero?
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  pros.times { response.push(Game::PLUS) }
         | 
| 87 | 
            +
                  cons.times { response.push(Game::MINUS) }
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  response.join
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
            end
         | 
    
        data/lib/locales/en.yml
    ADDED
    
    
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Codebreaker
         | 
| 4 | 
            +
              module Storage
         | 
| 5 | 
            +
                STORAGE_FILE = 'storage.yml'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def store_game
         | 
| 8 | 
            +
                  saved_games = load_games_history
         | 
| 9 | 
            +
                  saved_games << self
         | 
| 10 | 
            +
                  File.write(STORAGE_FILE, saved_games.to_yaml)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def statistics_with_raiting
         | 
| 14 | 
            +
                  raiting = 0
         | 
| 15 | 
            +
                  sort_data_for_statistics.map do |row|
         | 
| 16 | 
            +
                    raiting += 1
         | 
| 17 | 
            +
                    Hash[:raiting, raiting].merge!(row)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def show_statistics
         | 
| 22 | 
            +
                  tp(statistics_with_raiting).class
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                private
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def load_games_history
         | 
| 28 | 
            +
                  File.empty?(STORAGE_FILE) ? [] : YAML.load_file(STORAGE_FILE)
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def data_for_statistics
         | 
| 32 | 
            +
                  load_games_history.map do |game|
         | 
| 33 | 
            +
                    { name: game.user.name, level: game.level, attempts_total: game.total_attempts,
         | 
| 34 | 
            +
                      attempts_used: game.total_attempts - game.attempts, hints_total: game.total_hints,
         | 
| 35 | 
            +
                      hints_used: game.total_hints - game.hints }
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def sort_data_for_statistics
         | 
| 40 | 
            +
                  data_for_statistics.sort_by { |row| [row[:level], row[:attempts_used], row[:hints_used]] }
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Codebreaker
         | 
| 4 | 
            +
              module Validation
         | 
| 5 | 
            +
                # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
         | 
| 6 | 
            +
                def validate(name, options = {})
         | 
| 7 | 
            +
                  define_method(:validate!) do
         | 
| 8 | 
            +
                    attribute = instance_variable_get("@#{name}".to_sym)
         | 
| 9 | 
            +
                    raise I18n.t(:set_value) if options[:presence] && (attribute.nil? || attribute == '')
         | 
| 10 | 
            +
                    raise I18n.t(:incorrect_type) if options[:type] && !attribute.instance_of?(options[:type])
         | 
| 11 | 
            +
                    raise I18n.t(:incorrect_length) if options[:length] && !options[:length].include?(attribute.to_s.length)
         | 
| 12 | 
            +
                    raise I18n.t(:incorrect_value) if options [:values] && !attribute.digits.select! do |digit|
         | 
| 13 | 
            +
                                                        options[:values].include?(digit)
         | 
| 14 | 
            +
                                                      end.nil?
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/secret_code.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Codebreaker
         | 
| 4 | 
            +
              class SecretCode
         | 
| 5 | 
            +
                extend Validation
         | 
| 6 | 
            +
                include Valid
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                attr_accessor :value
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                validate :value, presence: true, type: Integer, length: [4], values: (1..6)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def initialize(value)
         | 
| 13 | 
            +
                  @value = value
         | 
| 14 | 
            +
                  validate!
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/lib/user.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Codebreaker
         | 
| 4 | 
            +
              class User
         | 
| 5 | 
            +
                extend Validation
         | 
| 6 | 
            +
                include Valid
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                attr_reader :name
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                validate :name, presence: true, type: String, length: (3..20)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def initialize(name)
         | 
| 13 | 
            +
                  @name = name
         | 
| 14 | 
            +
                  validate!
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/storage.yml
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,211 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: codebreaker_al
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Anastasiia Losytska
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2022-07-14 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.10.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.10.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: i18n
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 1.10.0
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 1.10.0
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: pry
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 0.14.1
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 0.14.1
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rake
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 13.0.6
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: 13.0.6
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rspec
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: 3.11.0
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: 3.11.0
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rubocop
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: 1.31.1
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: 1.31.1
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: rubocop-rspec
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 2.12.1
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 2.12.1
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: simplecov
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - "~>"
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: 0.21.2
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - "~>"
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: 0.21.2
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: table_print
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - "~>"
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: 1.5.7
         | 
| 132 | 
            +
              type: :development
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - "~>"
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: 1.5.7
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: yaml
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - "~>"
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: 0.2.0
         | 
| 146 | 
            +
              type: :development
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - "~>"
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: 0.2.0
         | 
| 153 | 
            +
            description:
         | 
| 154 | 
            +
            email:
         | 
| 155 | 
            +
            - alosytska@gmail.com
         | 
| 156 | 
            +
            executables: []
         | 
| 157 | 
            +
            extensions: []
         | 
| 158 | 
            +
            extra_rdoc_files: []
         | 
| 159 | 
            +
            files:
         | 
| 160 | 
            +
            - ".circleci/config.yml"
         | 
| 161 | 
            +
            - ".gitignore"
         | 
| 162 | 
            +
            - ".rspec"
         | 
| 163 | 
            +
            - ".rubocop.yml"
         | 
| 164 | 
            +
            - ".travis.yml"
         | 
| 165 | 
            +
            - Gemfile
         | 
| 166 | 
            +
            - Gemfile.lock
         | 
| 167 | 
            +
            - LICENSE.txt
         | 
| 168 | 
            +
            - Rakefile
         | 
| 169 | 
            +
            - bin/console
         | 
| 170 | 
            +
            - bin/setup
         | 
| 171 | 
            +
            - codebreaker.gemspec
         | 
| 172 | 
            +
            - connection.rb
         | 
| 173 | 
            +
            - lib/codebreaker.rb
         | 
| 174 | 
            +
            - lib/codebreaker/version.rb
         | 
| 175 | 
            +
            - lib/game.rb
         | 
| 176 | 
            +
            - lib/locales/config.rb
         | 
| 177 | 
            +
            - lib/locales/en.yml
         | 
| 178 | 
            +
            - lib/modules/storage.rb
         | 
| 179 | 
            +
            - lib/modules/valid.rb
         | 
| 180 | 
            +
            - lib/modules/validation.rb
         | 
| 181 | 
            +
            - lib/rubocop/.rubocop_todo.yml
         | 
| 182 | 
            +
            - lib/secret_code.rb
         | 
| 183 | 
            +
            - lib/user.rb
         | 
| 184 | 
            +
            - storage.yml
         | 
| 185 | 
            +
            homepage: https://github.com/anastasiialosytska/Codebreaker
         | 
| 186 | 
            +
            licenses:
         | 
| 187 | 
            +
            - MIT
         | 
| 188 | 
            +
            metadata:
         | 
| 189 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 190 | 
            +
              homepage_uri: https://github.com/anastasiialosytska/Codebreaker
         | 
| 191 | 
            +
              source_code_uri: https://github.com/anastasiialosytska/Codebreaker
         | 
| 192 | 
            +
            post_install_message:
         | 
| 193 | 
            +
            rdoc_options: []
         | 
| 194 | 
            +
            require_paths:
         | 
| 195 | 
            +
            - lib
         | 
| 196 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 197 | 
            +
              requirements:
         | 
| 198 | 
            +
              - - ">="
         | 
| 199 | 
            +
                - !ruby/object:Gem::Version
         | 
| 200 | 
            +
                  version: 2.6.0
         | 
| 201 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 202 | 
            +
              requirements:
         | 
| 203 | 
            +
              - - ">="
         | 
| 204 | 
            +
                - !ruby/object:Gem::Version
         | 
| 205 | 
            +
                  version: '0'
         | 
| 206 | 
            +
            requirements: []
         | 
| 207 | 
            +
            rubygems_version: 3.1.6
         | 
| 208 | 
            +
            signing_key:
         | 
| 209 | 
            +
            specification_version: 4
         | 
| 210 | 
            +
            summary: Logic game Codebreacker
         | 
| 211 | 
            +
            test_files: []
         |