Class: Poker::Card
- Inherits:
-
Object
- Object
- Poker::Card
- Defined in:
- lib/poker/card.rb
Constant Summary collapse
- RANKS =
%w{ 2 3 4 5 6 7 8 9 T J Q K A }
- SUITS =
%w{ c d h s }
- PRIMES =
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
Instance Attribute Summary collapse
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#rank_value ⇒ Object
readonly
Returns the value of attribute rank_value.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
-
#suit_value ⇒ Object
readonly
Returns the value of attribute suit_value.
Instance Method Summary collapse
-
#initialize(str) ⇒ Card
constructor
A new instance of Card.
- #to_s ⇒ Object
-
#value ⇒ Object
An integer is made up of four bytes.
Constructor Details
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
7 8 9 |
# File 'lib/poker/card.rb', line 7 def rank @rank end |
#rank_value ⇒ Object (readonly)
Returns the value of attribute rank_value.
7 8 9 |
# File 'lib/poker/card.rb', line 7 def rank_value @rank_value end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
7 8 9 |
# File 'lib/poker/card.rb', line 7 def suit @suit end |
#suit_value ⇒ Object (readonly)
Returns the value of attribute suit_value.
7 8 9 |
# File 'lib/poker/card.rb', line 7 def suit_value @suit_value end |
Instance Method Details
#to_s ⇒ Object
34 35 36 |
# File 'lib/poker/card.rb', line 34 def to_s @str end |
#value ⇒ Object
An integer is made up of four bytes. The high-order bytes are used to hold the rank bit pattern, whereas the low-order bytes hold the suit/rank/prime value of the card.
--------
——–--------
——–+ |xxxbbbbb|bbbbbbbb|cdhsrrrr|xxpppppp| --------
——–--------
——–+
p = prime number of rank (deuce=2,trey=3,four=5,five=7,…,ace=41) r = rank of card (deuce=0,trey=1,four=2,five=3,…,ace=12) cdhs = suit of card b = bit turned on depending on rank of card #
29 30 31 32 |
# File 'lib/poker/card.rb', line 29 def value PRIMES[rank_value] | (rank_value << 8) | 0x8000 >> suit_value | (1 << (16 + rank_value)) end |