mastermind_suzan 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/.DS_Store +0 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +233 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/mastermind +2 -0
- data/bin/setup +8 -0
- data/lib/game_engine.rb +48 -0
- data/lib/mastermind_suzan/color.rb +45 -0
- data/lib/mastermind_suzan/logic.rb +96 -0
- data/lib/mastermind_suzan/messages.rb +74 -0
- data/lib/mastermind_suzan/player.rb +12 -0
- data/lib/mastermind_suzan/validation.rb +46 -0
- data/lib/mastermind_suzan/version.rb +3 -0
- data/mastermind_suzan.gemspec +27 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47c53153fbf684eaa7b6a554099465cd6436ed29
|
4
|
+
data.tar.gz: ed4d00b7bc98e5923cb666ae62a3909cb20065d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 508de7dd28b01424c7d442dd482675b6b3903653c5138a49a615164a034970bf3582de376a20788cb95796a7e4a4008781481f67e4d158ce591edcb53d75d433
|
7
|
+
data.tar.gz: 2cf95228500712847852e4b3123ddf3421244009bc29d4ca847e1c378fd6c7ea80370f894f729ab74af41c6bce96c4fba73f9e3cca010cb32fb79b7758a81441
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "db/schema.rb"
|
5
|
+
UseCache: false
|
6
|
+
Style/CollectionMethods:
|
7
|
+
Description: Preferred collection methods.
|
8
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
9
|
+
Enabled: true
|
10
|
+
PreferredMethods:
|
11
|
+
collect: map
|
12
|
+
collect!: map!
|
13
|
+
find: detect
|
14
|
+
find_all: select
|
15
|
+
reduce: inject
|
16
|
+
Style/DotPosition:
|
17
|
+
Description: Checks the position of the dot in multi-line method calls.
|
18
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
19
|
+
Enabled: true
|
20
|
+
EnforcedStyle: trailing
|
21
|
+
SupportedStyles:
|
22
|
+
- leading
|
23
|
+
- trailing
|
24
|
+
Style/FileName:
|
25
|
+
Description: Use snake_case for source file names.
|
26
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
27
|
+
Enabled: false
|
28
|
+
Exclude: []
|
29
|
+
Style/GuardClause:
|
30
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
31
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
32
|
+
Enabled: false
|
33
|
+
MinBodyLength: 1
|
34
|
+
Style/IfUnlessModifier:
|
35
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
36
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
37
|
+
Enabled: false
|
38
|
+
MaxLineLength: 80
|
39
|
+
Style/OptionHash:
|
40
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
41
|
+
Enabled: false
|
42
|
+
Style/PercentLiteralDelimiters:
|
43
|
+
Description: Use `%`-literal delimiters consistently
|
44
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
45
|
+
Enabled: false
|
46
|
+
PreferredDelimiters:
|
47
|
+
"%": "()"
|
48
|
+
"%i": "()"
|
49
|
+
"%q": "()"
|
50
|
+
"%Q": "()"
|
51
|
+
"%r": "{}"
|
52
|
+
"%s": "()"
|
53
|
+
"%w": "()"
|
54
|
+
"%W": "()"
|
55
|
+
"%x": "()"
|
56
|
+
Style/PredicateName:
|
57
|
+
Description: Check the names of predicate methods.
|
58
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
59
|
+
Enabled: true
|
60
|
+
NamePrefix:
|
61
|
+
- is_
|
62
|
+
- has_
|
63
|
+
- have_
|
64
|
+
NamePrefixBlacklist:
|
65
|
+
- is_
|
66
|
+
Exclude:
|
67
|
+
- spec/**/*
|
68
|
+
Style/RaiseArgs:
|
69
|
+
Description: Checks the arguments passed to raise/fail.
|
70
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
71
|
+
Enabled: false
|
72
|
+
EnforcedStyle: exploded
|
73
|
+
SupportedStyles:
|
74
|
+
- compact
|
75
|
+
- exploded
|
76
|
+
Style/SignalException:
|
77
|
+
Description: Checks for proper usage of fail and raise.
|
78
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
79
|
+
Enabled: false
|
80
|
+
EnforcedStyle: semantic
|
81
|
+
SupportedStyles:
|
82
|
+
- only_raise
|
83
|
+
- only_fail
|
84
|
+
- semantic
|
85
|
+
Style/SingleLineBlockParams:
|
86
|
+
Description: Enforces the names of some block params.
|
87
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
88
|
+
Enabled: false
|
89
|
+
Methods:
|
90
|
+
- reduce:
|
91
|
+
- a
|
92
|
+
- e
|
93
|
+
- inject:
|
94
|
+
- a
|
95
|
+
- e
|
96
|
+
Style/SingleLineMethods:
|
97
|
+
Description: Avoid single-line methods.
|
98
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
99
|
+
Enabled: false
|
100
|
+
AllowIfMethodIsEmpty: true
|
101
|
+
Style/StringLiterals:
|
102
|
+
Description: Checks if uses of quotes match the configured preference.
|
103
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
104
|
+
Enabled: true
|
105
|
+
EnforcedStyle: double_quotes
|
106
|
+
SupportedStyles:
|
107
|
+
- single_quotes
|
108
|
+
- double_quotes
|
109
|
+
Style/StringLiteralsInInterpolation:
|
110
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
111
|
+
match the configured preference.
|
112
|
+
Enabled: true
|
113
|
+
EnforcedStyle: single_quotes
|
114
|
+
SupportedStyles:
|
115
|
+
- single_quotes
|
116
|
+
- double_quotes
|
117
|
+
Style/TrailingCommaInLiteral:
|
118
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
119
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
120
|
+
Enabled: false
|
121
|
+
EnforcedStyleForMultiline: no_comma
|
122
|
+
SupportedStyles:
|
123
|
+
- comma
|
124
|
+
- no_comma
|
125
|
+
Metrics/AbcSize:
|
126
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
127
|
+
conditions.
|
128
|
+
Enabled: false
|
129
|
+
Max: 15
|
130
|
+
Metrics/ClassLength:
|
131
|
+
Description: Avoid classes longer than 100 lines of code.
|
132
|
+
Enabled: false
|
133
|
+
CountComments: false
|
134
|
+
Max: 100
|
135
|
+
Metrics/ModuleLength:
|
136
|
+
CountComments: false
|
137
|
+
Max: 100
|
138
|
+
Description: Avoid modules longer than 100 lines of code.
|
139
|
+
Enabled: false
|
140
|
+
Metrics/CyclomaticComplexity:
|
141
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
142
|
+
cases needed to validate a method.
|
143
|
+
Enabled: false
|
144
|
+
Max: 6
|
145
|
+
Metrics/MethodLength:
|
146
|
+
Description: Avoid methods longer than 10 lines of code.
|
147
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
148
|
+
Enabled: false
|
149
|
+
CountComments: false
|
150
|
+
Max: 10
|
151
|
+
Metrics/ParameterLists:
|
152
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
153
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
154
|
+
Enabled: false
|
155
|
+
Max: 5
|
156
|
+
CountKeywordArgs: true
|
157
|
+
Metrics/PerceivedComplexity:
|
158
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
159
|
+
reader.
|
160
|
+
Enabled: false
|
161
|
+
Max: 7
|
162
|
+
Lint/AssignmentInCondition:
|
163
|
+
Description: Don't use assignment in conditions.
|
164
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
165
|
+
Enabled: false
|
166
|
+
AllowSafeAssignment: true
|
167
|
+
Style/InlineComment:
|
168
|
+
Description: Avoid inline comments.
|
169
|
+
Enabled: false
|
170
|
+
Style/AccessorMethodName:
|
171
|
+
Description: Check the naming of accessor methods for get_/set_.
|
172
|
+
Enabled: false
|
173
|
+
Style/Alias:
|
174
|
+
Description: Use alias_method instead of alias.
|
175
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
176
|
+
Enabled: false
|
177
|
+
Style/Documentation:
|
178
|
+
Description: Document classes and non-namespace modules.
|
179
|
+
Enabled: false
|
180
|
+
Style/DoubleNegation:
|
181
|
+
Description: Checks for uses of double negation (!!).
|
182
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
183
|
+
Enabled: false
|
184
|
+
Style/EachWithObject:
|
185
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
186
|
+
Enabled: false
|
187
|
+
Style/EmptyLiteral:
|
188
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
189
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
190
|
+
Enabled: false
|
191
|
+
Style/ModuleFunction:
|
192
|
+
Description: Checks for usage of `extend self` in modules.
|
193
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
194
|
+
Enabled: false
|
195
|
+
Style/OneLineConditional:
|
196
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
197
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
198
|
+
Enabled: false
|
199
|
+
Style/PerlBackrefs:
|
200
|
+
Description: Avoid Perl-style regex back references.
|
201
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
202
|
+
Enabled: false
|
203
|
+
Style/Send:
|
204
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
205
|
+
may overlap with existing methods.
|
206
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
207
|
+
Enabled: false
|
208
|
+
Style/SpecialGlobalVars:
|
209
|
+
Description: Avoid Perl-style global variables.
|
210
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
211
|
+
Enabled: false
|
212
|
+
Style/VariableInterpolation:
|
213
|
+
Description: Don't interpolate global, instance and class variables directly in
|
214
|
+
strings.
|
215
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
216
|
+
Enabled: false
|
217
|
+
Style/WhenThen:
|
218
|
+
Description: Use when x then ... for one-line cases.
|
219
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
220
|
+
Enabled: false
|
221
|
+
Lint/EachWithObjectArgument:
|
222
|
+
Description: Check for immutable argument given to each_with_object.
|
223
|
+
Enabled: true
|
224
|
+
Lint/HandleExceptions:
|
225
|
+
Description: Don't suppress exception.
|
226
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
227
|
+
Enabled: false
|
228
|
+
Lint/LiteralInCondition:
|
229
|
+
Description: Checks of literals used in conditions.
|
230
|
+
Enabled: false
|
231
|
+
Lint/LiteralInInterpolation:
|
232
|
+
Description: Checks for literals used in interpolation.
|
233
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at TODO: Write your email address. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 TODO: Write your name
|
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,55 @@
|
|
1
|
+
# MastermindSuzan
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/andela-oesho/mastermind_suzan)
|
4
|
+
[](https://codeclimate.com/github/andela-oesho/mastermind_suzan/coverage)
|
5
|
+
|
6
|
+
Welcome to Mastermind by suzan. An interactive gem packaged and played in a ruby environment.
|
7
|
+
|
8
|
+
##About Mastermind
|
9
|
+
|
10
|
+
Mastermind or Master Mind is a code-breaking game. The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It resembles an earlier pencil and paper game called Bulls and Cows that may date back a century or more.
|
11
|
+
|
12
|
+
The player decides in advance how many games they will play, which must be an even number. The computer is the codemaker, the player is the codebreaker. The codemaker chooses a pattern of colours. Duplicates are allowed. The codebreaker tries to figure out the pattern with a limited number of guesses.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
The User should have ruby set on his pc
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```rub
|
21
|
+
gem 'mastermind_suzan'
|
22
|
+
```
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install /mastermind_suzan
|
30
|
+
|
31
|
+
## Game Play
|
32
|
+
|
33
|
+
* A splash screen is showed once a game is started from where the user can start a game or read instructions.
|
34
|
+
* A random code of varying legth is generated depending on the level selected by the user.
|
35
|
+
* You have twelve guesses per game.
|
36
|
+
* On every guess, you are presented with a message identifying the number of elements you got correctly, and in what positions.
|
37
|
+
* To view entry history, enter h or history at any time.
|
38
|
+
* To view sequence generated, enter c or cheat at any time
|
39
|
+
* To quit the game at any point enter q or quit.
|
40
|
+
* The game is timed and on successful completion, the user gets a detail of his performance and a top players list is
|
41
|
+
displayed
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/andela-oesho/mastermind_suzan/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "game_run"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/mastermind
ADDED
data/bin/setup
ADDED
data/lib/game_engine.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "mastermind_suzan/messages"
|
2
|
+
require "mastermind_suzan/logic"
|
3
|
+
require "mastermind_suzan/player"
|
4
|
+
require "mastermind_suzan/validation"
|
5
|
+
require "mastermind_suzan/color"
|
6
|
+
|
7
|
+
|
8
|
+
module MastermindSuzan
|
9
|
+
class GameEngine
|
10
|
+
include Messages
|
11
|
+
attr_accessor :player, :logic
|
12
|
+
|
13
|
+
def start
|
14
|
+
puts welcome_user
|
15
|
+
input = gets.chomp.downcase
|
16
|
+
case input
|
17
|
+
when "p", "play" then play
|
18
|
+
when "i", "instructions" then game_guide
|
19
|
+
when "q", "quit" then exit
|
20
|
+
else
|
21
|
+
exit_game
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def play
|
26
|
+
player_level
|
27
|
+
@logic = Logic.new(player)
|
28
|
+
until player.guesses.length >= 12
|
29
|
+
logic.set_user_input
|
30
|
+
logic.process_guess
|
31
|
+
end
|
32
|
+
logic.sequence_code
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
def player_level
|
37
|
+
puts level_message
|
38
|
+
level = gets.chomp.downcase
|
39
|
+
@player = Player.new(level)
|
40
|
+
player.gamecolor = Color.new.set(level)
|
41
|
+
end
|
42
|
+
|
43
|
+
def exit_game
|
44
|
+
puts character_check
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative "messages"
|
2
|
+
|
3
|
+
module MastermindSuzan
|
4
|
+
class Color
|
5
|
+
include Messages
|
6
|
+
BEGINNER = %w(r g b y).freeze
|
7
|
+
INTERMEDIATE = %w(r g b y w).freeze
|
8
|
+
ADVANCED = %w(r g b y w p).freeze
|
9
|
+
|
10
|
+
def set(level)
|
11
|
+
case level
|
12
|
+
when "b", "beginner" then beginner
|
13
|
+
when "i", "intermediate" then intermediate
|
14
|
+
when "a", "advanced" then advanced
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def beginner
|
19
|
+
puts beginner_level_message
|
20
|
+
random_sequence = []
|
21
|
+
4.times do
|
22
|
+
random_sequence << BEGINNER.sample
|
23
|
+
end
|
24
|
+
random_sequence
|
25
|
+
end
|
26
|
+
|
27
|
+
def intermediate
|
28
|
+
puts intermediate_level_message
|
29
|
+
random_sequence = []
|
30
|
+
6.times do
|
31
|
+
random_sequence << INTERMEDIATE.sample
|
32
|
+
end
|
33
|
+
random_sequence
|
34
|
+
end
|
35
|
+
|
36
|
+
def advanced
|
37
|
+
puts advanced_level_message
|
38
|
+
random_sequence = []
|
39
|
+
8.times do
|
40
|
+
random_sequence << ADVANCED.sample
|
41
|
+
end
|
42
|
+
random_sequence
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative "validation"
|
2
|
+
require_relative "messages"
|
3
|
+
require_relative "color"
|
4
|
+
require_relative "player"
|
5
|
+
require "byebug"
|
6
|
+
|
7
|
+
module MastermindSuzan
|
8
|
+
class Logic
|
9
|
+
include Messages
|
10
|
+
attr_accessor :user_input, :perfect_match_count, :validation, :player
|
11
|
+
attr_reader :partial_match_count, :count
|
12
|
+
|
13
|
+
def initialize(player)
|
14
|
+
@player = player
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_user_input
|
18
|
+
@validation = Validation.new(player)
|
19
|
+
@user_input = validation.collect_guess
|
20
|
+
if history_or_cheat?
|
21
|
+
display_history_or_cheat
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def history_or_cheat?
|
26
|
+
history_and_cheat_views_arr = %w(h c history cheat)
|
27
|
+
history_and_cheat_views_arr.include? user_input.join("")
|
28
|
+
end
|
29
|
+
|
30
|
+
def display_history_or_cheat
|
31
|
+
case user_input.join("")
|
32
|
+
when "h", "history" then guess_history
|
33
|
+
when "c", "cheat" then sequence_code
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def guess_history
|
38
|
+
puts history_header
|
39
|
+
player.guesses.each_with_index do |guess, index|
|
40
|
+
history_input = guess.split(",")
|
41
|
+
history_input.delete(history_input.last)
|
42
|
+
puts history_message(index, guess, history_input)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def sequence_code
|
47
|
+
puts sequence_code_message(player)
|
48
|
+
end
|
49
|
+
|
50
|
+
def zip_code_with_guess
|
51
|
+
player.gamecolor.zip(user_input)
|
52
|
+
end
|
53
|
+
|
54
|
+
def process_guess
|
55
|
+
if user_input == player.gamecolor
|
56
|
+
player.duration = Time.now - player.start_time
|
57
|
+
puts congrats_message(player)
|
58
|
+
replay_game
|
59
|
+
else
|
60
|
+
select_perfect_matches
|
61
|
+
select_partial_matches
|
62
|
+
feedback_to_user
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def select_perfect_matches
|
67
|
+
perfect_matches = zip_code_with_guess.select { |elem| elem[0] == elem[1] }
|
68
|
+
@perfect_match_count = perfect_matches.count
|
69
|
+
end
|
70
|
+
|
71
|
+
def select_partial_matches
|
72
|
+
partial_matches = zip_code_with_guess.select { |elem| elem[0] != elem[1] }
|
73
|
+
system_partial_match, user_partial_match = partial_matches.transpose
|
74
|
+
partial_color_match = []
|
75
|
+
user_partial_match.each do |element|
|
76
|
+
if system_partial_match.include? element
|
77
|
+
system_partial_match.delete_at(system_partial_match.index(element))
|
78
|
+
partial_color_match << element
|
79
|
+
end
|
80
|
+
@partial_match_count = partial_color_match.count
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def feedback_to_user
|
85
|
+
unless history_or_cheat?
|
86
|
+
player.guesses << feedback_message(user_input, perfect_match_count, partial_match_count, @player.guesses.length)
|
87
|
+
puts player.guesses.last
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def replay_game
|
92
|
+
puts play_again
|
93
|
+
validation.check_replay_input
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module MastermindSuzan
|
2
|
+
module Messages
|
3
|
+
def welcome_user
|
4
|
+
"Welcome to Mastermind\n Would you like to (p)lay, read the (i)instructions, or (q)uit?"
|
5
|
+
end
|
6
|
+
|
7
|
+
def beginner_level_message
|
8
|
+
"I have generated a beginner sequence with four elements made up of: (r)ed, (g)reen, (b)lue, and (y)ellow. \n Use (q)uit at any time to end the game. What's your guess?\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def intermediate_level_message
|
12
|
+
"I have generated an intermediate sequence with six elements made up of: (r)ed, (g)reen, (b)lue, (y)ellow, and (w)hite. \n Use (q)uit at any time to end the game. What's your guess?\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
def advanced_level_message
|
16
|
+
"I have generated an advanced sequence with eight elements made up of: (r)ed, (g)reen, (b)lue, (y)ellow, (w)hite, (y)ellow, and (p)urple. \n Use (q)uit at any time to end the game. What's your guess?\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def game_guide
|
20
|
+
"\nOnce game starts, a random code is generated and you're asked to guess what the code is.
|
21
|
+
Every code is a four/five/six digit word made up by the letters [r, g, b, y]/[r, g, b, y, w]/[r, g, b, y, w, p]
|
22
|
+
depending on difficulty levels beginner/intermediate/advanced levels. You have twelve guesses per game.
|
23
|
+
On every guess, you are presented with a message identifying the number of elements you got correctly, and in what positions.
|
24
|
+
To view entry history, enter h or history at any time
|
25
|
+
To view sequence generated, enter c or cheat at any time
|
26
|
+
To quit the game at any point enter q or quit\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def feedback_message(userinput, perfect_match_count, partial_match_count, count)
|
30
|
+
"#{userinput.join} has #{perfect_match_count + partial_match_count} correct element, you have #{perfect_match_count} in the correct position, you have taken #{count + 1} guess"
|
31
|
+
end
|
32
|
+
|
33
|
+
def short_input
|
34
|
+
"Your input is too short"
|
35
|
+
end
|
36
|
+
|
37
|
+
def long_input
|
38
|
+
"Your input is too long"
|
39
|
+
end
|
40
|
+
|
41
|
+
def congrats_message(player)
|
42
|
+
"Congratulations! you guessed the sequence #{player.gamecolor.join} in #{player.guesses.length} guess(es) over #{player.duration}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def play_again
|
46
|
+
"Do you want to (p)lay again or (q)uit?"
|
47
|
+
end
|
48
|
+
|
49
|
+
def level_message
|
50
|
+
"choose a level, (b)eginner, (i)ntermediate or (a)dvanced? "
|
51
|
+
end
|
52
|
+
|
53
|
+
def sequence_code_message(player)
|
54
|
+
"The sequence generated is #{player.gamecolor.join}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_input
|
58
|
+
"Please enter a valid input"
|
59
|
+
end
|
60
|
+
|
61
|
+
def character_check
|
62
|
+
"Invalid character exiting.............."
|
63
|
+
end
|
64
|
+
|
65
|
+
def history_header
|
66
|
+
"A display of your history below"
|
67
|
+
end
|
68
|
+
|
69
|
+
def history_message(index, guess, history_input)
|
70
|
+
"(#{index + 1}) Your input '#{history_input.join(',').
|
71
|
+
gsub(/have|has/, 'had').gsub('you had', 'and')}'"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative "logic"
|
2
|
+
# require_relative "game_engine"
|
3
|
+
require "byebug"
|
4
|
+
|
5
|
+
module MastermindSuzan
|
6
|
+
class Validation
|
7
|
+
include Messages
|
8
|
+
attr_accessor :player, :guess
|
9
|
+
|
10
|
+
def initialize(player)
|
11
|
+
@player = player
|
12
|
+
end
|
13
|
+
|
14
|
+
def collect_guess
|
15
|
+
loop do
|
16
|
+
@guess = gets.chomp.downcase
|
17
|
+
break if check_valid_input?(guess)
|
18
|
+
input_error(guess.length)
|
19
|
+
end
|
20
|
+
guess.split("")
|
21
|
+
end
|
22
|
+
|
23
|
+
def input_error(guess_length)
|
24
|
+
if guess_length < player.gamecolor.length
|
25
|
+
puts short_input
|
26
|
+
else
|
27
|
+
puts long_input
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_replay_input
|
32
|
+
player_input = gets.chomp.downcase
|
33
|
+
if player_input == "p" || player_input == "play"
|
34
|
+
GameEngine.new.start
|
35
|
+
else
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_valid_input?(guess)
|
41
|
+
history_cheat_view_arr = %w(h c history cheat)
|
42
|
+
return true if history_cheat_view_arr.include? guess
|
43
|
+
guess.length == player.gamecolor.length
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mastermind_suzan/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mastermind_suzan"
|
8
|
+
spec.version = MastermindSuzan::VERSION
|
9
|
+
spec.authors = ["Susan Esho"]
|
10
|
+
spec.email = ["susan.esho@andela.com"]
|
11
|
+
|
12
|
+
spec.summary = ["This installs mastermind on the pc."]
|
13
|
+
spec.description = ["Mastermind is a game where a user tries to"]
|
14
|
+
spec.homepage = "https://github.com/andela-oesho/mastermind_suzan"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = ["mastermind"]
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mastermind_suzan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Susan Esho
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '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: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: '["Mastermind is a game where a user tries to"]'
|
56
|
+
email:
|
57
|
+
- susan.esho@andela.com
|
58
|
+
executables:
|
59
|
+
- mastermind
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".DS_Store"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".rubocop.yml"
|
67
|
+
- ".travis.yml"
|
68
|
+
- CODE_OF_CONDUCT.md
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/mastermind
|
75
|
+
- bin/setup
|
76
|
+
- lib/game_engine.rb
|
77
|
+
- lib/mastermind_suzan/color.rb
|
78
|
+
- lib/mastermind_suzan/logic.rb
|
79
|
+
- lib/mastermind_suzan/messages.rb
|
80
|
+
- lib/mastermind_suzan/player.rb
|
81
|
+
- lib/mastermind_suzan/validation.rb
|
82
|
+
- lib/mastermind_suzan/version.rb
|
83
|
+
- mastermind_suzan.gemspec
|
84
|
+
homepage: https://github.com/andela-oesho/mastermind_suzan
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: '["This installs mastermind on the pc."]'
|
108
|
+
test_files: []
|