mastermind_generator 0.0.1.pre.pre.alpha → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b37d479689687d682817b6be649134828be6f5c06c8924c31e04808cbd39593
4
- data.tar.gz: b4877a03cf8323951a705643f8a7c1b5dcaf4198028e69ad38ad0fa716992bba
3
+ metadata.gz: f9071f9198d1f4edd135fade0eb8a6e877b4473ecea5ade19ce2b5b2ac0613a3
4
+ data.tar.gz: 376419af696ad3c77e136c335c88abe14073f65659384ece2d1fe117bc69e1a6
5
5
  SHA512:
6
- metadata.gz: 55c912aaf50dd9c4cfa42b9e3782c5d1c9d1263cfab49957c13a43e3692783eeb12ac9799581e0050d6f879bca0fced7dee6cffa4a790a8d258e717c27a6fae2
7
- data.tar.gz: 319c2edd011d3cf3e1659d061d215b40fe2e28326f0eb301459ae32151df339ac0a04332d89956a6dd4d1ecb253f36aa7b3d8d5ac06f61ddb7b6307d89735b96
6
+ metadata.gz: a9e904d612999ef9ce20e10381471175f81ad7b18b4a7afdb9510dc148fd69e6617950680579247873e81540fa6a9513a2e0c1f0554211027118f778645d0d53
7
+ data.tar.gz: bb688a3c9f2ab22149949780291b2c11a05b42a37cb1df5eec86d7b04407aba3f4eebdf55c82b9bf55b41a9aaffb9fe8a5757f327e5b8475a1a6340319efef56
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-pro
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ gem "coveralls", require: false
7
8
  gem "minitest", "~> 5.14.3"
8
9
  gem "minitest-reporters", ">= 0.5.0"
9
10
  gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mastermind_generator (0.0.1.pre.pre.alpha)
4
+ mastermind_generator (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,19 +9,31 @@ GEM
9
9
  ansi (1.5.0)
10
10
  ast (2.4.2)
11
11
  builder (3.2.4)
12
+ coveralls (0.7.2)
13
+ multi_json (~> 1.3)
14
+ rest-client (= 1.6.7)
15
+ simplecov (>= 0.7)
16
+ term-ansicolor (= 1.2.2)
17
+ thor (= 0.18.1)
12
18
  docile (1.3.5)
19
+ mime-types (3.3.1)
20
+ mime-types-data (~> 3.2015)
21
+ mime-types-data (3.2021.0225)
13
22
  minitest (5.14.4)
14
23
  minitest-reporters (1.4.3)
15
24
  ansi
16
25
  builder
17
26
  minitest (>= 5.0)
18
27
  ruby-progressbar
28
+ multi_json (1.15.0)
19
29
  parallel (1.20.1)
20
30
  parser (3.0.0.0)
21
31
  ast (~> 2.4.1)
22
32
  rainbow (3.0.0)
23
33
  rake (13.0.3)
24
34
  regexp_parser (2.1.1)
35
+ rest-client (1.6.7)
36
+ mime-types (>= 1.16)
25
37
  rexml (3.2.4)
26
38
  rubocop (1.8.1)
27
39
  parallel (~> 1.10)
@@ -43,6 +55,10 @@ GEM
43
55
  simplecov_json_formatter (~> 0.1)
44
56
  simplecov-html (0.12.3)
45
57
  simplecov_json_formatter (0.1.2)
58
+ term-ansicolor (1.2.2)
59
+ tins (~> 0.8)
60
+ thor (0.18.1)
61
+ tins (0.13.2)
46
62
  unicode-display_width (2.0.0)
47
63
 
48
64
  PLATFORMS
@@ -50,6 +66,7 @@ PLATFORMS
50
66
  x86_64-linux
51
67
 
52
68
  DEPENDENCIES
69
+ coveralls
53
70
  mastermind_generator!
54
71
  minitest (~> 5.14.3)
55
72
  minitest-reporters (>= 0.5.0)
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # MastermindGenerator
2
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/mastermind_generator`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/mastermind_generator.svg)](https://badge.fury.io/rb/mastermind_generator)
4
+ [![Build Status](https://travis-ci.com/sbagdat/mastermind_generator.svg?token=eLjuyGgeA2bT8BPBsdDh&branch=main)](https://travis-ci.com/sbagdat/mastermind_generator)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ Mastermind<sup>*</sup> Generator is a fully customizable mastermind (or master mind) game generator. It supports using
7
+ custom items other than classic color variations. It can also generate multi-player games.
8
+
9
+ If you are looking for a playable version of Mastermind, you can look at
10
+ [demo folder](https://github.com/sbagdat/mastermind_generator/tree/main/demo).
11
+
12
+ <sup>*</sup> Mastermind s a code-breaking game. For more
13
+ information: [Wikipedia](https://en.wikipedia.org/wiki/Mastermind_(board_game))
6
14
 
7
15
  ## Installation
8
16
 
@@ -20,19 +28,188 @@ Or install it yourself as:
20
28
 
21
29
  $ gem install mastermind_generator
22
30
 
23
- ## Usage
31
+ ## Configuration
32
+
33
+ Before you use mastermind generator you need to configure it. Two attributes should be supplied as shown below:
34
+ * **items:** The items array you want to play with.
35
+ * **difficulties:** Difficulty levels of your game. It must be in a ruby hash format.
36
+ * For each level,
37
+ * **item_count:** players allowed to use how many items.
38
+ * **sequence_length:** sequences must be how many characters length.
39
+
40
+ ```ruby
41
+ MastermindGenerator.configure do |config|
42
+ config.items = %w[red green blue yellow purple orange]
43
+ config.difficulties = {
44
+ beginner: {
45
+ item_count: 4,
46
+ sequence_length: 4
47
+ },
48
+ intermediate: {
49
+ item_count: 5,
50
+ sequence_length: 6
51
+ },
52
+ advanced: {
53
+ item_count: 6,
54
+ sequence_length: 8
55
+ }
56
+ }
57
+ end
58
+ ```
59
+
60
+ ## Basic Usage
61
+
62
+ Require the gem and include it in your class definition.
63
+
64
+ ```ruby
65
+ require 'mastermind_generator'
66
+ # If you write your configuration code in a seperate file uncomment the line below:
67
+ # require "path_to_your_configuration_file"
68
+
69
+ class MastermindGame
70
+ include MastermindGenerator
71
+
72
+ # your code goes here...
73
+ end
74
+ ```
75
+
76
+ Now, you can generate game objects...
77
+
78
+ ```ruby
79
+ require 'mastermind_generator'
80
+ # other requires
81
+
82
+ class MastermindGame
83
+ include MastermindGenerator
84
+
85
+ def start
86
+ # You must supply one of the difficulty level as an argument to `Game.new`
87
+ @game = Game.new(:beginner)
88
+
89
+ # You can add one or two player
90
+ @game.add_player("Aaron")
91
+ @game.add_player("Celine")
92
+
93
+ # You are ready to create a game loop however you want
94
+ # An example is shown below
95
+ loop do
96
+ # Current player takes a guess (chosen automatically)
97
+ print "Hey #{game.player.name}! What's your guess?"
98
+ guess = gets.strip.downcase
99
+ @game.take_a_guess(guess)
100
+
101
+ # Check the guess is succeed or fail
102
+ if game.finished?
103
+ puts "congrats"
104
+ break
105
+ else
106
+ puts "feedback"
107
+ end
108
+
109
+ # if the game is multi-player, you need to call `@game.next_turn`
110
+ @game.next_turn if game.players.length > 1
111
+ end
112
+ end
113
+ end
114
+ ```
115
+
116
+ ## Player Information
117
+
118
+ After you added one or two players to the game by using `add_player` method. You can reach some useful information
119
+ about player of that turn. Every `MastermindGenerator::Player` instances have these methods:
120
+
121
+ * `@game.player.guesses`: All guesses entered by current player. It might be useful to show some historical information.
122
+ * `@game.player.guess`: Last guess of the user, returns `MastermindGenerator::Guess` instance.
123
+ * `@game.player.winner?`: Returns `true` if player's latest guess is successful, otherwise returns false.
124
+ * `@game.player.timer`: Returns a `MastermindGenerator::Timer` object. You can use it to show players how much time they spent to break the code.
125
+
126
+ ## Guess Information
127
+
128
+ You can access guess instances by players. Every `MastermindGenerator::Guess` instances have these methods:
129
+
130
+ * `@game.player.guess.succeed?`: Whether the guess was successful or not.
131
+ * `@game.player.guess.correct_element_count`: How many elements were matched with the target sequence.
132
+ * `@game.player.guess.correct_position_count`: How many positions were matched with the target sequence.
133
+ * `@game.player.guess.correct_position_hints`: You can use it to show the correct positions like `R_BG__`
134
+ * `@game.player.guess.statistics`: Returns a hash that it contains all the information about the guess.
135
+
136
+ ```ruby
137
+ @game.player.guess.statistics
138
+ # # => {
139
+ # value: guess sequence value,
140
+ # target: target esequence value,
141
+ # status: successful or failed,
142
+ # count: how many guesses were made,
143
+ # element_count: correct element count,
144
+ # position_count: correct position count,
145
+ # position_hints: correct position hints
146
+ # }
147
+ ```
148
+
149
+ ## Timer Information
150
+
151
+ As we mentioned above, each `MastermindGenerator::Player` instance has a method called `#timer` that can be used to
152
+ access that player's timer. However, timers are setting up behind the scenes, you can also start, pause or stop
153
+ them by using `@game.player.timer.start`, `@game.player.timer.pause`, and `@game.player.timer.stop` methods.
154
+
155
+ Main purpose of timer objects is providing duration information like below:
156
+
157
+ ```ruby
158
+ # returns duration as seconds
159
+ @game.player.timer.duration
160
+ # 123
161
+
162
+ # returns duration as human readable text
163
+ @game.player.timer.duration_as_text
164
+ # 2 minutes, 3 seconds
165
+ ```
166
+
167
+ ## Providing Feedbacks
168
+
169
+ You can give feedbacks to your player by using the methods we mentioned above. A few example might be like these:
170
+
171
+ ```ruby
172
+ ...
173
+
174
+ def congrats
175
+ player = game.player
176
+ puts("Congratulations #{player.name}! You guessed the sequence '#{game.sequence.value.upcase}' in "\
177
+ "#{player.guesses.length} guesses over #{player.timer.duration_as_text}.")
178
+ end
179
+
180
+ def feedback
181
+ stats = player.guess.statistics
182
+ puts("'#{stats[:value].upcase}' has #{stats[:element_count]} of the correct elements with "\
183
+ " #{stats[:position_count]} in the correct positions.\nYou've taken #{stats[:count]} guess.")
184
+ end
185
+ ...
186
+ ```
24
187
 
25
- TODO: Write usage instructions here
188
+ ## Exception Handling
26
189
 
27
- ## Development
190
+ There are four error types defined in the gem with proper `#message` methods.
191
+ * SequenceTooLongError
192
+ * SequenceTooShortError
193
+ * SequenceHasInvalidCharsError
194
+ * InvalidDifficultyError
28
195
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
196
+ An example usage might be like this:
30
197
 
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).
198
+ ```ruby
199
+ begin
200
+ print("Hey #{game.player.name}! What's your guess? > ")
201
+ game.take_a_guess(gets.strip.downcase)
202
+ rescue SequenceTooLongError, SequenceTooShortError, SequenceHasInvalidCharsError => e
203
+ warn("#{e.message}. Try again!")
204
+ retry
205
+ end
206
+ ```
32
207
 
33
208
  ## Contributing
34
209
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mastermind_generator. 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]/mastermind_generator/blob/master/CODE_OF_CONDUCT.md).
210
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/mastermind_generator. This project
211
+ is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
212
+ the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).
36
213
 
37
214
  ## License
38
215
 
@@ -40,4 +217,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
217
 
41
218
  ## Code of Conduct
42
219
 
43
- Everyone interacting in the MastermindGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mastermind_generator/blob/master/CODE_OF_CONDUCT.md).
220
+ Everyone interacting in the MastermindGenerator project's codebases, issue trackers, chat rooms and mailing lists is
221
+ expected to follow
222
+ the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "rake/testtask"
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
9
+ t.test_files = FileList["./test/**/*_test.rb"]
10
10
  end
11
11
 
12
12
  require "rubocop/rake_task"
@@ -5,7 +5,7 @@ require_relative "mastermind/mg_configuration"
5
5
  require_relative "mastermind/console_interface"
6
6
 
7
7
  # Mastermind game
8
- class Mastermind
8
+ class Mastermind # rubocop:disable Metrics/ClassLength
9
9
  include MastermindGenerator
10
10
 
11
11
  def initialize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MastermindGenerator
4
- VERSION = "0.0.1.pre-alpha"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Sıtkı Bağdat"]
9
9
  spec.email = ["sbagdat@gmail.com"]
10
10
 
11
- spec.summary = "Mastermind game generator API"
12
- spec.description = "Mastermind game generator API"
11
+ spec.summary = "Fully customizable mastermind game generator."
12
+ spec.description = "Mastermind* Generator is a fully customizable mastermind (or master mind) game generator. It supports using custom items other than classic color variations. It can also generate multi-player games."
13
13
  spec.homepage = "https://github.com/sbagdat/mastermind_generator"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastermind_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.pre.alpha
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sıtkı Bağdat
@@ -10,7 +10,9 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Mastermind game generator API
13
+ description: Mastermind* Generator is a fully customizable mastermind (or master mind)
14
+ game generator. It supports using custom items other than classic color variations.
15
+ It can also generate multi-player games.
14
16
  email:
15
17
  - sbagdat@gmail.com
16
18
  executables:
@@ -18,6 +20,7 @@ executables:
18
20
  extensions: []
19
21
  extra_rdoc_files: []
20
22
  files:
23
+ - ".coveralls.yml"
21
24
  - ".gitignore"
22
25
  - ".rubocop.yml"
23
26
  - ".travis.yml"
@@ -29,16 +32,11 @@ files:
29
32
  - Rakefile
30
33
  - bin/console
31
34
  - bin/setup
32
- - demo/.rubocop.yml
33
35
  - demo/Gemfile
34
- - demo/Gemfile.lock
35
36
  - demo/README.md
36
- - demo/Rakefile
37
37
  - demo/lib/mastermind.rb
38
38
  - demo/lib/mastermind/console_interface.rb
39
39
  - demo/lib/mastermind/mg_configuration.rb
40
- - demo/test/console_interface_test.rb
41
- - demo/test/test_helper.rb
42
40
  - exe/mastermind_generator
43
41
  - lib/mastermind_generator.rb
44
42
  - lib/mastermind_generator/configuration.rb
@@ -71,12 +69,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
69
  version: 3.0.0
72
70
  required_rubygems_version: !ruby/object:Gem::Requirement
73
71
  requirements:
74
- - - ">"
72
+ - - ">="
75
73
  - !ruby/object:Gem::Version
76
- version: 1.3.1
74
+ version: '0'
77
75
  requirements: []
78
76
  rubygems_version: 3.2.5
79
77
  signing_key:
80
78
  specification_version: 4
81
- summary: Mastermind game generator API
79
+ summary: Fully customizable mastermind game generator.
82
80
  test_files: []
data/demo/.rubocop.yml DELETED
@@ -1,18 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.0
3
- NewCops: enable
4
- SuggestExtensions: false
5
- Exclude:
6
- - '**/*_test.rb'
7
- - '**/factories/*s.rb'
8
-
9
- Style/StringLiterals:
10
- Enabled: true
11
- EnforcedStyle: double_quotes
12
-
13
- Style/StringLiteralsInInterpolation:
14
- Enabled: true
15
- EnforcedStyle: double_quotes
16
-
17
- Layout/LineLength:
18
- Max: 120
data/demo/Gemfile.lock DELETED
@@ -1,57 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- ansi (1.5.0)
5
- ast (2.4.2)
6
- builder (3.2.4)
7
- docile (1.3.5)
8
- mastermind_generator (0.0.1.pre.pre.alpha)
9
- minitest (5.14.4)
10
- minitest-reporters (1.4.3)
11
- ansi
12
- builder
13
- minitest (>= 5.0)
14
- ruby-progressbar
15
- parallel (1.20.1)
16
- parser (3.0.0.0)
17
- ast (~> 2.4.1)
18
- rainbow (3.0.0)
19
- rake (13.0.3)
20
- regexp_parser (2.1.1)
21
- rexml (3.2.4)
22
- rubocop (1.11.0)
23
- parallel (~> 1.10)
24
- parser (>= 3.0.0.0)
25
- rainbow (>= 2.2.2, < 4.0)
26
- regexp_parser (>= 1.8, < 3.0)
27
- rexml
28
- rubocop-ast (>= 1.2.0, < 2.0)
29
- ruby-progressbar (~> 1.7)
30
- unicode-display_width (>= 1.4.0, < 3.0)
31
- rubocop-ast (1.4.1)
32
- parser (>= 2.7.1.5)
33
- rubocop-minitest (0.10.3)
34
- rubocop (>= 0.87, < 2.0)
35
- ruby-progressbar (1.11.0)
36
- simplecov (0.21.2)
37
- docile (~> 1.1)
38
- simplecov-html (~> 0.11)
39
- simplecov_json_formatter (~> 0.1)
40
- simplecov-html (0.12.3)
41
- simplecov_json_formatter (0.1.2)
42
- unicode-display_width (2.0.0)
43
-
44
- PLATFORMS
45
- x86_64-darwin-20
46
-
47
- DEPENDENCIES
48
- mastermind_generator
49
- minitest (>= 5.14.3)
50
- minitest-reporters (>= 0.5.0)
51
- rake (>= 13.0.3)
52
- rubocop (>= 1.8.1)
53
- rubocop-minitest (>= 0.10.3)
54
- simplecov (>= 0.21.2)
55
-
56
- BUNDLED WITH
57
- 2.2.5
data/demo/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rake/testtask"
4
- require "rubocop/rake_task"
5
-
6
- Rake::TestTask.new do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- RuboCop::RakeTask.new
13
-
14
- task default: %i[test rubocop]
@@ -1,39 +0,0 @@
1
- require 'stringio'
2
- require './test/test_helper'
3
- require 'mastermind/console_interface'
4
-
5
- class ConsoleInterfaceTest < MiniTest::Test
6
-
7
- def test_it_exists
8
- console_interface = ConsoleInterface.new
9
-
10
- assert_instance_of ConsoleInterface, console_interface
11
- end
12
-
13
- def test_it_can_print_a_message
14
- output = StringIO.new
15
- console_interface = ConsoleInterface.new(output: output)
16
- message = 'Hello'
17
-
18
- console_interface.print_message(message)
19
-
20
- assert_match(/#{message}/, output.string)
21
- end
22
-
23
- def test_it_can_ask_a_question
24
- output = StringIO.new
25
- console_interface = ConsoleInterface.new(output: output)
26
- question = 'Would you like to continue'
27
-
28
- console_interface.ask_question(question)
29
-
30
- assert_match(/Would you like to continue/, output.string)
31
- end
32
-
33
- def test_it_can_get_answer
34
- input = StringIO.new('input')
35
- console_interface = ConsoleInterface.new(input: input)
36
-
37
- assert_equal 'input', console_interface.answer
38
- end
39
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
-
5
- require "simplecov"
6
- SimpleCov.start
7
-
8
- require "minitest/autorun"
9
- require "minitest/unit"
10
- require "mocha/minitest"
11
- require "minitest/pride"