chadet 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d79cfd9a050851716c952b82b190b06ce8675582
4
- data.tar.gz: 830b04d7b5d2fe1c4f86fdc234eb46c0dbf8bf80
3
+ metadata.gz: da359f21ff6008e3f8f75ce20cfdeb1b0b3727f9
4
+ data.tar.gz: 5e66d5254bea5614627a62b9441bf88294278f04
5
5
  SHA512:
6
- metadata.gz: 5885e64f43bdb1ec7d3136db537138105a600aa5e63f5fcc87943f24875e6b0e79769157cfa95e086f5e7782af2696965b6ee4bba1c3bd79558a413bc5c71c18
7
- data.tar.gz: eef546c2b911f7acd351bd593d712645e01ba4bf798f6a6a89e2bcc59f16706ef4fd8454f888da8be3b70e5de3de96b7b54df78ae8c32c88c4a62ce986782de1
6
+ metadata.gz: 451a4efdd388c6f9282b069ffebae43020a7543ae94cc6daa5565056daba4b44daf754989457bff6cc9342063bad51a6cf0d83d5778cccb62312b0da9aa8bacb
7
+ data.tar.gz: 85bf6a1d6616cb76c388a186d1f2b6cf54f4d35ce64541d93fa4e0bafab90e21f81264d243cefbc427f7a538fb9818140f2cf213f84cfad3b7995acd02717841
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Adrian Setyadi
1
+ Copyright (c) 2015 Adrian Setyadi
2
2
 
3
3
  MIT License
4
4
 
data/bin/chadet CHANGED
@@ -64,6 +64,57 @@ class String
64
64
  end
65
65
  end
66
66
 
67
+ def finish_game
68
+ end
69
+
70
+
71
+ def display saved_games
72
+ puts " Game Saved at"
73
+ saved_games.each do |game|
74
+ time = DateTime.parse("20"+game.to_i(36).to_s)
75
+ saved_at = time.strftime('%a, %b %d, %Y->%I:%M:%S %p')
76
+ puts "#{game.code} #{saved_at}"
77
+ end
78
+ end
79
+
80
+ def load filename
81
+ # move to bin directory
82
+ Dir.chdir('bin')
83
+ filename = filename + ".csv"
84
+ if filename != "filename" && File.exists?(filename)
85
+
86
+ # @loaded = true
87
+ # table_width = 15 + @num_of_chars + 2*@num_of_chars.to_s.length
88
+ # print "\r\e[#{guess_object.guess_num+3}A"
89
+ # print (" "*table_width + "\n")*(guess_object.guess_num+3)
90
+ # print "\r\e[#{guess_object.guess_num+3}A"
91
+ # saved_game = File.read(work_dir + "/" + filename + ".4dig")
92
+ # saved_game_arr = saved_game.split("\n")
93
+ # @chars_set = saved_game_arr[1]
94
+ # @secret_chars = saved_game_arr[4]
95
+ # secret_object.secret_chars = @secret_chars
96
+ # @num_of_chars = @secret_chars.length
97
+ # @hint_used = saved_game_arr[7].to_i
98
+ # @max_hint = (@chars_set.length/@num_of_chars).to_i
99
+ # @moves = saved_game_arr[10..-1]
100
+ # guess_object.guess_num = @moves.length
101
+ # chars_to_use
102
+ # table_header
103
+ # @moves = @moves.inject("") {|result, line| result + line + "\n"}
104
+ # puts @moves
105
+ # else
106
+ # "No saved game with that name.".yellow.flash 1.5
107
+ # end
108
+ else
109
+ # list all saved game
110
+ saved_games = Dir.glob("*.csv").map { |x| x.sub! '.csv', '' }
111
+ display saved_games
112
+ end
113
+ # move back to parent directory
114
+ Dir.chdir('..')
115
+ exit
116
+ end
117
+
67
118
  # Specify new Hash to store the options
68
119
  options = {}
69
120
 
@@ -82,57 +133,10 @@ optparse = OptionParser.new do |opts|
82
133
  + " guess intelligently based on the previous answers.\n\n" \
83
134
  + "Options:\n\n"
84
135
 
85
- opts.on '-r', '--rules', 'How to play this game' do
86
- rules_of_play = <<rules
87
- -----------------------------------
88
- How to play Characters Detective:
89
- -----------------------------------
90
- +-------------------------------------------------------------+
91
- ◙ | As the game begins, computer generates a random set of |
92
- | characters for you to guess. |
93
- +-------------------------------------------------------------+
94
- +-------------------------------------------------------------+
95
- ◙ | This random set of characters is by default a 4 digit |
96
- | decimal numbers, or the standard Bulls and Cows game, as |
97
- | people know it. To change this behaviour, simply specify |
98
- | the '--number=' (or simply '-n') option to change the |
99
- | number of characters to guess and/or specify the |
100
- | '--characters=' (or '-c') option to change the default set |
101
- | of characters to guess. |
102
- | |
103
- | Example: |
104
- | If you type \e[7m chadet --number=2 --characters=abcdef \e[0m you |
105
- | will then play the game like this: |
106
- | ,¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸ |
107
- | ------------------ +-----------------+ |
108
- | no.| chars cc. cp. |Set of characters| |
109
- | ------------------ |to guess with: | |
110
- | 1| \e[33mab\e[0m [\e[32m0\e[0m] [\e[32m0\e[0m] +-----------------+ |
111
- | 2| \e[33mcd\e[0m [\e[32m1\e[0m] [\e[32m0\e[0m] |\e[33mabcdef\e[0m | |
112
- | \e[32mGuess:\e[0m _ +-----------------+ |
113
- | |
114
- | |
115
- | For more options, type: \e[7m chadet --help \e[0m |
116
- +-------------------------------------------------------------+
117
- +-------------------------------------------------------------+
118
- ◙ | At first, you have to blindly guess the characters. |
119
- +-------------------------------------------------------------+
120
- +-------------------------------------------------------------+
121
- ◙ | After each guess, computer will give you answer on how many |
122
- | characters you guessed correctly (Correct Characters or |
123
- | cc.) and how many characters that their positions you |
124
- | guessed correctly (Correct Positions or cp.). |
125
- +-------------------------------------------------------------+
126
- +-------------------------------------------------------------+
127
- ◙ | By analizing computer answers in the previous guesses, you |
128
- | can guess inteligently what comes next. |
129
- +-------------------------------------------------------------+
130
- +-------------------------------------------------------------+
131
- ◙ | You can type \e[32msave\e[0m, \e[32mquit\e[0m or \e[32mhint\e[0m during the game. Their |
132
- | names should imply what they can do. |
133
- +-------------------------------------------------------------+
134
- rules
135
- puts rules_of_play
136
+ opts.on '-r', '--rules', 'How to play this game' do
137
+ Dir.chdir(File.dirname(__FILE__))
138
+ Dir.chdir("../lib")
139
+ system('less -F -R Rules_Of_The_Game_▼_')
136
140
  exit
137
141
  end
138
142
 
@@ -151,6 +155,11 @@ rules
151
155
  options[:test] = true
152
156
  end
153
157
 
158
+ options[:load] = "file"
159
+ opts.on '-l', '--load [SAVED GAME]', String, 'Load saved game' do |game|
160
+ options[:load] = game
161
+ end
162
+
154
163
  opts.on '-h', '--help', 'Display this message' do
155
164
  puts opts
156
165
  puts ""
@@ -167,11 +176,12 @@ end
167
176
  # Run parse! on the parser object
168
177
  optparse.parse!
169
178
 
179
+ load options[:load] if options[:load] != "file"
170
180
  # Set of characters to play with
171
181
  chars_set = options[:characters]
172
182
  if chars_set.length < 2
173
183
  print "Chadet: ".green
174
- puts "Cannot play with a set of character less than 2 characters.".red
184
+ puts "Cannot play with less than 2 characters to guess with.".red
175
185
  exit
176
186
  end
177
187
 
@@ -190,9 +200,9 @@ chars_to_guess = secret_obj.secret_chars
190
200
  num_of_chars = secret_obj.num_of_chars
191
201
 
192
202
  # Set the number to guess
203
+ # system('clear')
204
+ print `tput smcup`
193
205
  puts "The secret characters are: #{chars_to_guess}".blue if options[:test] == true
194
-
195
- system('clear')
196
206
  play = Chadet::Play.new(secret_obj)
197
207
  play.header
198
208
  play.chars_to_use
@@ -228,7 +238,7 @@ begin
228
238
  elsif go.is_redundant?
229
239
  go.handle_redundancy
230
240
  elsif go.guess.length > num_of_chars
231
- ("We'll take the first#{num_of_chars == 1 ? '' : ' ' + num_of_chars.to_s} "\
241
+ ("I'll take the first#{num_of_chars == 1 ? '' : ' ' + num_of_chars.to_s} "\
232
242
  + "character#{num_of_chars == 1 ? '' : 's'}.").green.flash 1.5
233
243
  go.guess = go.guess[0...num_of_chars]
234
244
  go.guess_num += 1
@@ -269,4 +279,10 @@ if message == a_bit_slow
269
279
  puts "\n " + message.yellow
270
280
  else
271
281
  message.blink
272
- end
282
+ end
283
+
284
+ print "\n"
285
+ print "(GAME OVER)".code
286
+
287
+ sleep 1
288
+ print `tput rmcup`
@@ -6,15 +6,17 @@ 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-05"
10
+
9
11
  spec.authors = ["Adrian Setyadi"]
10
12
  spec.email = ["a.styd@yahoo.com"]
11
- spec.summary = %q{Characters Detective: A game of guessing random characters intelligently.}
12
- spec.description = %q{Characters Detective: A 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.}
13
- spec.homepage = "https://rubygems.org/gems/chadet"
13
+ spec.summary = %q{Characters Detective: A command line game of guessing random characters intelligently.}
14
+ 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
+ spec.homepage = "https://github.com/styd/chadet"
14
16
  spec.license = "MIT"
15
17
 
16
18
  spec.files = `git ls-files -z`.split("\x0")
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
21
  spec.require_paths = ["lib"]
20
- end
22
+ end
@@ -0,0 +1,49 @@
1
+ -----------------------------------------------------------------
2
+  How to play Characters Detective: 
3
+ -----------------------------------------------------------------
4
+ +-------------------------------------------------------------+
5
+ ◙ | As the game begins, computer generates a random set of |
6
+ | characters for you to guess. |
7
+ +-------------------------------------------------------------+
8
+ +-------------------------------------------------------------+
9
+ ◙ | This random set of characters is by default a 4 digit |
10
+ | decimal numbers, or the standard Bulls and Cows game, as |
11
+ | people know it. To change this behaviour, simply specify |
12
+ | the '--number=' (or simply '-n') option to change the |
13
+ | number of characters to guess and/or specify the |
14
+ | '--characters=' (or '-c') option to change the default set |
15
+ | of characters to guess. |
16
+ | |
17
+ | Example: |
18
+ | If you type  chadet --number=2 --characters=abcdef  you |
19
+ | will then play the game like this: |
20
+ | ,¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸ |
21
+ | ------------------ +-----------------+ |
22
+ | no.| chars cc. cp. |Set of characters| |
23
+ | ------------------ |to guess with: | |
24
+ | 1| ab [0] [0] +-----------------+ |
25
+ | 2| cd [1] [0] |abcdef | |
26
+ | Guess: _ +-----------------+ |
27
+ | |
28
+ | |
29
+ | For more options, type:  chadet --help  |
30
+ +-------------------------------------------------------------+
31
+ +-------------------------------------------------------------+
32
+ ◙ | At first, you have to blindly guess the characters. |
33
+ +-------------------------------------------------------------+
34
+ +-------------------------------------------------------------+
35
+ ◙ | After each guess, computer will give you answer on how many |
36
+ | characters you guessed correctly (Correct Characters or |
37
+ | cc.) and how many characters that their positions you |
38
+ | guessed correctly (Correct Positions or cp.). |
39
+ +-------------------------------------------------------------+
40
+ +-------------------------------------------------------------+
41
+ ◙ | By analizing computer answers in the previous guesses, you |
42
+ | can guess inteligently what comes next. |
43
+ +-------------------------------------------------------------+
44
+ +-------------------------------------------------------------+
45
+ ◙ | You can type  save ,  quit  or  hint  during the game. |
46
+ | Their names should imply what they can do. |
47
+ +-------------------------------------------------------------+
48
+
49
+ press 'q' to go back.
@@ -16,8 +16,11 @@ module Chadet
16
16
  end
17
17
 
18
18
  def header
19
- puts "Type: " + "chadet --help".code + " in the terminal to see more options.\n"\
20
- + "To quit this game at any time, type: " + "quit".code + "\n"
19
+ puts "==========================================================\n" \
20
+ + " Chadet (Characters Detective) ".code + "\n" \
21
+ + "==========================================================\n" \
22
+ + "To see more options, type " + "chadet --help".code + " in the terminal.\n"\
23
+ + "To quit this game at any time, type " + "quit".code + "\n"
21
24
  puts ",¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸"
22
25
  end
23
26
 
@@ -50,7 +53,12 @@ module Chadet
50
53
  # table bottom horizontal line
51
54
  cp_pos = 12 + @num_of_chars + 2*@num_of_chars.to_s.length
52
55
  table_width = cp_pos + 2
53
- puts " " + "-"*table_width
56
+ print " "
57
+ table_width.times do
58
+ print "-"
59
+ sleep 0.015
60
+ end
61
+ print "\n"
54
62
  end
55
63
 
56
64
  def answer guess, guess_num
@@ -131,21 +139,22 @@ module Chadet
131
139
  @hint_used += 1
132
140
  else
133
141
  ("Sorry, you've used #{@max_hint == 1 ? 'the' : 'up all'} #{@max_hint.to_s + " " unless @max_hint == 1}"\
134
- + "hint#{'s' unless @max_hint == 1}.").red.flash 1.2
142
+ + "hint#{'s' unless @max_hint == 1}.").red.flash
135
143
  end
136
144
  end
137
145
 
138
146
  def save_game guess_num
139
147
  end_game if guess_num > 0
140
- # create directory if not exists
141
- dir_name = Chadet::DIR_NAME
142
- Dir.chdir(Chadet::HOME_DIR)
143
- Dir.mkdir(dir_name) unless File.exists?(dir_name)
148
+ # create data directory if not exists
149
+ Dir.chdir(File.dirname(__FILE__))
150
+ Dir.chdir("..")
151
+ Dir.mkdir("data") unless Dir.exists?("data")
152
+ Dir.chdir("data")
144
153
  # generate filename
145
154
  time = Time.now
146
155
  filename = time.strftime("%y%m%d%H%M%S").to_i.to_s(36)
147
156
  # save file
148
- CSV.open(Chadet::WORK_DIR + "/" + filename + ".csv", "wb") do |f|
157
+ CSV.open(filename + ".csv", "wb") do |f|
149
158
  f << [@chars_set.to_i(18).to_s(36), @secret_chars.to_i(18).to_s(36), @hint_used.to_s]
150
159
  @moves.each do |move|
151
160
  f << move
@@ -179,7 +188,7 @@ module Chadet
179
188
  print "\r "
180
189
  print "\r " + "Save game? (yes/no): ".yellow
181
190
  save = gets.chomp
182
- print "\r\e[1A" + " "*25
191
+ print "\r\e[1A" + " "*27
183
192
  print "\r"
184
193
  if yes_commands.include? save.downcase
185
194
  guess_num = do_save guess_num
@@ -191,35 +200,6 @@ module Chadet
191
200
  end
192
201
  return guess_num
193
202
  end
194
-
195
- def load_game guess_object, secret_object
196
- filename = ".filename"
197
- work_dir = File.dirname(__FILE__)
198
- if File.exists?(work_dir + "/" + filename + ".4dig")
199
- @loaded = true
200
- table_width = 15 + @num_of_chars + 2*@num_of_chars.to_s.length
201
- print "\r\e[#{guess_object.guess_num+3}A"
202
- print (" "*table_width + "\n")*(guess_object.guess_num+3)
203
- print "\r\e[#{guess_object.guess_num+3}A"
204
- saved_game = File.read(work_dir + "/" + filename + ".4dig")
205
- saved_game_arr = saved_game.split("\n")
206
- @chars_set = saved_game_arr[1]
207
- @secret_chars = saved_game_arr[4]
208
- secret_object.secret_chars = @secret_chars
209
- @num_of_chars = @secret_chars.length
210
- @hint_used = saved_game_arr[7].to_i
211
- @max_hint = (@chars_set.length/@num_of_chars).to_i
212
- @moves = saved_game_arr[10..-1]
213
- guess_object.guess_num = @moves.length
214
- chars_to_use
215
- table_header
216
- @moves = @moves.inject("") {|result, line| result + line + "\n"}
217
- puts @moves
218
- else
219
- "No saved game found.".yellow.flash 1.5
220
- end
221
- return guess_object.guess_num
222
- end
223
203
  end
224
204
 
225
205
  class SecretCharacters
@@ -1,6 +1,3 @@
1
1
  module Chadet
2
- VERSION = "1.0.0"
3
- HOME_DIR = `echo $HOME`.chomp
4
- DIR_NAME = "chadet"
5
- WORK_DIR = HOME_DIR + "/ruby_gems/#{DIR_NAME}"
2
+ VERSION = "1.0.5"
6
3
  end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chadet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'Characters Detective: A game of guessing random characters intelligently.
14
- Computer will generate a random set of characters. The default number of characters
15
- is 4 and the default set of characters is decimal digits from 0 to 9. After each
16
- guess you make, computer will tell you how many characters you guessed correctly
17
- and how many characters that their position you guessed correctly. Next, you can
18
- guess intelligently based on the previous answers.'
13
+ description: 'Characters Detective: A command line game of guessing random characters
14
+ intelligently. Computer will generate a random set of characters. The default number
15
+ of characters is 4 and the default set of characters is decimal digits from 0 to
16
+ 9. After each guess you make, computer will tell you how many characters you guessed
17
+ correctly and how many characters that their position you guessed correctly. Next,
18
+ you can guess intelligently based on the previous answers.'
19
19
  email:
20
20
  - a.styd@yahoo.com
21
21
  executables:
@@ -26,9 +26,10 @@ files:
26
26
  - LICENSE.txt
27
27
  - bin/chadet
28
28
  - chadet.gemspec
29
+ - lib/Rules_Of_The_Game_▼_
29
30
  - lib/chadet.rb
30
31
  - lib/chadet/version.rb
31
- homepage: https://rubygems.org/gems/chadet
32
+ homepage: https://github.com/styd/chadet
32
33
  licenses:
33
34
  - MIT
34
35
  metadata: {}
@@ -51,5 +52,6 @@ rubyforge_project:
51
52
  rubygems_version: 2.4.8
52
53
  signing_key:
53
54
  specification_version: 4
54
- summary: 'Characters Detective: A game of guessing random characters intelligently.'
55
+ summary: 'Characters Detective: A command line game of guessing random characters
56
+ intelligently.'
55
57
  test_files: []