droll 1.0rc5.2.3 → 1.0rc5.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +14 -13
  2. data/bin/droll +20 -0
  3. data/lib/droll.rb +155 -23
  4. metadata +4 -4
@@ -26,18 +26,28 @@ total to yield a final number.
26
26
  The first number following each 4 or 5 in this example is the result of a die
27
27
  immediately rolled to handle exploding die values.
28
28
 
29
+ This brief explanation of capabilities is slightly out of date. See RDoc and
30
+ code comments for details. In fact, anything in this file might be out of date
31
+ at any given time, though I will try to update it in a timely manner.
32
+
29
33
 
30
34
  ## installation
31
35
 
32
- If you already have Ruby installed, installing droll should be easy. Just
33
- download the gem package from the [Bitbucket repository][bitbucket] and use the
34
- gem command to install it:
36
+ If you already have Ruby installed with rubygems, installing droll should be
37
+ easy. Just use the gem command. At present, because droll is in a pre-release
38
+ state ("release candidate"), you need to use the `--pre` option to install from
39
+ the RubyGems archive:
40
+
41
+ $ gem install droll --pre
42
+
43
+ You can also download the gem package from the [Bitbucket repo][bitbucket] and
44
+ use the gem command to install it:
35
45
 
36
46
  $ gem install droll-<version>.gem
37
47
 
38
48
  In this example, replace `<version>` with the version number in the name of the
39
49
  gemfile you downloaded. For version 1.0.0, for instance, the command might
40
- look like this:
50
+ look like this (though as of this writing it is not yet at version 1.0.0):
41
51
 
42
52
  $ gem install droll-1.0.0.gem
43
53
 
@@ -49,15 +59,6 @@ systems, please feel free to submit patches to this README file via one of the
49
59
  approaches detailed in the **contributions** section at the bottom of this
50
60
  file.
51
61
 
52
- Eventually, droll will be distributed through Ruby's standard centralized
53
- package management system, and the entire installation process will be reduced
54
- to the following for most cases:
55
-
56
- $ gem install droll
57
-
58
- That day has not yet arrived. Special circumstances apply to the use of the
59
- `drollbot` command; see below.
60
-
61
62
  ## usage
62
63
 
63
64
  The following sections explain how to use the executable tools that come with
data/bin/droll CHANGED
@@ -40,6 +40,13 @@ SYNTAX
40
40
  than a threshold value, roll another die of that type and
41
41
  add it to the total.
42
42
 
43
+ k Only use the highest die values, up to a number of dice
44
+ equal to a specified value. When the "k" is capitalized
45
+ "K", use the lowest die values instead.
46
+
47
+ n Count the number of dice that yield values equal to or
48
+ higher than a threshhold value.
49
+
43
50
  3. Die Value (Mandatory; No Default)
44
51
 
45
52
  Indicates the set of values the die can produce. Two types of die
@@ -93,6 +100,19 @@ EXAMPLES
93
100
  3e02.4 Same as 3e02, but roll an additional 1x02 if the total of the
94
101
  original 3d02 roll is equal to 4 or greater.
95
102
 
103
+ 3k02 Roll three three-sided dice for values between 0 and 2 as
104
+ though rolling 3d02, but only keep the highest die.
105
+
106
+ 3k02.2 Same as 3k02, but keep the highest two dice.
107
+
108
+ 3K02.2 Same as 3k02.2, but keep the lowest two dice.
109
+
110
+ 3n10 Roll three ten-sided dice for values between 1 and 10, and
111
+ count only the number of dice whose values are 10.
112
+
113
+ 3n10.6 Same as 3n10, but count the number of dice whose values are 6
114
+ or higher.
115
+
96
116
  EOF
97
117
 
98
118
  version_help = <<EOF
@@ -48,15 +48,53 @@ exploding occurs, leaving an 11 result from the virtual dice. As normal, when
48
48
  all die rolling is resolved and summed, the modifier (+7 in this case) is
49
49
  applied to the total.
50
50
 
51
- ==== Explosion Threshold
51
+ ==== Threshhold Acceptance
52
52
 
53
- An exploding threshold may be specified by a period/fullstop character followed
54
- by a number, with any modifiers coming after it:
53
+ Using k instead of d, x, or e in the die code indicates that out of the number
54
+ of dice rolled, only the highest of them will be kept ("k" is for "keep").
55
+ Thus, for this die code, only the highest result is kept:
56
+
57
+ 2k20
58
+
59
+ If the k is capitalized, the lowest result is kept instead of the highest.
60
+
61
+ ==== Threshhold Counting
62
+
63
+ In some cases, it may be desirable to count the number of dice that produce a
64
+ result of the maximum value the die can produce. Use n instead of d, x, e, or
65
+ k in this die code:
66
+
67
+ 3n4
68
+
69
+ This will yield a result that is a count of four-sided dice that meet a
70
+ threshhold equal to the maximum value of the die (4). The "n" is short for
71
+ "number", as in "the number of dice that meet or exceed the threshhold".
72
+
73
+ ==== Alternate Threshholds
74
+
75
+ A threshhold number may be specified by a period/fullstop character followed by
76
+ a number, with any modifiers coming after it:
55
77
 
56
78
  3x4.3+7
57
79
 
58
- In this case, the die code is treated the same way as in the previous example,
59
- except that it explodes on 3 or 4, and not just on 4.
80
+ In this case, the die code is treated the same way as in the previous 3x4+7
81
+ example, except that it explodes on 3 or 4, and not just on 4.
82
+
83
+ For threshhold acceptance, the threshhold number is used to determine how many
84
+ of the highest or lowest die values will be kept. In this die code, then, the
85
+ result is the sum of the highest three die values:
86
+
87
+ 4k6.3
88
+
89
+ In the case of threshhold counting, it would yield a result that is a count of
90
+ four-sided dice that meet or exceed a threshhold of 3, which means a count of
91
+ all dice with values of 3 or 4, before adding the number 7 to the total with
92
+ this die code:
93
+
94
+ 3n4.3+7
95
+
96
+ Note that for threshhold counting, the modifier is applied to the count, and
97
+ not to die roll values.
60
98
 
61
99
  ==== Alternate Minimum Value
62
100
 
@@ -66,11 +104,7 @@ a 0-N range, precede the die value with a 0 in the die code:
66
104
  3d03
67
105
 
68
106
  This die code rolls three virtual dice whose values may be anywhere in the
69
- range of 0-3 and returns the total for all three dice. For other minimum
70
- values, apply a modifier. For instance, for a value ranging from -3 to 0, a
71
- die code like the following may be used:
72
-
73
- d03-3
107
+ range of 0-3 and returns the total for all three dice.
74
108
 
75
109
  === Usage:
76
110
 
@@ -102,7 +136,7 @@ This method returns the version number for the Droll gem.
102
136
 
103
137
  =end
104
138
 
105
- def self.version; '1.0rc5.2.3'; end
139
+ def self.version; '1.0rc5.3.1'; end
106
140
 
107
141
  =begin rdoc
108
142
 
@@ -149,7 +183,7 @@ The +dcode+ argument is any valid die code recognized by Droll.
149
183
  if 0 != @pcode['val'][0].to_i
150
184
  if 2 > @pcode['val'].to_i
151
185
  return false
152
- elsif 2 > @pcode['thresh'].to_i
186
+ elsif @pcode['type'].match(/[^Kk]/) and 2 > @pcode['thresh'].to_i
153
187
  return false
154
188
  end
155
189
  end
@@ -163,7 +197,12 @@ The +dcode+ argument is any valid die code recognized by Droll.
163
197
  d['num'], d['type'], die_vals = die_roll.split(/([A-Za-z])/)
164
198
  d['val'], d['thresh'] = die_vals.split(/\./)
165
199
  d['val'] = d['val'].to_s
166
- d['thresh'] ||= d['val'].sub(/^0/, '')
200
+
201
+ if d['type'].match(/[Kk]/)
202
+ d['thresh'] ||= 1
203
+ else
204
+ d['thresh'] ||= d['val'].sub(/^0/, '')
205
+ end
167
206
 
168
207
  d['num'] = 1 if d['num'] == ''
169
208
  d['sign'] ||= '+'
@@ -197,7 +236,98 @@ The +dcode+ argument is any valid die code recognized by Droll.
197
236
 
198
237
  public
199
238
 
200
- =begin
239
+ =begin rdoc
240
+
241
+ This method takes an array of numeric values as its sole argument, and compares
242
+ it to the instantiated die code's threshhold value. It returns an integer
243
+ value equal to the number of values in the array argument that are equal to or
244
+ greater than the threshhold value.
245
+
246
+ Given a threshhold of 2:
247
+
248
+ count_dice_min_thresh([0,1,2,3]) #=> 2
249
+
250
+ count_dice_min_thresh([0,1]) #=> 0
251
+
252
+ =end
253
+
254
+ def count_dice_min_thresh(dresults)
255
+ num_dice_min_thresh = dresults.reject do |n|
256
+ n < @pcode['thresh'].to_i
257
+ end.size
258
+ end
259
+
260
+ =begin rdoc
261
+
262
+ This method takes an array of numeric values as its sole argument, and returns
263
+ the total of the highest N values in the array, where N is the instantiated die
264
+ code's threshhold value.
265
+
266
+ Given a die code of 3k02:
267
+
268
+ sum_thresh_high_dice([2, 2, 2]) #=> 2
269
+
270
+ sum_thresh_high_dice([0, 0, 1]) #=> 1
271
+
272
+ Given a die code of 3k02.2:
273
+
274
+ sum_thresh_high_dice([0, 1, 2]) #=> 3
275
+
276
+ sum_thresh_high_dice([0, 0, 1]) #=> 1
277
+
278
+ =end
279
+
280
+ def sum_thresh_high_dice(dresults)
281
+ dresults.sort.reverse[0..(@pcode['thresh'].to_i - 1)].inject(:+)
282
+ end
283
+
284
+ =begin rdoc
285
+
286
+ This method takes an array of numeric values as its sole argument, and returns
287
+ the total of the lowest N values in the array, where N is the instantiated die
288
+ code's threshhold value.
289
+
290
+ Given a die code of 3K02:
291
+
292
+ sum_thresh_low_dice([1, 1, 1]) #=> 1
293
+
294
+ sum_thresh_low_dice([0, 1, 2]) #=> 0
295
+
296
+ Given a die code of 3K02.2:
297
+
298
+ sum_thresh_low_dice([0, 1, 2]) #=> 1
299
+
300
+ sum_thresh_low_dice([1, 2, 2]) #=> 3
301
+
302
+ =end
303
+
304
+ def sum_thresh_low_dice(dresults)
305
+ dresults.sort[0..(@pcode['thresh'].to_i - 1)].inject(:+)
306
+ end
307
+
308
+ =begin rdoc
309
+
310
+ This method takes an array of numeric values as its sole argument, and compares the total of the values in the array to the product of the instantiated die code's threshhold value and number of dice value. Unless that product is greater than that total, the results of a die roll of 1xX.Y are appended to the array provided in the method argument, where X is the value of the instantiated die code and Y is the threshhold of the instantiated die code.
311
+
312
+ Given a die code of 2e2:
313
+
314
+ explode_on_max_total([2, 2]) #=> [2, 2, ...]
315
+
316
+ explode_on_max_total([2, 1]) #=> [2, 1]
317
+
318
+ =end
319
+
320
+ def explode_on_max_total(dresults)
321
+ dice_total = dresults.map {|s| s.to_i }.inject(:+)
322
+ unless (@pcode['thresh'].to_i * @pcode['num'].to_i) > dice_total
323
+ dresults.push(
324
+ roll_die @pcode['val'], 'x', @pcode['thresh']
325
+ )
326
+ end
327
+ dresults.flatten
328
+ end
329
+
330
+ =begin rdoc
201
331
 
202
332
  By default, this method returns a string showing the die code rolled, the
203
333
  individual die rolls that make up the complete roll of dice, the modifier
@@ -224,17 +354,19 @@ an integer equal to the total result.
224
354
  end
225
355
 
226
356
  if @pcode['type'] == 'e'
227
- dice_total = running_totals.map {|s| s.to_i}.inject(:+)
228
- if dice_total >= @pcode['thresh'].to_i
229
- running_totals.push(
230
- roll_die @pcode['val'], 'x', @pcode['thresh']
231
- )
232
- end
233
- running_totals.flatten!
357
+ running_totals = explode_on_max_total(running_totals)
234
358
  end
235
359
 
236
- total_result = running_totals.map {|s| s.to_i }.inject do |sum,n|
237
- sum ? sum+n : n
360
+ if @pcode['type'] == 'k'
361
+ total_result = sum_thresh_high_dice running_totals
362
+ elsif @pcode['type'] == 'K'
363
+ total_result = sum_thresh_low_dice running_totals
364
+ elsif @pcode['type'] == 'n'
365
+ total_result = count_dice_min_thresh running_totals
366
+ else # "normal" totaling
367
+ total_result = running_totals.map {|s| s.to_i }.inject do |sum,n|
368
+ sum ? sum+n : n
369
+ end
238
370
  end
239
371
 
240
372
  case @pcode['sign']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droll
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0rc5.2.3
4
+ version: 1.0rc5.3.1
5
5
  prerelease: 3
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-16 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: isaac
16
- requirement: &12637340 !ruby/object:Gem::Requirement
16
+ requirement: &6030100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12637340
24
+ version_requirements: *6030100
25
25
  description: ! " Droll is a Ruby library providing dice roller functionality, with
26
26
  a\n command line utility and an IRC bot as included user interfaces.\n"
27
27
  email: code@apotheon.net