cards_lib 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/cards_lib.gemspec +1 -1
- data/lib/cards_lib/card.rb +3 -3
- data/lib/cards_lib/refinements.rb +1 -2
- data/lib/cards_lib/standard/rules/poker.rb +66 -0
- data/lib/cards_lib/standard/rules.rb +8 -0
- data/lib/cards_lib/standard.rb +2 -0
- data/lib/cards_lib/version.rb +1 -1
- metadata +5 -4
- data/CODE_OF_CONDUCT.md +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40686980c91619c8ef3bb32e4e588ac6aad753bd
|
4
|
+
data.tar.gz: 83b9ae9a10145ff9645e69a7c384bb76b7edb8c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d5ab265159385f58c1ee7c213260f6c83bb8ded6448d8f8ff0f90433f8233a7f7dc23ab564991409ab7b8b805fdc0402732266c67991bc2b3f662265e83f9f
|
7
|
+
data.tar.gz: 1f830281cea4d85741e25596f48884dd4469589eed84e2da52dbc1d8e25b778dca4d5d245d0584c64abd39c0bd7b0babd31cf0bfbe4e0143371392f3debb456b
|
data/README.md
CHANGED
@@ -41,6 +41,12 @@ CardsLib::IsSet.verify(
|
|
41
41
|
)
|
42
42
|
```
|
43
43
|
|
44
|
+
##Goodies
|
45
|
+
|
46
|
+
* lib/cards_lib/is_set.rb is a golden tool in card hand verification.
|
47
|
+
* In lib/cards_lib/standard.rb there are some basic deck templates.
|
48
|
+
* In lib/cards_lib/standard/rules/poker.rb there are some working Poker hand verification methods.
|
49
|
+
|
44
50
|
##License
|
45
51
|
|
46
52
|
The MIT License (MIT)
|
data/cards_lib.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>=
|
22
|
+
spec.required_ruby_version = '>= 2.0.0'
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.10.6"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.4"
|
data/lib/cards_lib/card.rb
CHANGED
@@ -5,7 +5,7 @@ module CardsLib
|
|
5
5
|
raise InvalidCardFace, "Parameter face cannot be blank!" if face.to_s.empty?
|
6
6
|
@suit = if_hash_then_fetch(face, :suit)
|
7
7
|
@rank = if_hash_then_fetch(face, :rank)
|
8
|
-
@face = face_from_rank_and_suit(@rank, @suit) if
|
8
|
+
@face = face_from_rank_and_suit(@rank, @suit) if face.is_a? Hash
|
9
9
|
|
10
10
|
@face ||= face
|
11
11
|
@ranker = ranker.new(rank)
|
@@ -56,14 +56,14 @@ module CardsLib
|
|
56
56
|
end
|
57
57
|
|
58
58
|
class InvalidCardFace < Exception; end
|
59
|
-
class
|
59
|
+
class InvalidRankAndSuit < Exception; end
|
60
60
|
|
61
61
|
private
|
62
62
|
def face_from_rank_and_suit(rank, suit)
|
63
63
|
if rank && suit
|
64
64
|
[rank, ((rank.length.>(1) && suit.length.>(1)) ? " of " : ""), suit].join
|
65
65
|
else
|
66
|
-
raise
|
66
|
+
raise InvalidRankAndSuit, "Suit and Rank provided in Hash are invalid!"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module CardsLib
|
2
|
+
module Standard
|
3
|
+
module Rules
|
4
|
+
module Poker
|
5
|
+
def self.precedence
|
6
|
+
[
|
7
|
+
:royal_flush, :straight_flush, :four_of_a_kind,
|
8
|
+
:full_house, :flush, :straight,
|
9
|
+
:three_of_a_kind, :two_pair, :one_pair,
|
10
|
+
:high_card
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.royal_flush(cards)
|
15
|
+
cards if IsSet.verify(cards, [:suited]) && straight_to_ace(cards)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.straight_flush(cards)
|
19
|
+
cards if IsSet.verify(cards, [:unique, :ordered, :suited], {min: 5, max: 5})
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.four_of_a_kind(cards)
|
23
|
+
cards if IsSet.verify(cards, [:unique, :paired], {min: 4, max: 4})
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.full_house(cards)
|
27
|
+
pair, set = cards.group_by(&:rank).values.sort
|
28
|
+
cards if pair.inject(:pair?) && IsSet.verify(set, [:unique, :paired], {min:3, max: 3})
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.flush(cards)
|
32
|
+
cards if IsSet.verify(cards, [:unique, :suited], {min: 5, max: 5})
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.straight(cards)
|
36
|
+
cards if IsSet.verify(cards, [:unique, :ordered], {min: 5, max: 5}) ||
|
37
|
+
straight_to_ace(cards)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.three_of_a_kind(cards)
|
41
|
+
cards if IsSet.verify(cards, [:unique, :paired], {min:3, max: 3})
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.two_pair(cards)
|
45
|
+
pair1, pair2 = cards.group_by(&:rank).values.sort
|
46
|
+
cards if pair1.inject(:pair?) && pair2.inject(:pair?)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.one_pair(cards)
|
50
|
+
cards if IsSet.verify(cards, [:unique, :paired], {min:2, max: 2})
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.high_card(cards)
|
54
|
+
cards.detect {|c| c.rank[/\AA/]} || cards.sort.pop
|
55
|
+
end
|
56
|
+
|
57
|
+
class << self
|
58
|
+
def straight_to_ace(cards)
|
59
|
+
cards.sort.map(&:rank) == Cards[*%w[As Ks Qs Js Ts]].sort.map(&:rank)
|
60
|
+
end
|
61
|
+
private :straight_to_ace
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/cards_lib/standard.rb
CHANGED
data/lib/cards_lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cards_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,7 +89,6 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".travis.yml"
|
92
|
-
- CODE_OF_CONDUCT.md
|
93
92
|
- Gemfile
|
94
93
|
- Guardfile
|
95
94
|
- LICENSE.txt
|
@@ -105,6 +104,8 @@ files:
|
|
105
104
|
- lib/cards_lib/ranker.rb
|
106
105
|
- lib/cards_lib/refinements.rb
|
107
106
|
- lib/cards_lib/standard.rb
|
107
|
+
- lib/cards_lib/standard/rules.rb
|
108
|
+
- lib/cards_lib/standard/rules/poker.rb
|
108
109
|
- lib/cards_lib/version.rb
|
109
110
|
homepage: http://github.com/danielpclark/CardsLib
|
110
111
|
licenses:
|
@@ -118,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
119
|
requirements:
|
119
120
|
- - ">="
|
120
121
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
122
|
+
version: 2.0.0
|
122
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
124
|
requirements:
|
124
125
|
- - ">="
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|