ofcp_card_counter 0.0.1
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/.autotest +3 -0
- data/.editorconfig +21 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +20 -0
- data/README.md +26 -0
- data/lib/ofcp_card_counter/card_counter.rb +25 -0
- data/lib/ofcp_card_counter/version.rb +3 -0
- data/lib/ofcp_card_counter.rb +5 -0
- data/ofcp_card_counter.gemspec +24 -0
- data/spec/card_counter_spec.rb +68 -0
- data/spec/spec_helper.rb +24 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a1251c53679102578debc70663578bd58e4e506
|
4
|
+
data.tar.gz: c992980f629937f1e24af3f7e72b22d4cf5bd82f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 184da69c8026dd5c220b407a324626ba4108d9376fdc199ea1e6030c0a43e0eb39f2db89d8e0c0c699cf3c19afc5c6434b5132c9c0a0e5d4bf393b40c4788353
|
7
|
+
data.tar.gz: 8a22059b16454160f78b11665d0ea792c6fc85bf9649426b7e2f14d4c7aa45a18c265781ba476a7e9d2e12618f43ca331088774b7eca0fbd2eb052e8c756c36b
|
data/.autotest
ADDED
data/.editorconfig
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
2
|
+
# coding styles between different editors and IDEs
|
3
|
+
# editorconfig.org
|
4
|
+
|
5
|
+
root = true
|
6
|
+
|
7
|
+
|
8
|
+
[*]
|
9
|
+
|
10
|
+
# Change these settings to your own preference
|
11
|
+
indent_style = space
|
12
|
+
indent_size = 2
|
13
|
+
|
14
|
+
# We recommend you to keep these unchanged
|
15
|
+
end_of_line = lf
|
16
|
+
charset = utf-8
|
17
|
+
trim_trailing_whitespace = true
|
18
|
+
insert_final_newline = true
|
19
|
+
|
20
|
+
[*.md]
|
21
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.0.0@ofcp-card-counter --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.9.3)
|
5
|
+
autotest-doom (0.0.1)
|
6
|
+
test_notifier (~> 0)
|
7
|
+
autotest-growl (0.2.16)
|
8
|
+
diff-lcs (1.2.4)
|
9
|
+
notifier (0.4.1)
|
10
|
+
rspec (2.14.1)
|
11
|
+
rspec-core (~> 2.14.0)
|
12
|
+
rspec-expectations (~> 2.14.0)
|
13
|
+
rspec-mocks (~> 2.14.0)
|
14
|
+
rspec-core (2.14.5)
|
15
|
+
rspec-expectations (2.14.2)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.14.3)
|
18
|
+
test_notifier (0.4.0)
|
19
|
+
notifier
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
ZenTest
|
26
|
+
autotest-doom
|
27
|
+
autotest-growl
|
28
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Roy van de Water
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Ofcp Card Counter
|
2
|
+
=================
|
3
|
+
|
4
|
+
Statistics calculations for Open Face Chinese Poker hands
|
5
|
+
|
6
|
+
Basic Usage
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Calculates the dependent probability of receiving one or more cards left
|
10
|
+
in the deck.
|
11
|
+
|
12
|
+
@card_counter = OfcpCardCounter::CardCounter.new(
|
13
|
+
:turns_left => 3, # Number of cards this player is yet to get
|
14
|
+
:cards => %w{2H 3H 4H} # All cards that are already known and dealt
|
15
|
+
)
|
16
|
+
@card_counter.probability_of_getting 2, :of => %w{5H 6H}
|
17
|
+
#=> 0.002551020408163265
|
18
|
+
|
19
|
+
|
20
|
+
@card_counter = OfcpCardCounter::CardCounter.new(
|
21
|
+
:turns_left => 10, # Number of cards this player is yet to get
|
22
|
+
:cards => %w{4H JH QH} # All cards that are already known and dealt
|
23
|
+
)
|
24
|
+
@card_counter.probability_of_getting 2, :of => %w{2H 3H 5H 6H 7H 8H 9H 10H KH AH}
|
25
|
+
#=> 0.6647656110932596
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class OfcpCardCounter::CardCounter
|
2
|
+
def initialize(options={})
|
3
|
+
@turns_left = options[:turns_left]
|
4
|
+
@cards = options[:cards]
|
5
|
+
end
|
6
|
+
|
7
|
+
def probability_of_getting(number, options={})
|
8
|
+
return 1.0 if number <= 0 || options[:of].nil?
|
9
|
+
|
10
|
+
targets = options[:of] - @cards
|
11
|
+
targets_left = targets.count.to_f
|
12
|
+
turns_left = (options[:turns_left] || @turns_left).to_f
|
13
|
+
cards_left = (options[:cards_left] || 52 - @cards.count).to_f
|
14
|
+
|
15
|
+
return 0.0 if turns_left < number
|
16
|
+
|
17
|
+
successful_case = targets_left / cards_left
|
18
|
+
successful_case *= probability_of_getting (number - 1), :of => targets[1..-1], :cards_left => (cards_left - 1), :turns_left => (turns_left - 1)
|
19
|
+
|
20
|
+
unsuccessful_case = (cards_left - targets_left) / cards_left
|
21
|
+
unsuccessful_case *= probability_of_getting number, :of => targets, :cards_left => (cards_left - 1), :turns_left => (turns_left - 1)
|
22
|
+
|
23
|
+
successful_case + unsuccessful_case
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ofcp_card_counter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ofcp_card_counter"
|
8
|
+
spec.version = OfcpCardCounter::VERSION
|
9
|
+
spec.authors = ["Roy van de Water"]
|
10
|
+
spec.email = ["me@royvandewater.com"]
|
11
|
+
spec.description = %q{Open Face Chinese Poker Statistics}
|
12
|
+
spec.summary = %q{Statistics calculations for Open Face Chinese Poker hands}
|
13
|
+
spec.homepage = "http://github.com/royvandewater/ofcp-card-counter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative '../lib/ofcp_card_counter'
|
2
|
+
|
3
|
+
describe OfcpCardCounter::CardCounter do
|
4
|
+
describe 'probability_of_getting' do
|
5
|
+
context 'when 11 of 13 cards have already been dealt' do
|
6
|
+
before :each do
|
7
|
+
@sut = OfcpCardCounter::CardCounter.new(
|
8
|
+
:turns_left => 2,
|
9
|
+
:cards => ['2C',
|
10
|
+
'2H', '3H', '4H', '5H', '6H',
|
11
|
+
'2S', '3S', '4S', '5S', '6S']
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should calculate a probability of 2/41 when trying to get one of one cards' do
|
16
|
+
expect(@sut.probability_of_getting 1, :of => ['JH']).to eq 2.0/41.0
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should calculate a probability of 79/820 when trying to get one of two cards' do
|
20
|
+
expect(@sut.probability_of_getting 1, :of => ['JH', 'QH']).to eq 79.0/820.0
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should calculate a probability of 117/820 when trying to get one of three cards' do
|
24
|
+
expect(@sut.probability_of_getting 1, :of => ['JH', 'QH', 'KH']).to be_within(0.000001).of 117.0/820.0
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should calculate a probability of 1/820 when trying to get two cards' do
|
28
|
+
expect(@sut.probability_of_getting 2, :of => ['JH', 'QH']).to be_within(0.000001).of 1.0/820.0
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should calculate a probability of 3/820 when trying to get any two of three cards' do
|
32
|
+
expect(@sut.probability_of_getting 2, :of => ['JH', 'QH', 'KH']).to be_within(0.000001).of 3.0/820.0
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should calculate a probability of 3/410 when trying to get any two of four cards' do
|
36
|
+
expect(@sut.probability_of_getting 2, :of => ['JH', 'QH', 'KH', 'AH']).to be_within(0.000001).of 3.0/410.0
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should calculate a probability of 1/82 when trying to get any two of five cards' do
|
40
|
+
expect(@sut.probability_of_getting 2, :of => ['10H', 'JH', 'QH', 'KH', 'AH']).to eq 1.0/82.0
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should calculate a probability of 3/164 when trying to get any two of six cards' do
|
44
|
+
expect(@sut.probability_of_getting 2, :of => ['9H', '10H', 'JH', 'QH', 'KH', 'AH']).to eq 3.0/164.0
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should calculate a probability of 0 when trying to get three cards' do
|
48
|
+
expect(@sut.probability_of_getting 3, :of => ['JH', 'QH', 'KH']).to eq 0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when 10 of 13 cards have already been dealt' do
|
53
|
+
before :each do
|
54
|
+
@sut = OfcpCardCounter::CardCounter.new(
|
55
|
+
:turns_left => 3,
|
56
|
+
:cards => [
|
57
|
+
'2H', '3H', '4H', '5H', '6H',
|
58
|
+
'2S', '3S', '4S', '5S', '6S'
|
59
|
+
]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should calculate a probability of 1/11480 when trying to get three cards' do
|
64
|
+
expect(@sut.probability_of_getting 3, :of => ['JH', 'QH', 'KH']).to be_within(0.000001).of 1.0/11480.0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'debugger'
|
10
|
+
rescue LoadError
|
11
|
+
puts 'no debugger installed'
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
|
+
config.run_all_when_everything_filtered = true
|
17
|
+
config.filter_run :focus
|
18
|
+
|
19
|
+
# Run specs in random order to surface order dependencies. If you find an
|
20
|
+
# order dependency and want to debug it, you can fix the order by providing
|
21
|
+
# the seed, which is printed after each run.
|
22
|
+
# --seed 1234
|
23
|
+
config.order = 'random'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ofcp_card_counter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roy van de Water
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Open Face Chinese Poker Statistics
|
56
|
+
email:
|
57
|
+
- me@royvandewater.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .autotest
|
63
|
+
- .editorconfig
|
64
|
+
- .gitignore
|
65
|
+
- .rspec
|
66
|
+
- .rvmrc
|
67
|
+
- .travis.yml
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- lib/ofcp_card_counter.rb
|
73
|
+
- lib/ofcp_card_counter/card_counter.rb
|
74
|
+
- lib/ofcp_card_counter/version.rb
|
75
|
+
- ofcp_card_counter.gemspec
|
76
|
+
- spec/card_counter_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: http://github.com/royvandewater/ofcp-card-counter
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.0.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Statistics calculations for Open Face Chinese Poker hands
|
102
|
+
test_files:
|
103
|
+
- spec/card_counter_spec.rb
|
104
|
+
- spec/spec_helper.rb
|