chadet 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +68 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chadet.gemspec +11 -7
- data/{bin → exe}/chadet +33 -117
- data/lib/Rules_Of_The_Game_/342/226/274_ +3 -3
- data/lib/chadet.rb +12 -63
- data/lib/chadet/version.rb +1 -1
- metadata +56 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eecdee727fbc249514e491698dec16dd98c9ae3
|
4
|
+
data.tar.gz: ebbc3b03a31c812fb406c4a6d8b294a44cec6f7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1129d53b12523c4fcb9ef652ac1c3b910a912cb6c9444fa18333f835d3f5816b3cd983f8fe67c9a74943a0b39dfd1a7188ca8426a5e815db16aa6c35a89ec105
|
7
|
+
data.tar.gz: c621dd3d5ae6ef85ba94f0230c24aee3792ca617e4f7eba6231e3e4c963bd9183c043b1349a28d1c56b8935b37378e4c9843fbece177dcc0d05ee62b6d0d2b7c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the a.styd@yahoo.com. All complaints will be reviewed and
|
59
|
+
investigated and will result in a response that is deemed necessary and
|
60
|
+
appropriate to the circumstances. The project team is obligated to maintain
|
61
|
+
confidentiality with regard to the reporter of an incident. Further details of
|
62
|
+
specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Chadet
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/styd/chadet.svg?branch=master)](https://travis-ci.org/styd/chadet)
|
4
|
+
|
5
|
+
## Background
|
6
|
+
|
7
|
+
This game is taken from the game that was played on paper by me and my friends
|
8
|
+
back in high school (although back then we only played it with 4 numbers, 1, 2,
|
9
|
+
3, and 4). We were even doing some small competitions among us for
|
10
|
+
this game and it was fun. But, sadly, nobody is playing this now, so I kinda
|
11
|
+
miss it.
|
12
|
+
|
13
|
+
I search through for the game on the internet and I found
|
14
|
+
[something similar](https://en.wikipedia.org/wiki/Bulls_and_Cows)
|
15
|
+
but not quite. So, I thought, hey, I can make this. And this is it.
|
16
|
+
|
17
|
+
It's still a simple terminal game. No fancy playing against computer yet.
|
18
|
+
Instead you just guess random characters generated by the computer and the
|
19
|
+
computer will give you the number of correct characters and correct positions.
|
20
|
+
|
21
|
+
## Preview
|
22
|
+
|
23
|
+
$ chadet
|
24
|
+
|
25
|
+
<a href="https://asciinema.org/a/51a6mqyp4fwwc1838nilhrqzp" target="_blank"><img src="https://asciinema.org/a/51a6mqyp4fwwc1838nilhrqzp.png" width="480"/></a>
|
26
|
+
|
27
|
+
|
28
|
+
$ chadet --chars=abc
|
29
|
+
|
30
|
+
<a href="https://asciinema.org/a/ae15mib039s4b403kxjbaf9rd" target="_blank"><img src="https://asciinema.org/a/ae15mib039s4b403kxjbaf9rd.png" width="480"/></a>
|
31
|
+
|
32
|
+
|
33
|
+
$ chadet --number=2 --chars=123
|
34
|
+
|
35
|
+
<a href="https://asciinema.org/a/bukjpuusxdamxpsl7jwjc90x7" target="_blank"><img src="https://asciinema.org/a/bukjpuusxdamxpsl7jwjc90x7.png" width="480"/></a>
|
36
|
+
|
37
|
+
## Requirements
|
38
|
+
|
39
|
+
This game needs `bash` and `xterm` to run properly.
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
$ gem install chadet
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
Read the rules of the game by typing `chadet --rules` or simply `chadet -r`. You will find out how to play the game.
|
48
|
+
|
49
|
+
<a href="https://asciinema.org/a/3o3v62f4faft0gnuqq1j9urhb" target="_blank"><img src="https://asciinema.org/a/3o3v62f4faft0gnuqq1j9urhb.png" width="480"/></a>
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
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.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/styd/chadet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
|
63
|
+
* Write actual test.
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
68
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chadet"
|
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/setup
ADDED
data/chadet.gemspec
CHANGED
@@ -6,17 +6,21 @@ require 'chadet/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "chadet"
|
8
8
|
spec.version = Chadet::VERSION
|
9
|
-
spec.date = "2015-08-20"
|
10
|
-
|
11
9
|
spec.authors = ["Adrian Setyadi"]
|
12
10
|
spec.email = ["a.styd@yahoo.com"]
|
11
|
+
|
13
12
|
spec.summary = %q{Characters Detective: A command line game of guessing random characters intelligently.}
|
14
13
|
spec.description = %q{Characters Detective: A command line game of guessing random characters intelligently. Computer will generate a random set of characters. The default number of characters is 4 and the default set of characters is decimal digits from 0 to 9. After each guess you make, computer will tell you how many characters you guessed correctly and how many characters that their position you guessed correctly. Next, you can guess intelligently based on the previous answers.}
|
15
14
|
spec.homepage = "https://github.com/styd/chadet"
|
16
15
|
spec.license = "MIT"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
spec.
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
|
-
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
end
|
data/{bin → exe}/chadet
RENAMED
@@ -6,37 +6,16 @@ require 'chadet'
|
|
6
6
|
|
7
7
|
class String
|
8
8
|
# define methods for coloring text
|
9
|
-
colors = {:
|
9
|
+
colors = {red: 31, green: 32, yellow: 33, blue: 34, cyan: 36, code: 7}
|
10
10
|
colors.each do |k, v|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def flash seconds = 2
|
19
|
-
info = " " + self
|
20
|
-
print info
|
21
|
-
sleep seconds
|
22
|
-
print "\r" + " "*info.gsub(/\e\[\d*m(.*)\e\[0m/, '\1').length
|
23
|
-
print "\r"
|
24
|
-
end
|
11
|
+
define_method(k) do
|
12
|
+
str = case k
|
13
|
+
when :code then " #{self} "
|
14
|
+
else "#{self}"
|
15
|
+
end
|
25
16
|
|
26
|
-
|
27
|
-
info = " " + self
|
28
|
-
print "\n"
|
29
|
-
x = num_of_times
|
30
|
-
x.times do
|
31
|
-
print info.gsub(/[\w!?\.\'\(\)˚\-。ー\;\/\"\:<>+,★·.·´¯`░]/, " ")
|
32
|
-
sleep 0.18*x/4
|
33
|
-
print (info.lines.length == 1 ? "\r" : "\r\e[#{info.lines.count-1}A")
|
34
|
-
print info.yellow
|
35
|
-
sleep 0.1
|
36
|
-
print (info.lines.length == 1 ? "\r" : "\r\e[#{info.lines.count-1}A")
|
37
|
-
x -= 0.2
|
17
|
+
return "\e[#{v}m#{str}\e[0m"
|
38
18
|
end
|
39
|
-
puts info.yellow
|
40
19
|
end
|
41
20
|
|
42
21
|
def flash seconds = 2
|
@@ -64,67 +43,6 @@ class String
|
|
64
43
|
end
|
65
44
|
end
|
66
45
|
|
67
|
-
def finish_game
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
def display saved_games
|
72
|
-
puts "---------------------------------------------"
|
73
|
-
puts " Game | Saved at"
|
74
|
-
puts "---------------------------------------------"
|
75
|
-
saved_games.each do |game|
|
76
|
-
time = DateTime.parse("20"+game.to_i(36).to_s)
|
77
|
-
saved_at = time.strftime('%a, %b %d, %Y => %I:%M:%S %p')
|
78
|
-
puts "#{game.code} | #{saved_at}"
|
79
|
-
end
|
80
|
-
puts "---------------------------------------------"
|
81
|
-
end
|
82
|
-
|
83
|
-
def load filename
|
84
|
-
# move to data directory
|
85
|
-
Dir.chdir(File.dirname(__FILE__))
|
86
|
-
Dir.chdir('..')
|
87
|
-
Dir.mkdir("data") unless Dir.exists?("data")
|
88
|
-
Dir.chdir("data")
|
89
|
-
filename = filename + ".csv"
|
90
|
-
if filename != "file.csv" && File.exists?(filename)
|
91
|
-
|
92
|
-
# @loaded = true
|
93
|
-
# table_width = 15 + @num_of_chars + 2*@num_of_chars.to_s.length
|
94
|
-
# print "\r\e[#{guess_object.guess_num+3}A"
|
95
|
-
# print (" "*table_width + "\n")*(guess_object.guess_num+3)
|
96
|
-
# print "\r\e[#{guess_object.guess_num+3}A"
|
97
|
-
# saved_game = File.read(work_dir + "/" + filename + ".4dig")
|
98
|
-
# saved_game_arr = saved_game.split("\n")
|
99
|
-
# @chars_set = saved_game_arr[1]
|
100
|
-
# @secret_chars = saved_game_arr[4]
|
101
|
-
# secret_object.secret_chars = @secret_chars
|
102
|
-
# @num_of_chars = @secret_chars.length
|
103
|
-
# @hint_used = saved_game_arr[7].to_i
|
104
|
-
# @max_hint = (@chars_set.length/@num_of_chars).to_i
|
105
|
-
# @moves = saved_game_arr[10..-1]
|
106
|
-
# guess_object.guess_num = @moves.length
|
107
|
-
# chars_to_use
|
108
|
-
# table_header
|
109
|
-
# @moves = @moves.inject("") {|result, line| result + line + "\n"}
|
110
|
-
# puts @moves
|
111
|
-
# else
|
112
|
-
# "No saved game with that name.".yellow.flash 1.5
|
113
|
-
# end
|
114
|
-
else
|
115
|
-
# list all saved game
|
116
|
-
saved_games = Dir.glob("*.csv").map { |x| x.sub! '.csv', '' }
|
117
|
-
if saved_games.count > 0
|
118
|
-
display saved_games
|
119
|
-
else
|
120
|
-
puts "No saved game is found."
|
121
|
-
end
|
122
|
-
end
|
123
|
-
# move back to parent directory
|
124
|
-
Dir.chdir('..')
|
125
|
-
exit
|
126
|
-
end
|
127
|
-
|
128
46
|
# Save original terminal rows and columns size
|
129
47
|
term_cols = `tput cols`.chomp
|
130
48
|
term_rows = `tput lines`.chomp
|
@@ -134,18 +52,18 @@ options = {}
|
|
134
52
|
|
135
53
|
# Create an option parser object to describe the type of options and their description
|
136
54
|
optparse = OptionParser.new do |opts|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
55
|
+
opts.banner = "Usage:\n\n"
|
56
|
+
+ " chadet "
|
57
|
+
+ "[Options] Number... [Options] Characters... [Options]\n\n"
|
58
|
+
+ "Description:\n\n"
|
59
|
+
+ " Characters Detective.\n"
|
60
|
+
+ " A game of guessing random characters intelligently. The default number\n"
|
61
|
+
+ " of characters to guess is 4 and the default set of characters to guess\n"
|
62
|
+
+ " with is decimal digits from 0 to 9. After each guess you make, computer\n"
|
63
|
+
+ " will tell you how many characters you guessed correctly and how many\n"
|
64
|
+
+ " characters that their positions you guessed correctly. Next, you can\n"
|
65
|
+
+ " guess intelligently based on the previous answers.\n\n"
|
66
|
+
+ "Options:\n\n"
|
149
67
|
|
150
68
|
opts.on '-r', '--rules', 'How to play this game' do
|
151
69
|
Dir.chdir(File.dirname(__FILE__))
|
@@ -162,20 +80,13 @@ optparse = OptionParser.new do |opts|
|
|
162
80
|
end
|
163
81
|
|
164
82
|
options[:characters] = "0123456789"
|
165
|
-
opts.on '-c', '--
|
83
|
+
opts.on '-c', '--chars CHARS SET', 'Set of characters you want to play' do |chars|
|
166
84
|
options[:characters] = chars
|
167
85
|
end
|
168
|
-
|
86
|
+
|
169
87
|
options[:test] = false
|
170
88
|
opts.on '-t', '--test [TEST MODE]', 'Display the characters to guess' do
|
171
89
|
options[:test] = true
|
172
|
-
end
|
173
|
-
|
174
|
-
options[:load] = "file"
|
175
|
-
opts.on '-l', '--load [SAVED GAME]', String, 'Load saved game' do |game|
|
176
|
-
options[:load] = game unless game.nil?
|
177
|
-
load options[:load]
|
178
|
-
exit
|
179
90
|
end
|
180
91
|
|
181
92
|
opts.on '-h', '--help', 'Display this message' do
|
@@ -210,6 +121,10 @@ if chars_set.length < 2
|
|
210
121
|
print "Chadet: ".green
|
211
122
|
puts "Cannot play with less than 2 characters to guess with.".red
|
212
123
|
exit
|
124
|
+
elsif chars_set.length > 12
|
125
|
+
print "Chadet: ".green
|
126
|
+
puts "Cannot play with more than 12 characters to guess with.".red
|
127
|
+
exit
|
213
128
|
end
|
214
129
|
|
215
130
|
# Set number of characters based on option -d given or the default number of 4
|
@@ -243,22 +158,18 @@ go = Chadet::Guess.new(chars_set)
|
|
243
158
|
|
244
159
|
|
245
160
|
# list of commands
|
246
|
-
save_commands = %w{save svae saev sav sev}
|
247
161
|
exit_commands = %w{quit exit solve solv}
|
248
162
|
cheat_commands = %w{hint hit cheat clue bonus}
|
249
163
|
|
250
164
|
# Play the game until cc. & cp. = num_of_chars
|
251
165
|
begin
|
252
|
-
print "Guess: ".green
|
166
|
+
print "Guess: ".green
|
253
167
|
go.guess = gets.chomp
|
254
168
|
print "\r\e[1A" + " "*(go.guess.length + 7)
|
255
169
|
print "\r"
|
256
170
|
# Check for exit commands
|
257
|
-
if
|
258
|
-
go.guess_num = play.
|
259
|
-
break if go.guess_num < 0
|
260
|
-
elsif exit_commands.include? go.guess.downcase
|
261
|
-
go.guess_num = play.do_quit go.guess_num
|
171
|
+
if exit_commands.include? go.guess.downcase
|
172
|
+
go.guess_num = play.quit_game go.guess_num
|
262
173
|
break if go.guess_num < 0
|
263
174
|
elsif cheat_commands.include? go.guess.downcase
|
264
175
|
play.do_hint
|
@@ -279,6 +190,11 @@ begin
|
|
279
190
|
go.guess_num += 1
|
280
191
|
puts play.answer go.guess, go.guess_num
|
281
192
|
end
|
193
|
+
rescue Interrupt
|
194
|
+
go.guess_num = play.quit_game go.guess_num
|
195
|
+
break
|
196
|
+
rescue Exception => e
|
197
|
+
exit
|
282
198
|
end until go.guess == secret_obj.secret_chars
|
283
199
|
|
284
200
|
play.end_game if go.guess_num > 0
|
@@ -32,7 +32,7 @@
|
|
32
32
|
◙ | At first, you have to blindly guess the characters. |
|
33
33
|
+-------------------------------------------------------------+
|
34
34
|
+-------------------------------------------------------------+
|
35
|
-
◙ | After each guess, computer will give you answer on how many |
|
35
|
+
◙ | After each guess, computer will give you answer on how many |
|
36
36
|
| characters you guessed correctly (Correct Characters or |
|
37
37
|
| cc.) and how many characters that their positions you |
|
38
38
|
| guessed correctly (Correct Positions or cp.). |
|
@@ -42,8 +42,8 @@
|
|
42
42
|
| can guess inteligently what comes next. |
|
43
43
|
+-------------------------------------------------------------+
|
44
44
|
+-------------------------------------------------------------+
|
45
|
-
◙ | You can type [7m
|
46
|
-
|
|
45
|
+
◙ | You can type [7m quit [0m or [7m hint [0m during the game. Their names |
|
46
|
+
| should imply what they can do. |
|
47
47
|
+-------------------------------------------------------------+
|
48
48
|
|
49
49
|
[7mpress 'q' to go back.[0m
|
data/lib/chadet.rb
CHANGED
@@ -17,7 +17,7 @@ module Chadet
|
|
17
17
|
|
18
18
|
def header
|
19
19
|
puts "=================================================================\n" \
|
20
|
-
+ "
|
20
|
+
+ " Chadet (Characters Detective) ".code + "\n" \
|
21
21
|
+ "=================================================================\n" \
|
22
22
|
+ "Requires "+"bash".code + " and " + "xterm".code + " to run properly. "\
|
23
23
|
+ "In the terminal, \ntype " + "chadet --help".code + " for more options and "\
|
@@ -34,7 +34,6 @@ module Chadet
|
|
34
34
|
|
35
35
|
def result guess_num
|
36
36
|
# Congratulate the player for finishing the game
|
37
|
-
save = "Your game has been saved."
|
38
37
|
quit = "Try it again!"
|
39
38
|
lucky = "Wow! (˚o˚) Lucky guess."
|
40
39
|
congratulate = "★·.·´¯`·.·★·.·´¯`·.·★\n ░G░O░O░D░ ░J░O░B░!░\n ★·.·´¯`·.·★·.·´¯`·.·★\n" \
|
@@ -44,11 +43,9 @@ module Chadet
|
|
44
43
|
|
45
44
|
# To decide what message to display after the game finished
|
46
45
|
case guess_num
|
47
|
-
when -2
|
48
|
-
message = save
|
49
46
|
when -1
|
50
47
|
message = quit
|
51
|
-
when 1
|
48
|
+
when 1
|
52
49
|
message = lucky
|
53
50
|
when 2..@chars_set.length
|
54
51
|
message = congratulate
|
@@ -64,7 +61,7 @@ module Chadet
|
|
64
61
|
end
|
65
62
|
|
66
63
|
def chars_to_use
|
67
|
-
@chars_set.length >= 17 ?
|
64
|
+
box_width = @chars_set.length >= 17 ? @chars_set.length + 2 : 19
|
68
65
|
end_pos = 65
|
69
66
|
start_pos = end_pos - box_width
|
70
67
|
puts " "*start_pos + "+" + "-"*(box_width-2) + "+" + "\n"\
|
@@ -82,12 +79,13 @@ module Chadet
|
|
82
79
|
cp_pos = 12 + @num_of_chars + 2*@num_of_chars.to_s.length
|
83
80
|
table_width = cp_pos + 2
|
84
81
|
puts " " + "-"*table_width + "\n"\
|
85
|
-
+ " no.|" + " "*chars_pos + "chars"
|
82
|
+
+ " no.|" + " "*chars_pos + "chars" \
|
83
|
+
+ " "*(cc_pos - chars_pos - "chars".length - " no.|".length) \
|
86
84
|
+ "cc." + " "*(cp_pos - cc_pos - "cc.".length)\
|
87
85
|
+ "cp." + "\n"\
|
88
86
|
+ " " + "-"*table_width
|
89
87
|
end
|
90
|
-
|
88
|
+
|
91
89
|
def end_game
|
92
90
|
# table bottom horizontal line
|
93
91
|
cp_pos = 12 + @num_of_chars + 2*@num_of_chars.to_s.length
|
@@ -115,7 +113,7 @@ module Chadet
|
|
115
113
|
+ ("0"*(_n_-_u_) + _U_).green + "]"
|
116
114
|
@moves << [guess, "0"*(_n_-_b_) + _B_, "0"*(_n_-_u_) + _U_]
|
117
115
|
return output
|
118
|
-
end
|
116
|
+
end
|
119
117
|
|
120
118
|
# Method to check how many characters are correctly guessed
|
121
119
|
def checkCC guess
|
@@ -131,7 +129,7 @@ module Chadet
|
|
131
129
|
# Method to check how many correct characters are presented in correct positions
|
132
130
|
def checkCP guess
|
133
131
|
cp = 0
|
134
|
-
|
132
|
+
@num_of_chars.times do |i|
|
135
133
|
if @secret_chars[i] == guess[i]
|
136
134
|
cp += 1
|
137
135
|
end
|
@@ -145,7 +143,7 @@ module Chadet
|
|
145
143
|
clue = ""
|
146
144
|
chance = rand 1..100
|
147
145
|
if chance < (@num_of_chars.to_f/@chars_set.length.to_f*100) \
|
148
|
-
|
146
|
+
&& chance > (@num_of_chars.to_f/@chars_set.length.to_f*20) #display one correct number
|
149
147
|
picked_number = rand 0...(@num_of_chars-@used_true.length) || 0
|
150
148
|
true_characters = @secret_chars.tr(@used_true, '')
|
151
149
|
picked_true = true_characters[picked_number] || ""
|
@@ -173,7 +171,7 @@ module Chadet
|
|
173
171
|
end
|
174
172
|
|
175
173
|
def do_hint
|
176
|
-
if @hint_used != @max_hint
|
174
|
+
if @hint_used != @max_hint
|
177
175
|
hint.flash
|
178
176
|
@hint_used += 1
|
179
177
|
else
|
@@ -181,36 +179,6 @@ module Chadet
|
|
181
179
|
+ "hint#{'s' unless @max_hint == 1}.").red.flash
|
182
180
|
end
|
183
181
|
end
|
184
|
-
|
185
|
-
def save_game guess_num
|
186
|
-
end_game if guess_num > 0
|
187
|
-
# create data directory if not exists
|
188
|
-
Dir.chdir(File.dirname(__FILE__))
|
189
|
-
Dir.chdir("..")
|
190
|
-
Dir.mkdir("data") unless Dir.exists?("data")
|
191
|
-
Dir.chdir("data")
|
192
|
-
# generate filename
|
193
|
-
time = Time.now
|
194
|
-
filename = time.strftime("%y%m%d%H%M%S").to_i.to_s(36)
|
195
|
-
# save file
|
196
|
-
CSV.open(filename + ".csv", "wb") do |f|
|
197
|
-
f << [@chars_set.to_i(18).to_s(36), @secret_chars.to_i(18).to_s(36), @hint_used.to_s]
|
198
|
-
@moves.each do |move|
|
199
|
-
f << move
|
200
|
-
end
|
201
|
-
end
|
202
|
-
guess_num = -2
|
203
|
-
return guess_num
|
204
|
-
end
|
205
|
-
|
206
|
-
def do_save guess_num
|
207
|
-
if guess_num > 0
|
208
|
-
guess_num = save_game guess_num
|
209
|
-
else
|
210
|
-
"No game to save.".red.flash 1
|
211
|
-
end
|
212
|
-
return guess_num
|
213
|
-
end
|
214
182
|
|
215
183
|
def quit_game guess_num
|
216
184
|
print "\r"
|
@@ -220,25 +188,6 @@ module Chadet
|
|
220
188
|
end_game
|
221
189
|
return guess_num
|
222
190
|
end
|
223
|
-
|
224
|
-
def do_quit guess_num
|
225
|
-
if guess_num > 0
|
226
|
-
yes_commands = %w{yes yse ys ye y save saev seav sav sev s}
|
227
|
-
print "\r "
|
228
|
-
print "\r " + "Save game? (yes/no): ".yellow
|
229
|
-
save = gets.chomp
|
230
|
-
print "\r\e[1A" + " "*27
|
231
|
-
print "\r"
|
232
|
-
if yes_commands.include? save.downcase
|
233
|
-
guess_num = do_save guess_num
|
234
|
-
else
|
235
|
-
guess_num = quit_game guess_num
|
236
|
-
end
|
237
|
-
else
|
238
|
-
guess_num = quit_game guess_num
|
239
|
-
end
|
240
|
-
return guess_num
|
241
|
-
end
|
242
191
|
end
|
243
192
|
|
244
193
|
class SecretCharacters
|
@@ -276,7 +225,7 @@ module Chadet
|
|
276
225
|
redundant = true if a < b
|
277
226
|
return redundant
|
278
227
|
end
|
279
|
-
|
228
|
+
|
280
229
|
def handle_redundancy
|
281
230
|
char_freq = {}
|
282
231
|
@guess.each_char do |char|
|
@@ -294,7 +243,7 @@ module Chadet
|
|
294
243
|
end
|
295
244
|
"Redundant: you typed \"#{redundant}\" #{freq_string}.".yellow.flash
|
296
245
|
end
|
297
|
-
|
246
|
+
|
298
247
|
# Check if wrong character is input
|
299
248
|
def wrong_input?
|
300
249
|
wrong_char = false
|
data/lib/chadet/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chadet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Setyadi
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2017-01-08 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
13
55
|
description: 'Characters Detective: A command line game of guessing random characters
|
14
56
|
intelligently. Computer will generate a random set of characters. The default number
|
15
57
|
of characters is 4 and the default set of characters is decimal digits from 0 to
|
@@ -23,9 +65,17 @@ executables:
|
|
23
65
|
extensions: []
|
24
66
|
extra_rdoc_files: []
|
25
67
|
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".travis.yml"
|
70
|
+
- CODE_OF_CONDUCT.md
|
71
|
+
- Gemfile
|
26
72
|
- LICENSE.txt
|
27
|
-
-
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
28
77
|
- chadet.gemspec
|
78
|
+
- exe/chadet
|
29
79
|
- lib/Rules_Of_The_Game_▼_
|
30
80
|
- lib/chadet.rb
|
31
81
|
- lib/chadet/version.rb
|
@@ -49,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
99
|
version: '0'
|
50
100
|
requirements: []
|
51
101
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.6.8
|
53
103
|
signing_key:
|
54
104
|
specification_version: 4
|
55
105
|
summary: 'Characters Detective: A command line game of guessing random characters
|