chadet 0.0.1 → 1.0.0

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: 6cfd2236b309e3803cd4a359698031aa14bc4769
4
- data.tar.gz: 482cfc03d09d4d6521d9b132caa172f24cb44929
3
+ metadata.gz: d79cfd9a050851716c952b82b190b06ce8675582
4
+ data.tar.gz: 830b04d7b5d2fe1c4f86fdc234eb46c0dbf8bf80
5
5
  SHA512:
6
- metadata.gz: 553de67587410c0583ada232854e81061d4da84e22d5f05dfe60d8eeaa5a82da61a6fa647ce09ed862396f5eeb83bc15478ea92f7c354e5d5800a6e5b167adac
7
- data.tar.gz: 210db35063e06da63b93862978cc84c7302591900bb50a24b2be7a244f0a944b45ed4b7432b687c703b51ccb248deca02f8996c037ecf8038ad4e7ae7bcd0e29
6
+ metadata.gz: 5885e64f43bdb1ec7d3136db537138105a600aa5e63f5fcc87943f24875e6b0e79769157cfa95e086f5e7782af2696965b6ee4bba1c3bd79558a413bc5c71c18
7
+ data.tar.gz: eef546c2b911f7acd351bd593d712645e01ba4bf798f6a6a89e2bcc59f16706ef4fd8454f888da8be3b70e5de3de96b7b54df78ae8c32c88c4a62ce986782de1
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 astyd
1
+ Copyright (c) 2014 Adrian Setyadi
2
2
 
3
3
  MIT License
4
4
 
data/bin/chadet CHANGED
@@ -6,9 +6,13 @@ require 'chadet'
6
6
 
7
7
  class String
8
8
  # define methods for coloring text
9
- colors = {:red => 31, :green => 32, :yellow => 33, :blue => 34, :cyan=> 36}
9
+ colors = {:red => 31, :green => 32, :yellow => 33, :blue => 34, :cyan => 36, :code => 7}
10
10
  colors.each do |k, v|
11
- define_method(k) {return "\e[#{v}m#{self}\e[0m" }
11
+ if k == :code
12
+ define_method(k) {return "\e[#{v}m #{self} \e[0m"}
13
+ else
14
+ define_method(k) {return "\e[#{v}m#{self}\e[0m"}
15
+ end
12
16
  end
13
17
 
14
18
  def flash seconds = 2
@@ -43,7 +47,7 @@ class String
43
47
  print "\r"
44
48
  end
45
49
 
46
- def blink num_of_times = 4
50
+ def blink num_of_times = 5
47
51
  info = " " + self
48
52
  print "\n"
49
53
  x = num_of_times
@@ -70,8 +74,12 @@ optparse = OptionParser.new do |opts|
70
74
  + "[Options] Number... [Options] Characters... [Options]\n\n" \
71
75
  + "Description:\n\n" \
72
76
  + " Characters Detective.\n" \
73
- + " Game of guessing characters. The default number of characters is 4 and\n" \
74
- + " the default set of characters is decimal digits from 0 to 9.\n\n" \
77
+ + " A game of guessing random characters intelligently. The default number\n" \
78
+ + " of characters to guess is 4 and the default set of characters to guess\n" \
79
+ + " with is decimal digits from 0 to 9. After each guess you make, computer\n" \
80
+ + " will tell you how many characters you guessed correctly and how many\n" \
81
+ + " characters that their positions you guessed correctly. Next, you can\n" \
82
+ + " guess intelligently based on the previous answers.\n\n" \
75
83
  + "Options:\n\n"
76
84
 
77
85
  opts.on '-r', '--rules', 'How to play this game' do
@@ -93,18 +101,18 @@ optparse = OptionParser.new do |opts|
93
101
  | of characters to guess. |
94
102
  | |
95
103
  | Example: |
96
- | If you type \e[32mchadet --number=2 --characters=abcdef\e[0m you will |
97
- | then play the game like this: |
104
+ | If you type \e[7m chadet --number=2 --characters=abcdef \e[0m you |
105
+ | will then play the game like this: |
98
106
  | ,¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸ |
99
- | ------------------ ------------------- |
107
+ | ------------------ +-----------------+ |
100
108
  | no.| chars cc. cp. |Set of characters| |
101
109
  | ------------------ |to guess with: | |
102
- | 1| \e[33mab\e[0m [\e[32m0\e[0m] [\e[32m0\e[0m] ------------------- |
110
+ | 1| \e[33mab\e[0m [\e[32m0\e[0m] [\e[32m0\e[0m] +-----------------+ |
103
111
  | 2| \e[33mcd\e[0m [\e[32m1\e[0m] [\e[32m0\e[0m] |\e[33mabcdef\e[0m | |
104
- | \e[32mGuess:\e[0m _ ------------------- |
112
+ | \e[32mGuess:\e[0m _ +-----------------+ |
105
113
  | |
106
114
  | |
107
- | For more options, type: \e[32mchadet --help\e[0m |
115
+ | For more options, type: \e[7m chadet --help \e[0m |
108
116
  +-------------------------------------------------------------+
109
117
  +-------------------------------------------------------------+
110
118
  ◙ | At first, you have to blindly guess the characters. |
@@ -113,15 +121,15 @@ optparse = OptionParser.new do |opts|
113
121
  ◙ | After each guess, computer will give you answer on how many |
114
122
  | characters you guessed correctly (Correct Characters or |
115
123
  | cc.) and how many characters that their positions you |
116
- | guessed correctly (Correct Positions or cp.). |
124
+ | guessed correctly (Correct Positions or cp.). |
117
125
  +-------------------------------------------------------------+
118
126
  +-------------------------------------------------------------+
119
127
  ◙ | By analizing computer answers in the previous guesses, you |
120
- | can guess inteligently next. |
128
+ | can guess inteligently what comes next. |
121
129
  +-------------------------------------------------------------+
122
130
  +-------------------------------------------------------------+
123
- ◙ | You can type \e[32msave\e[0m, \e[32mquit\e[0m, \e[32mload\e[0m or \e[32mhint\e[0m during the game. |
124
- | Their names should imply what they can do. |
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. |
125
133
  +-------------------------------------------------------------+
126
134
  rules
127
135
  puts rules_of_play
@@ -141,12 +149,7 @@ rules
141
149
  options[:test] = false
142
150
  opts.on '-t', '--test [TEST MODE]', 'Display the characters to guess' do
143
151
  options[:test] = true
144
- end
145
-
146
- options[:load] = false
147
- opts.on '-g', '--load [LOAD GAME]', 'Load previously saved game' do
148
- options[:load] = true
149
- end
152
+ end
150
153
 
151
154
  opts.on '-h', '--help', 'Display this message' do
152
155
  puts opts
@@ -154,8 +157,8 @@ rules
154
157
  exit
155
158
  end
156
159
 
157
- opts.on '-v', '--version', 'Display the version of this game' do
158
- version = "Chadet v.0.0.1"
160
+ opts.on '-v', '--version', 'Display the version and author of this game' do
161
+ version = ("Chadet " + Chadet::VERSION).code + " is created by Adrian Setyadi"
159
162
  puts version
160
163
  exit
161
164
  end
@@ -199,7 +202,6 @@ go = Chadet::Guess.new(chars_set)
199
202
 
200
203
 
201
204
  # list of commands
202
- load_commands = %w{load laod}
203
205
  save_commands = %w{save svae saev sav sev}
204
206
  exit_commands = %w{quit exit solve solv}
205
207
  cheat_commands = %w{hint hit cheat clue bonus}
@@ -211,9 +213,7 @@ begin
211
213
  print "\r\e[1A" + " "*(go.guess.length + 7)
212
214
  print "\r"
213
215
  # Check for exit commands
214
- if load_commands.include? go.guess.downcase
215
- go.guess_num = play.load_game go, secret_obj
216
- elsif save_commands.include? go.guess.downcase
216
+ if save_commands.include? go.guess.downcase
217
217
  go.guess_num = play.do_save go.guess_num
218
218
  break if go.guess_num < 0
219
219
  elsif exit_commands.include? go.guess.downcase
data/chadet.gemspec CHANGED
@@ -8,14 +8,13 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Chadet::VERSION
9
9
  spec.authors = ["Adrian Setyadi"]
10
10
  spec.email = ["a.styd@yahoo.com"]
11
- spec.summary = %q{Characters Detective. Game of guessing characters intelligently.}
12
- spec.description = %q{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.}
13
- spec.homepage = "https://bitbucket.org/astyd"
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"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
-
21
20
  end
data/lib/chadet.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "chadet/version"
2
+ require "csv"
2
3
 
3
4
  module Chadet
4
5
  class Play
@@ -11,12 +12,12 @@ module Chadet
11
12
  @used_false = ""
12
13
  @max_hint = (@chars_set.length/@num_of_chars).to_i
13
14
  @hint_used = 0
14
- @moves = ""
15
+ @moves = []
15
16
  end
16
17
 
17
18
  def header
18
- puts "Type: " + "chadet --help".green + " in the terminal to see more options.\n"\
19
- + "To quit this game at any time, type: " + "quit".green + "\n"
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"
20
21
  puts ",¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸"
21
22
  end
22
23
 
@@ -60,22 +61,16 @@ module Chadet
60
61
  _n_ = _N_.length
61
62
  _B_ = checkCC(guess).to_s
62
63
  _b_ = _B_.length
63
- _U_ = checkCO(guess).to_s
64
+ _U_ = checkCP(guess).to_s
64
65
  _u_ = _U_.length
65
- output = (guess_num == -1 ? ' XXX' : " "*(4-_g_) + _G_) + "| #{guess.yellow}" \
66
+ output = (guess_num == -1 ? ' ANS' : " "*(4-_g_) + _G_) + "| #{guess.yellow}" \
66
67
  + " [" + ("0"*(_n_-_b_) + _B_).green + "] [" \
67
68
  + ("0"*(_n_-_u_) + _U_).green + "]"
68
- @moves << (output + "\n")
69
- if _U_ == _N_ && @loaded == true
70
- filename = ".filename"
71
- work_dir = File.dirname(__FILE__)
72
- file = work_dir + "/" + filename + ".4dig"
73
- File.delete(file) if File.exists?(file)
74
- end
69
+ @moves << [guess, "0"*(_n_-_b_) + _B_, "0"*(_n_-_u_) + _U_]
75
70
  return output
76
71
  end
77
72
 
78
- # Method to check how many digits are correctly guessed
73
+ # Method to check how many characters are correctly guessed
79
74
  def checkCC guess
80
75
  cc = 0
81
76
  guess.each_char do |x|
@@ -86,15 +81,15 @@ module Chadet
86
81
  return cc
87
82
  end
88
83
 
89
- # Method to check how many correct digits are presented in correct positions
90
- def checkCO guess
91
- co = 0
84
+ # Method to check how many correct characters are presented in correct positions
85
+ def checkCP guess
86
+ cp = 0
92
87
  for i in 0...@num_of_chars
93
88
  if @secret_chars[i] == guess[i]
94
- co += 1
89
+ cp += 1
95
90
  end
96
91
  end
97
- return co
92
+ return cp
98
93
  end
99
94
 
100
95
  # Method to display hint
@@ -109,7 +104,7 @@ module Chadet
109
104
  picked_true = true_characters[picked_number] || ""
110
105
  @used_true += picked_true
111
106
  if picked_true == ""
112
- clue = "You've already known #{@num_of_chars == 1 ? 'the' : 'all'} true "\
107
+ clue = "You already knew #{@num_of_chars == 1 ? 'the' : 'all'} true "\
113
108
  + "character#{'s' unless @num_of_chars == 1}."
114
109
  else
115
110
  clue = "'#{picked_true}' is#{@num_of_chars == 1 ? '' : ' among'} the true "\
@@ -132,7 +127,7 @@ module Chadet
132
127
 
133
128
  def do_hint
134
129
  if @hint_used != @max_hint
135
- hint.flash 1.1
130
+ hint.flash
136
131
  @hint_used += 1
137
132
  else
138
133
  ("Sorry, you've used #{@max_hint == 1 ? 'the' : 'up all'} #{@max_hint.to_s + " " unless @max_hint == 1}"\
@@ -142,20 +137,19 @@ module Chadet
142
137
 
143
138
  def save_game guess_num
144
139
  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)
145
144
  # generate filename
146
145
  time = Time.now
147
- work_dir = File.dirname(__FILE__)
148
- filename = ".filename" # "."+time.strftime("%y%m%d%H%M%S").to_i.to_s(36)
146
+ filename = time.strftime("%y%m%d%H%M%S").to_i.to_s(36)
149
147
  # save file
150
- File.open(work_dir + "/" + filename + ".4dig", "w+") do |f|
151
- f.write("[set of chars]\n")
152
- f.write(@chars_set + "\n"*2)
153
- f.write("[secret chars]\n")
154
- f.write(@secret_chars + "\n"*2)
155
- f.write("[hint used]\n")
156
- f.write(@hint_used.to_s + "\n"*2)
157
- f.write("[moves]\n")
158
- f.write(@moves)
148
+ CSV.open(Chadet::WORK_DIR + "/" + filename + ".csv", "wb") do |f|
149
+ f << [@chars_set.to_i(18).to_s(36), @secret_chars.to_i(18).to_s(36), @hint_used.to_s]
150
+ @moves.each do |move|
151
+ f << move
152
+ end
159
153
  end
160
154
  guess_num = -2
161
155
  return guess_num
@@ -279,7 +273,7 @@ module Chadet
279
273
  else
280
274
  freq_string = "#{frequency} times"
281
275
  end
282
- "Redundant: you mentioned \"#{redundant}\" #{freq_string}.".yellow.flash 1.1
276
+ "Redundant: you typed \"#{redundant}\" #{freq_string}.".yellow.flash
283
277
  end
284
278
 
285
279
  # Check if wrong character is input
@@ -1,3 +1,6 @@
1
1
  module Chadet
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
+ HOME_DIR = `echo $HOME`.chomp
4
+ DIR_NAME = "chadet"
5
+ WORK_DIR = HOME_DIR + "/ruby_gems/#{DIR_NAME}"
3
6
  end
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chadet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Computer will generate a random set of characters. The default number
14
- of characters is 4 and the default set of characters is decimal digits from 0 to
15
- 9. After each guess you make, computer will tell you how many characters you guessed
16
- correctly and how many characters that their position you guessed correctly.
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.'
17
19
  email:
18
20
  - a.styd@yahoo.com
19
21
  executables:
@@ -21,16 +23,12 @@ executables:
21
23
  extensions: []
22
24
  extra_rdoc_files: []
23
25
  files:
24
- - ".gitignore"
25
- - Gemfile
26
26
  - LICENSE.txt
27
- - README.md
28
- - Rakefile
29
27
  - bin/chadet
30
28
  - chadet.gemspec
31
29
  - lib/chadet.rb
32
30
  - lib/chadet/version.rb
33
- homepage: https://bitbucket.org/astyd
31
+ homepage: https://rubygems.org/gems/chadet
34
32
  licenses:
35
33
  - MIT
36
34
  metadata: {}
@@ -50,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
48
  version: '0'
51
49
  requirements: []
52
50
  rubyforge_project:
53
- rubygems_version: 2.2.2
51
+ rubygems_version: 2.4.8
54
52
  signing_key:
55
53
  specification_version: 4
56
- summary: Characters Detective. Game of guessing characters intelligently.
54
+ summary: 'Characters Detective: A game of guessing random characters intelligently.'
57
55
  test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in chadet.gemspec
4
- gemspec
data/README.md DELETED
@@ -1,31 +0,0 @@
1
- # Chadet
2
-
3
- Characters Detective. Game of guessing characters intelligently.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'chadet'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install chadet
20
-
21
- ## Usage
22
-
23
- Type: 'chadet --help' for options.
24
-
25
- ## Contributing
26
-
27
- 1. Fork it ( https://bitbucket.org/astyd/chadet/ )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-