games_dice 0.3.9 → 0.4.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/.rubocop.yml +15 -0
- data/.travis.yml +9 -12
- data/CHANGELOG.md +29 -13
- data/Gemfile +2 -0
- data/README.md +5 -5
- data/Rakefile +14 -11
- data/ext/games_dice/extconf.rb +4 -22
- data/ext/games_dice/probabilities.c +1 -1
- data/games_dice.gemspec +26 -28
- data/lib/games_dice/bunch.rb +241 -247
- data/lib/games_dice/complex_die.rb +287 -303
- data/lib/games_dice/complex_die_helpers.rb +68 -0
- data/lib/games_dice/constants.rb +10 -10
- data/lib/games_dice/dice.rb +146 -143
- data/lib/games_dice/die.rb +101 -97
- data/lib/games_dice/die_result.rb +193 -189
- data/lib/games_dice/map_rule.rb +72 -70
- data/lib/games_dice/marshal.rb +18 -13
- data/lib/games_dice/parser.rb +219 -218
- data/lib/games_dice/reroll_rule.rb +76 -77
- data/lib/games_dice/version.rb +3 -1
- data/lib/games_dice.rb +19 -16
- data/spec/bunch_spec.rb +399 -421
- data/spec/complex_die_spec.rb +314 -306
- data/spec/dice_spec.rb +33 -34
- data/spec/die_result_spec.rb +163 -170
- data/spec/die_spec.rb +81 -82
- data/spec/helpers.rb +26 -22
- data/spec/map_rule_spec.rb +40 -44
- data/spec/parser_spec.rb +106 -82
- data/spec/probability_spec.rb +530 -527
- data/spec/readme_spec.rb +404 -384
- data/spec/reroll_rule_spec.rb +40 -44
- metadata +63 -74
- data/lib/games_dice/probabilities.rb +0 -445
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c1046747fdad80e794bb7883aaaade1a14e737a39641b6e85e7c179e96a3375
|
4
|
+
data.tar.gz: 54b1c1aa41b58b53e8a72ad59f835de932fde926a038626a0df165605677300c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60e56aa2b32a4550ae6334c372ad1a9b0a07820c8a58ae4ce07c0ae3d5721ff91b8422d3d2d52b690e387738d3ee5bb6a7c05bed2d40145b776ef9a9d6295c0c
|
7
|
+
data.tar.gz: 7a0e7c3759def3b6f482e4242ae23b770c50876fc26f5464bca4e77b91cbf64596c901c4eb9cc69e9eee351d63fa8978426ceae7125eb34aa7c3e0856a0a8e1e
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
3
|
+
before_install:
|
4
|
+
- gem install bundler
|
5
|
+
|
6
|
+
os:
|
7
|
+
- linux
|
8
|
+
|
2
9
|
rvm:
|
3
|
-
- "
|
4
|
-
- "
|
5
|
-
- "2.0.0"
|
6
|
-
- rbx-18mode
|
7
|
-
- rbx-19mode
|
8
|
-
- ree
|
9
|
-
- jruby-18mode
|
10
|
-
- jruby-19mode
|
11
|
-
- jruby-head
|
12
|
-
allow_failures:
|
13
|
-
rvm:
|
14
|
-
- ruby-head
|
10
|
+
- "2.7.1"
|
11
|
+
- "3.0.0"
|
data/CHANGELOG.md
CHANGED
@@ -1,59 +1,75 @@
|
|
1
1
|
# GamesDice Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.4.0 ( 19 September 2021 )
|
4
|
+
|
5
|
+
* Dropping support for older Ruby versions (< 2.6)
|
6
|
+
* Native extensions are no longer optional, to reduce maintenance overhead. Effectively dropping support for JRuby.
|
7
|
+
* Tidy up code for maintainability (Rubocop and RSpec)
|
8
|
+
|
9
|
+
## 0.3.11 ( 26 May 2014 )
|
10
|
+
|
11
|
+
* Bugfix. Actually use custom PRNG passed to GamesDice.create or GamesDice::Bunch.new
|
12
|
+
* Dropping support for Ruby 1.8.* versions (it may still work if you restrict parslet version)
|
13
|
+
|
14
|
+
## 0.3.10 ( 29 July 2013 )
|
15
|
+
|
16
|
+
* Non-functional changes to improve code quality metrics on CodeClimate
|
17
|
+
* Altered specs to improve accuracy of coverage metrics on Coveralls
|
18
|
+
|
19
|
+
## 0.3.9 ( 23 July 2013 )
|
4
20
|
|
5
21
|
* New methods for inspecting and iterating over potential values in GamesDice::Die
|
6
22
|
* Code metric integration and badges for github
|
7
23
|
* Non-functional changes to improve code quality metrics on CodeClimate
|
8
24
|
|
9
|
-
## 0.3.7
|
25
|
+
## 0.3.7 ( 17 July 2013 )
|
10
26
|
|
11
27
|
* Compatibility between pure Ruby and native extension code when handling bad method params
|
12
28
|
* Added this changelog to documentation
|
13
29
|
|
14
|
-
## 0.3.6
|
30
|
+
## 0.3.6 ( 15 July 2013 )
|
15
31
|
|
16
32
|
* Extension building skipped, with fallback to pure Ruby, for JRuby compatibility
|
17
33
|
|
18
|
-
## 0.3.5
|
34
|
+
## 0.3.5 ( 14 July 2013 )
|
19
35
|
|
20
36
|
* Adjust C code to avoid warnings about C90 compatibility (warnings seen on Travis)
|
21
37
|
* Note MIT license in gemspec
|
22
38
|
* Add class method GamesDice::Probabilities.implemented_in
|
23
39
|
|
24
|
-
## 0.3.3
|
40
|
+
## 0.3.3 ( 11 July 2013 )
|
25
41
|
|
26
42
|
* Standardised code for Ruby 1.8.7 compatibility in GamesDice::Probabilities
|
27
43
|
* Bug fix for probability calculations where distributions are added with mulipliers e.g. '2d6 - 1d8'
|
28
44
|
|
29
|
-
## 0.3.2
|
45
|
+
## 0.3.2 ( 10 July 2013 )
|
30
46
|
|
31
47
|
* Bug fix for Ruby 1.8.7 compatibility in GamesDice::Probabilities
|
32
48
|
|
33
|
-
## 0.3.1
|
49
|
+
## 0.3.1 ( 10 July 2013 )
|
34
50
|
|
35
51
|
* Bug fix for Ruby 1.8.7 compatibility in GamesDice::Probabilities
|
36
52
|
|
37
|
-
## 0.3.0
|
53
|
+
## 0.3.0 ( 10 July 2013 )
|
38
54
|
|
39
55
|
* Implemented GamesDice::Probabilities as native extension
|
40
56
|
|
41
|
-
## 0.2.4
|
57
|
+
## 0.2.4 ( 18 June 2013 )
|
42
58
|
|
43
59
|
* Minor speed improvements to GamesDice::Probabilities
|
44
60
|
|
45
|
-
## 0.2.3
|
61
|
+
## 0.2.3 ( 12 June 2013 )
|
46
62
|
|
47
63
|
* More YARD documentation
|
48
64
|
|
49
|
-
## 0.2.2
|
65
|
+
## 0.2.2 ( 10 June 2013 )
|
50
66
|
|
51
67
|
* Extended YARD documentation
|
52
68
|
|
53
|
-
## 0.2.1
|
69
|
+
## 0.2.1 ( 5 June 2013 )
|
54
70
|
|
55
71
|
* Started basic YARD documentation
|
56
72
|
|
57
|
-
## 0.2.0
|
73
|
+
## 0.2.0 ( 30 May 2013 )
|
58
74
|
|
59
75
|
* First version with a complete feature set
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
[](http://badge.fury.io/rb/games_dice)
|
3
3
|
[](http://travis-ci.org/neilslater/games_dice)
|
4
4
|
[](https://coveralls.io/r/neilslater/games_dice?branch=master)
|
5
|
+
[](http://inch-ci.org/github/neilslater/games_dice)
|
5
6
|
[](https://codeclimate.com/github/neilslater/games_dice)
|
6
7
|
[](https://gemnasium.com/neilslater/games_dice)
|
7
8
|
|
@@ -29,12 +30,11 @@ gem as-is, and add them as features within your project code.
|
|
29
30
|
|
30
31
|
## Supported Ruby Versions
|
31
32
|
|
32
|
-
GamesDice is tested routinely on
|
33
|
+
GamesDice is tested routinely on MRI Rubies 1.9.3, 2.0.0, 2.1.0, 2.1.1 and JRuby, and the
|
34
|
+
"build passing" badge is based on those tests.
|
33
35
|
|
34
|
-
*
|
35
|
-
|
36
|
-
* JRuby in 1.8 and 1.9 modes
|
37
|
-
* Ruby Enterprise Edition
|
36
|
+
It *should* also work in versions from 1.8.7, in Ruby Enterprise and in Rubinius, but it
|
37
|
+
is not tested routinely on those Rubies.
|
38
38
|
|
39
39
|
## Installation
|
40
40
|
|
data/Rakefile
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
3
5
|
require 'rake/extensiontask'
|
4
|
-
require
|
6
|
+
require 'yard'
|
5
7
|
|
6
8
|
def can_compile_extensions
|
7
9
|
return false if RUBY_DESCRIPTION =~ /jruby/
|
8
|
-
|
10
|
+
|
11
|
+
true
|
9
12
|
end
|
10
13
|
|
11
|
-
desc
|
14
|
+
desc 'GamesDice unit tests'
|
12
15
|
RSpec::Core::RakeTask.new(:test) do |t|
|
13
|
-
t.pattern =
|
16
|
+
t.pattern = 'spec/*_spec.rb'
|
14
17
|
t.verbose = false
|
15
18
|
end
|
16
19
|
|
@@ -21,20 +24,20 @@ end
|
|
21
24
|
gemspec = Gem::Specification.load('games_dice.gemspec')
|
22
25
|
Rake::ExtensionTask.new do |ext|
|
23
26
|
ext.name = 'games_dice'
|
24
|
-
ext.source_pattern =
|
27
|
+
ext.source_pattern = '*.{c,h}'
|
25
28
|
ext.ext_dir = 'ext/games_dice'
|
26
29
|
ext.lib_dir = 'lib/games_dice'
|
27
30
|
ext.gem_spec = gemspec
|
28
31
|
end
|
29
32
|
|
30
|
-
task :delete_compiled_ext do |
|
33
|
+
task :delete_compiled_ext do |_t|
|
31
34
|
`rm lib/games_dice/games_dice.*`
|
32
35
|
end
|
33
36
|
|
34
|
-
task :
|
37
|
+
task pure_test: %i[delete_compiled_ext test]
|
35
38
|
|
36
39
|
if can_compile_extensions
|
37
|
-
task :
|
40
|
+
task default: %i[compile test]
|
38
41
|
else
|
39
|
-
task :
|
42
|
+
task default: [:test]
|
40
43
|
end
|
data/ext/games_dice/extconf.rb
CHANGED
@@ -1,25 +1,7 @@
|
|
1
|
-
#
|
2
|
-
can_compile_extensions = false
|
3
|
-
want_extensions = true
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'mkmf'
|
7
|
-
can_compile_extensions = true
|
8
|
-
rescue Exception
|
9
|
-
# This will appear only in verbose mode.
|
10
|
-
$stderr.puts "Could not require 'mkmf'. Not fatal: The extensions are optional."
|
11
|
-
end
|
1
|
+
# frozen_string_literal: true
|
12
2
|
|
3
|
+
# ext/games_dice/extconf.rb
|
13
4
|
|
14
|
-
|
15
|
-
create_makefile( 'games_dice/games_dice' )
|
16
|
-
|
17
|
-
else
|
18
|
-
# Create a dummy Makefile, to satisfy Gem::Installer#install
|
19
|
-
mfile = open("Makefile", "wb")
|
20
|
-
mfile.puts '.PHONY: install'
|
21
|
-
mfile.puts 'install:'
|
22
|
-
mfile.puts "\t" + '@echo "Extensions not installed, falling back to pure Ruby version."'
|
23
|
-
mfile.close
|
5
|
+
require 'mkmf'
|
24
6
|
|
25
|
-
|
7
|
+
create_makefile('games_dice/games_dice')
|
@@ -472,7 +472,7 @@ ProbabilityList *pl_repeat_n_sum_k( ProbabilityList *pl, int n, int k, int kbest
|
|
472
472
|
pl_result->offset = pl->offset * k;
|
473
473
|
|
474
474
|
for ( i = 0; i < pl->slots; i++ ) {
|
475
|
-
if (
|
475
|
+
if ( pl->probs[i] <= 0.0 ) continue;
|
476
476
|
|
477
477
|
q = i + pl->offset;
|
478
478
|
calc_keep_distributions( pl, k, q, kbest, keep_distributions );
|
data/games_dice.gemspec
CHANGED
@@ -1,42 +1,40 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'games_dice/version'
|
5
7
|
|
6
8
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
9
|
+
gem.name = 'games_dice'
|
8
10
|
gem.version = GamesDice::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
results of 10 roll again and add on".
|
14
|
-
gem.homepage =
|
15
|
-
gem.license =
|
11
|
+
gem.authors = ['Neil Slater']
|
12
|
+
gem.email = ['slobo777@gmail.com']
|
13
|
+
gem.description = 'A library for simulating dice. Use it to construct dice-rolling systems used in role-playing and board games.'
|
14
|
+
gem.summary = 'Simulates and explains dice rolls from simple "1d6" to complex "roll 7 ten-sided dice, take best 3,
|
15
|
+
results of 10 roll again and add on".'
|
16
|
+
gem.homepage = 'https://github.com/neilslater/games_dice'
|
17
|
+
gem.license = 'MIT'
|
16
18
|
|
17
|
-
gem.
|
18
|
-
gem.add_development_dependency
|
19
|
-
gem.add_development_dependency
|
20
|
-
gem.add_development_dependency
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
19
|
+
gem.required_ruby_version = '>= 2.6.0'
|
20
|
+
gem.add_development_dependency 'coveralls', '>= 0.6.7'
|
21
|
+
gem.add_development_dependency 'json', '>= 1.7.7'
|
22
|
+
gem.add_development_dependency 'rake', '>= 1.9.1'
|
23
|
+
gem.add_development_dependency 'rake-compiler', '>= 0.8.3'
|
24
|
+
gem.add_development_dependency 'rspec', '>= 2.13.0'
|
25
|
+
gem.add_development_dependency 'rubocop', '>= 1.2.1'
|
26
|
+
gem.add_development_dependency 'yard', '>= 0.8.6'
|
23
27
|
|
24
28
|
# Red Carpet renders README.md, and is optional even when developing the gem.
|
25
|
-
# However, it has a C extension,
|
29
|
+
# However, it has a C extension, which will not work in JRuby. This only affects the gem build process, so
|
26
30
|
# is only really used in environments like Travis, and is safe to wrap like this in the gemspec.
|
27
|
-
if RUBY_DESCRIPTION !~ /jruby/
|
28
|
-
if RUBY_VERSION < "1.9.0"
|
29
|
-
gem.add_development_dependency "redcarpet", ">=2.3.0", "<3.0.0"
|
30
|
-
else
|
31
|
-
gem.add_development_dependency "redcarpet", ">=2.3.0"
|
32
|
-
end
|
33
|
-
end
|
31
|
+
gem.add_development_dependency 'redcarpet', '>=3.5.1' if RUBY_DESCRIPTION !~ /jruby/
|
34
32
|
|
35
|
-
gem.add_dependency
|
33
|
+
gem.add_dependency 'parslet', '>= 1.5.0'
|
36
34
|
|
37
|
-
gem.files = `git ls-files`.split(
|
38
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
35
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
36
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
39
37
|
gem.extensions = gem.files.grep(%r{/extconf\.rb$})
|
40
38
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
41
|
-
gem.require_paths = [
|
39
|
+
gem.require_paths = ['lib']
|
42
40
|
end
|