card_nine 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/card_nine.rb +0 -3
- data/lib/card_nine/dealer.rb +14 -0
- data/lib/card_nine/dealers/simple.rb +11 -0
- data/lib/card_nine/dealers/texas_holdem.rb +12 -17
- data/lib/card_nine/deck.rb +3 -7
- data/lib/card_nine/table.rb +33 -23
- data/spec/card_nine/dealers/simple_spec.rb +20 -0
- data/spec/card_nine/dealers/texas_holdem_spec.rb +0 -83
- data/spec/card_nine/deck_spec.rb +2 -1
- data/spec/card_nine/table_spec.rb +60 -55
- data/spec/card_nine_spec.rb +14 -3
- data/spec/spec_helper.rb +1 -1
- metadata +5 -5
- data/lib/card_nine/hand.rb +0 -63
- data/spec/card_nine/hand_spec.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6e81abfc7d2342293b27bd817dc6d3efd7dc6d
|
4
|
+
data.tar.gz: 443536f808e04a8ee0e1b04eb30fe2468aa276cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841fa6dae3ce1dd5b2dfd0bbffb7ce6795691b1fdada683304590a136f3ef5505828e8ee07cc6a6a7b432e67316fc1bf791d8824073ee797146fe44a2ba08df3
|
7
|
+
data.tar.gz: 53a22aadba21b045dc72073cc1bf851d6ec50d95165e3ab2c28b778ffe137b0669150e331930a55d097d4914224d73ee611da7be83fc2f503fab77c63bdaf581
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/card_nine.rb
CHANGED
data/lib/card_nine/dealer.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
module CardNine
|
2
2
|
class Dealer
|
3
|
+
|
4
|
+
attr_reader :deck, :locations, :stages
|
5
|
+
|
6
|
+
def initialize(deck, locations, stages = {})
|
7
|
+
@deck = deck
|
8
|
+
@locations = locations
|
9
|
+
@stages = stages
|
10
|
+
end
|
11
|
+
|
12
|
+
def deal(players)
|
13
|
+
Table.new(deck.shuffle, players, locations, stages)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
3
17
|
end
|
4
18
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'card_nine/cards/playing_card'
|
2
|
+
require 'card_nine/dealer'
|
3
|
+
require 'card_nine/table'
|
4
|
+
|
2
5
|
module CardNine
|
3
6
|
module Dealers
|
4
7
|
# implements a CardNine::Dealer for the game of Texas Holdem. This is only
|
@@ -18,29 +21,21 @@ module CardNine
|
|
18
21
|
# wagering(:round, hand)
|
19
22
|
# end
|
20
23
|
# wager(:resolve, hand)
|
21
|
-
class TexasHoldem
|
22
|
-
|
23
|
-
attr_accessor :players, :deck
|
24
|
+
class TexasHoldem < CardNine::Dealer
|
24
25
|
|
25
26
|
STAGES = {
|
26
|
-
deal_hole_cards: ->(
|
27
|
-
flop: ->(
|
28
|
-
turn: ->(
|
29
|
-
river: ->(
|
27
|
+
deal_hole_cards: ->(t) { t.deal_players(2) },
|
28
|
+
flop: ->(t) { t.discard; t.deal(3, to: :community) },
|
29
|
+
turn: ->(t) { t.discard; t.deal(to: :community) },
|
30
|
+
river: ->(t) { t.discard; t.deal(to: :community) },
|
31
|
+
fold: ->(t, p) { t.remove_player(p) }
|
30
32
|
}
|
31
33
|
|
32
|
-
def initialize
|
33
|
-
|
34
|
-
@deck = deck
|
35
|
-
end
|
36
|
-
|
37
|
-
# generate a new hand from this dealer
|
38
|
-
# @return [CardNine::Hand]
|
39
|
-
def new_hand
|
40
|
-
players.rotate!
|
41
|
-
Hand.start(players: players, deck: deck, stages: STAGES)
|
34
|
+
def initialize
|
35
|
+
super CardNine::Cards::PlayingCard.deck, [:community], STAGES
|
42
36
|
end
|
43
37
|
|
44
38
|
end
|
39
|
+
|
45
40
|
end
|
46
41
|
end
|
data/lib/card_nine/deck.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
+
require 'virtus'
|
1
2
|
module CardNine
|
2
3
|
class Deck
|
3
|
-
# @!method initialize(args = nil)
|
4
|
-
# will set the instance vars using the keys of args as a attribute name
|
5
|
-
# @param [Hash, Nil] args
|
6
4
|
include Virtus.model
|
7
5
|
|
8
|
-
|
9
|
-
# @return [Array<Card>] all cards in the deck
|
10
|
-
attribute :cards, Array[Card], default: []
|
6
|
+
attribute :cards, Array, default: []
|
11
7
|
|
12
8
|
# @!attribute [rw] rng
|
13
9
|
# @return [Random,#rand]
|
@@ -15,7 +11,7 @@ module CardNine
|
|
15
11
|
|
16
12
|
# @return Array[Card] randomized
|
17
13
|
def shuffle
|
18
|
-
cards.shuffle(random: rng)
|
14
|
+
cards.shuffle!(random: rng)
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
data/lib/card_nine/table.rb
CHANGED
@@ -1,38 +1,48 @@
|
|
1
|
-
require 'virtus'
|
2
1
|
module CardNine
|
3
|
-
# a CardNine::Table is the shoe, discard pile, and player hands
|
4
2
|
class Table
|
5
|
-
|
3
|
+
attr_reader :shoe, :players, :hands, :locations, :discards, :stages
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize(shoe, players, locations, stages = {})
|
6
|
+
@shoe = shoe
|
7
|
+
@players = players
|
8
|
+
@locations = locations
|
9
|
+
@discards = []
|
10
|
+
@stages = stages
|
11
|
+
@hands = { shoe: @shoe, discards: @discards }
|
12
|
+
(@players + @locations).each { |l| register_loc(l) }
|
13
|
+
end
|
10
14
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
15
|
+
# @return Array all locations that cards can be dealt to
|
16
|
+
def locs
|
17
|
+
@hands.keys
|
18
|
+
end
|
14
19
|
|
15
|
-
#
|
16
|
-
|
17
|
-
|
20
|
+
# @param [String,Symbol] loc which location to see
|
21
|
+
# @return Array[Card] cards for that loc
|
22
|
+
def cards_for(loc)
|
23
|
+
@hands[loc]
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
def
|
22
|
-
|
26
|
+
|
27
|
+
def deal(count = 1, from: :shoe, to:)
|
28
|
+
cards_for(to).push(*cards_for(from).pop(count))
|
23
29
|
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
layout[loc]
|
31
|
+
def deal_each_player(count)
|
32
|
+
count.times { @players.each { |p| deal(to: p) } }
|
28
33
|
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
l = Hash.new { |h, k| h[k] = [] }
|
33
|
-
l[:shoe] = self.deck.shuffle
|
34
|
-
return l
|
35
|
+
def deal_each_location(count)
|
36
|
+
count.times { @locations.each { |p| deal(to: p) } }
|
35
37
|
end
|
36
38
|
|
39
|
+
def deal_stage(stage_name)
|
40
|
+
@stages[stage_name].call(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def register_loc(loc)
|
45
|
+
@hands[loc] = []
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'card_nine/dealers/simple'
|
3
|
+
|
4
|
+
describe CardNine::Dealers::Simple do
|
5
|
+
let(:card_names) { %w{Batman Nightwing Batgirl Robin} }
|
6
|
+
let(:cards) { card_names.map { |c| CardNine::Cards::SimpleCard.new(c) } }
|
7
|
+
let(:deck) { CardNine::Deck.new(cards: card_names) }
|
8
|
+
|
9
|
+
let(:players) { %w{Tim Dick Jason} }
|
10
|
+
let(:locations) { [:batcave] }
|
11
|
+
let(:expected_attributes) {
|
12
|
+
{
|
13
|
+
deck: deck,
|
14
|
+
locations: locations
|
15
|
+
}
|
16
|
+
}
|
17
|
+
subject { CardNine::Dealers::Simple.new(deck, locations) }
|
18
|
+
|
19
|
+
|
20
|
+
end
|
@@ -2,88 +2,5 @@ require 'rspec'
|
|
2
2
|
require 'card_nine/dealers/texas_holdem'
|
3
3
|
|
4
4
|
describe CardNine::Dealers::TexasHoldem do
|
5
|
-
let(:players) { %w|Barbera Stephanie Cassandra| }
|
6
|
-
|
7
|
-
subject { described_class.new(players: players) }
|
8
|
-
|
9
|
-
it { is_expected.to be_a described_class }
|
10
|
-
it { is_expected.to respond_to :new_hand }
|
11
|
-
|
12
|
-
describe '.new_hand' do
|
13
|
-
subject { described_class.new(players: players).new_hand }
|
14
|
-
it { is_expected.to be_a CardNine::Hand }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'STAGES' do
|
18
|
-
context ':hole_cards' do
|
19
|
-
subject do
|
20
|
-
h = described_class.new(players: players).new_hand
|
21
|
-
h.deal_stage(:deal_hole_cards)
|
22
|
-
h
|
23
|
-
end
|
24
|
-
it { is_expected.to be_a CardNine::Hand }
|
25
|
-
it { expect(subject.at('Barbera').length).to eq 2 }
|
26
|
-
it { expect(subject.at('Stephanie').length).to eq 2 }
|
27
|
-
it { expect(subject.at('Cassandra').length).to eq 2 }
|
28
|
-
it { expect(subject.at(:discards)).to be_empty }
|
29
|
-
it { expect(subject.at(:shoe).length).to eq 46 }
|
30
|
-
end
|
31
|
-
|
32
|
-
context ':flop' do
|
33
|
-
subject do
|
34
|
-
h = described_class.new(players: players).new_hand
|
35
|
-
h.deal_stage(:flop)
|
36
|
-
h
|
37
|
-
end
|
38
|
-
it { is_expected.to be_a CardNine::Hand }
|
39
|
-
it { expect(subject.at(:community).length).to eq 3 }
|
40
|
-
it { expect(subject.at(:discards).length).to eq 1 }
|
41
|
-
it { expect(subject.at(:shoe).length).to eq 48 }
|
42
|
-
end
|
43
|
-
|
44
|
-
context ':turn' do
|
45
|
-
subject do
|
46
|
-
h = described_class.new(players: players).new_hand
|
47
|
-
h.deal_stage(:turn)
|
48
|
-
h
|
49
|
-
end
|
50
|
-
it { is_expected.to be_a CardNine::Hand }
|
51
|
-
it { expect(subject.at(:community).length).to eq 1 }
|
52
|
-
it { expect(subject.at(:discards).length).to eq 1 }
|
53
|
-
it { expect(subject.at(:shoe).length).to eq 50 }
|
54
|
-
end
|
55
|
-
|
56
|
-
context ':river' do
|
57
|
-
subject do
|
58
|
-
h = described_class.new(players: players).new_hand
|
59
|
-
h.deal_stage(:river)
|
60
|
-
h
|
61
|
-
end
|
62
|
-
it { is_expected.to be_a CardNine::Hand }
|
63
|
-
it { expect(subject.at(:community).length).to eq 1 }
|
64
|
-
it { expect(subject.at(:discards).length).to eq 1 }
|
65
|
-
it { expect(subject.at(:shoe).length).to eq 50 }
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'all in order' do
|
69
|
-
subject do
|
70
|
-
h = described_class.new(players: players).new_hand
|
71
|
-
h.deal_stage(:deal_hole_cards)
|
72
|
-
h.deal_stage(:flop)
|
73
|
-
h.deal_stage(:turn)
|
74
|
-
h.deal_stage(:river)
|
75
|
-
h
|
76
|
-
end
|
77
|
-
it { is_expected.to be_a CardNine::Hand }
|
78
|
-
it { expect(subject.at('Barbera').length).to eq 2 }
|
79
|
-
it { expect(subject.at('Stephanie').length).to eq 2 }
|
80
|
-
it { expect(subject.at('Cassandra').length).to eq 2 }
|
81
|
-
it { expect(subject.at(:community).length).to eq 5 }
|
82
|
-
it { expect(subject.at(:discards).length).to eq 3 }
|
83
|
-
it { expect(subject.at(:shoe).length).to eq 38 }
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
5
|
|
89
6
|
end
|
data/spec/card_nine/deck_spec.rb
CHANGED
@@ -7,13 +7,14 @@ describe CardNine::Deck do
|
|
7
7
|
let(:rng) { Random.new }
|
8
8
|
subject { described_class.new(cards: cards) }
|
9
9
|
it { is_expected.to have_attributes(cards: cards) }
|
10
|
+
it { expect(subject.cards.length).to eq 4 }
|
10
11
|
it { expect(subject.rng).to respond_to :rand }
|
11
12
|
it { is_expected.to respond_to :shuffle }
|
12
13
|
it 'should call shuffle on cards list' do
|
13
14
|
cards = %w|Batman Batgirl Robin Nightwing|.map { |n| CardNine::Cards::SimpleCard.new(name: n) }
|
14
15
|
rng = Random.new(1234)
|
15
16
|
deck = described_class.new(rng: rng, cards: cards)
|
16
|
-
expect(deck.cards).to receive(:shuffle)
|
17
|
+
expect(deck.cards).to receive(:shuffle!)
|
17
18
|
deck.shuffle
|
18
19
|
end
|
19
20
|
|
@@ -2,73 +2,78 @@ require 'rspec'
|
|
2
2
|
require 'card_nine/table'
|
3
3
|
|
4
4
|
describe CardNine::Table do
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
let(:deck) { CardNine::Deck.new(cards: cards) }
|
10
|
-
subject { described_class.new(deck: deck) }
|
11
|
-
it { is_expected.to be_a described_class }
|
12
|
-
it { expect(subject.deck).to eq deck }
|
13
|
-
it { expect(subject.players).to eq [] }
|
14
|
-
it { expect(subject.layout).to be_a Hash }
|
15
|
-
it { expect(subject.layout[:shoe].length).to eq 4 }
|
16
|
-
it { expect(subject.layout[:discards]).to eq [] }
|
17
|
-
describe '.move_card(from: old_pile, to: new_pile)' do
|
18
|
-
context 'using default count and :from' do
|
19
|
-
subject do
|
20
|
-
table = described_class.new(deck: deck, players: %w|Jason Tim|)
|
21
|
-
table.move_card(to: 'Tim')
|
22
|
-
table.move_card(to: 'Jason')
|
23
|
-
table.move_card(to: :discards)
|
24
|
-
table
|
25
|
-
end
|
5
|
+
let(:card_names) { %w{Batman Nightwing Batgirl Robin} }
|
6
|
+
let(:cards) { card_names.map { |c| CardNine::Cards::SimpleCard.new(c) } }
|
7
|
+
let(:shoe) { CardNine::Deck.new(cards: card_names).cards }
|
26
8
|
|
27
|
-
|
9
|
+
let(:players) { %w{Tim Dick Jason} }
|
10
|
+
let(:locations) { [:batcave] }
|
11
|
+
let(:expected_locs) { [:shoe, :discards] + locations + players }
|
12
|
+
let(:expected_attributes) {
|
13
|
+
{
|
14
|
+
shoe: shoe,
|
15
|
+
players: players,
|
16
|
+
locations: locations,
|
17
|
+
stages: {}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
subject { CardNine::Table.new(shoe, players, locations) }
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
22
|
+
it { is_expected.to be_a CardNine::Table }
|
23
|
+
it { is_expected.to have_attributes expected_attributes }
|
24
|
+
it { expect(subject.locs).to include *expected_locs }
|
25
|
+
it { expect(subject.discards).to eq [] }
|
26
|
+
it { expect(subject.cards_for(:batcave)).to eq [] }
|
27
|
+
it { expect(subject.cards_for('Tim')).to eq [] }
|
36
28
|
|
29
|
+
describe '.deal(count = 1, to:)' do
|
30
|
+
let(:table) { CardNine::Table.new(shoe, players, locations) }
|
31
|
+
subject { table.deal(to: :batcave); table }
|
32
|
+
it { expect(subject.cards_for(:batcave)).to eq ['Robin'] }
|
33
|
+
it { expect(subject.shoe).to eq %w{Batman Nightwing Batgirl } }
|
34
|
+
context 'with a count of 2' do
|
35
|
+
subject { table.deal(2, to: :batcave); table }
|
36
|
+
it { expect(subject.cards_for(:batcave)).to eq ['Batgirl', 'Robin'] }
|
37
|
+
it { expect(subject.shoe).to eq ['Batman', 'Nightwing'] }
|
37
38
|
end
|
38
|
-
context 'with
|
39
|
+
context 'with a from location' do
|
39
40
|
subject do
|
40
|
-
table
|
41
|
-
table.
|
42
|
-
table.move_card(2, to: 'Jason')
|
41
|
+
table.deal(2, to: :batcave)
|
42
|
+
table.deal(from: :batcave, to: 'Tim')
|
43
43
|
table
|
44
44
|
end
|
45
|
+
it { expect(subject.cards_for(:batcave)).to eq ['Batgirl'] }
|
46
|
+
it { expect(subject.cards_for('Tim')).to eq ['Robin'] }
|
47
|
+
end
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
expect(subject.at(:shoe).length).to eq 0
|
52
|
-
expect(subject.at(:discards).length).to eq 0
|
53
|
-
end
|
50
|
+
describe '.deal_each_player(grp, count)' do
|
51
|
+
let(:table) { CardNine::Table.new(shoe, players, locations) }
|
52
|
+
subject do
|
53
|
+
table.deal_each_player(1)
|
54
|
+
table
|
54
55
|
end
|
55
|
-
|
56
|
-
|
57
|
-
table = described_class.new(deck: deck, players: %w|Jason Tim|)
|
58
|
-
table.move_card(4, to: 'Tim')
|
59
|
-
table.move_card(2, to: 'Jason', from: 'Tim')
|
60
|
-
table
|
61
|
-
end
|
56
|
+
it { expect(subject.shoe).to eq ['Batman'] }
|
57
|
+
it { expect(subject.cards_for('Tim')).to eq ['Robin'] }
|
62
58
|
|
63
|
-
|
59
|
+
context 'with a count over 1' do
|
60
|
+
let(:card_names) { %w{Batman Nightwing Batgirl Robin Spoiler Huntress} }
|
61
|
+
subject { table.deal_each_player(2); table }
|
62
|
+
it { expect(subject.shoe).to eq [] }
|
63
|
+
it { expect(subject.cards_for('Dick')).to eq ['Spoiler', 'Nightwing'] }
|
64
|
+
end
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
describe '.deal_stage(stage_name)' do
|
68
|
+
it 'should yield to the named proc' do
|
69
|
+
canary = double('canary')
|
70
|
+
expect(canary).to receive(:call)
|
71
|
+
stages = { deal_1: canary }
|
72
|
+
table = CardNine::Table.new(shoe, players, locations, stages)
|
73
|
+
table.deal_stage(:deal_1)
|
71
74
|
end
|
72
75
|
|
73
76
|
end
|
77
|
+
|
78
|
+
|
74
79
|
end
|
data/spec/card_nine_spec.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'card_nine'
|
3
|
-
|
3
|
+
require 'card_nine/dealers/texas_holdem'
|
4
|
+
require 'card_nine/dealers/simple'
|
4
5
|
describe CardNine do
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
describe 'texas holdem dealer' do
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Simple dealer' do
|
12
|
+
let(:deck) { CardNine::Deck.new(cards: %w{Batman Nightwing Batgirl Robin}) }
|
13
|
+
|
14
|
+
let(:players) { %w{Tim Dick Jason} }
|
15
|
+
subject { CardNine::Dealers::Simple.new(deck, [:batcave]) }
|
16
|
+
|
17
|
+
it { is_expected.to be_a CardNine::Dealers::Simple }
|
18
|
+
end
|
8
19
|
|
9
20
|
|
10
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,7 @@ RSpec.configure do |config|
|
|
17
17
|
config.filter_run :focus
|
18
18
|
config.run_all_when_everything_filtered = true
|
19
19
|
config.filter_run_excluding :rewrite => true
|
20
|
-
|
20
|
+
config.order = :random
|
21
21
|
# rspec-mocks config goes here. You can use an alternate test double
|
22
22
|
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
23
23
|
config.mock_with :rspec do |mocks|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card_nine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott M Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -201,17 +201,17 @@ files:
|
|
201
201
|
- lib/card_nine/cards/playing_card.rb
|
202
202
|
- lib/card_nine/cards/simple_card.rb
|
203
203
|
- lib/card_nine/dealer.rb
|
204
|
+
- lib/card_nine/dealers/simple.rb
|
204
205
|
- lib/card_nine/dealers/texas_holdem.rb
|
205
206
|
- lib/card_nine/deck.rb
|
206
|
-
- lib/card_nine/hand.rb
|
207
207
|
- lib/card_nine/table.rb
|
208
208
|
- spec/card_nine/card_spec.rb
|
209
209
|
- spec/card_nine/cards/playing_card_spec.rb
|
210
210
|
- spec/card_nine/cards/simple_card_spec.rb
|
211
211
|
- spec/card_nine/dealer_spec.rb
|
212
|
+
- spec/card_nine/dealers/simple_spec.rb
|
212
213
|
- spec/card_nine/dealers/texas_holdem_spec.rb
|
213
214
|
- spec/card_nine/deck_spec.rb
|
214
|
-
- spec/card_nine/hand_spec.rb
|
215
215
|
- spec/card_nine/table_spec.rb
|
216
216
|
- spec/card_nine_spec.rb
|
217
217
|
- spec/spec_helper.rb
|
@@ -244,9 +244,9 @@ test_files:
|
|
244
244
|
- spec/card_nine/cards/playing_card_spec.rb
|
245
245
|
- spec/card_nine/cards/simple_card_spec.rb
|
246
246
|
- spec/card_nine/dealer_spec.rb
|
247
|
+
- spec/card_nine/dealers/simple_spec.rb
|
247
248
|
- spec/card_nine/dealers/texas_holdem_spec.rb
|
248
249
|
- spec/card_nine/deck_spec.rb
|
249
|
-
- spec/card_nine/hand_spec.rb
|
250
250
|
- spec/card_nine/table_spec.rb
|
251
251
|
- spec/card_nine_spec.rb
|
252
252
|
- spec/spec_helper.rb
|
data/lib/card_nine/hand.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'virtus'
|
2
|
-
require 'card_nine/deck'
|
3
|
-
require 'card_nine/table'
|
4
|
-
module CardNine
|
5
|
-
class Hand
|
6
|
-
include Virtus.model
|
7
|
-
|
8
|
-
# @!attribute [rw] deck
|
9
|
-
# @return [CardNine::Deck]
|
10
|
-
attribute :deck, CardNine::Deck
|
11
|
-
|
12
|
-
# @!attribute [rw] players
|
13
|
-
# @return [Array]
|
14
|
-
attribute :players, Array, default: []
|
15
|
-
|
16
|
-
# @!attribute [rw] table
|
17
|
-
# @return [CardNine::Table]
|
18
|
-
attribute :table, CardNine::Table, default: :initialize_table
|
19
|
-
|
20
|
-
attribute :stages, Hash, default: {}
|
21
|
-
|
22
|
-
# create a new hand, yield to a setup block if given
|
23
|
-
def self.start(args = nil)
|
24
|
-
hand = self.new(args)
|
25
|
-
yield hand if block_given?
|
26
|
-
hand
|
27
|
-
end
|
28
|
-
|
29
|
-
# pass deal commands to table
|
30
|
-
# @yieldparam [Table] table for current hand
|
31
|
-
def deal(count = 1, from: :shoe, to:)
|
32
|
-
table.move_card(count, from: from, to: to)
|
33
|
-
end
|
34
|
-
|
35
|
-
def deal_players(count = 1, from: :shoe)
|
36
|
-
count.times do
|
37
|
-
players.each do |p|
|
38
|
-
deal(1, from: from, to: p)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def discard(count = 1, from: :shoe)
|
44
|
-
deal(count, from: from, to: :discards)
|
45
|
-
end
|
46
|
-
|
47
|
-
def deal_stage(stage_name = nil, &blk)
|
48
|
-
stages[stage_name].call(self) if stage_name && stages[stage_name]
|
49
|
-
blk.call(self) if blk
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
# @return Array<Card> cards at +loc+ location on table
|
54
|
-
def at(loc)
|
55
|
-
table.at(loc)
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def initialize_table
|
60
|
-
CardNine::Table.new(players: players, deck: deck)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/spec/card_nine/hand_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'card_nine/hand'
|
3
|
-
|
4
|
-
describe CardNine::Hand do
|
5
|
-
let(:players) { %w|Batman Batgirl Robin| }
|
6
|
-
let(:deck) { CardNine::Cards::PlayingCard.deck }
|
7
|
-
let(:table) { CardNine::Table.new(players: players, deck: deck) }
|
8
|
-
let(:stages) { { deal_five: ->(h) { h.deal_players(5) } } }
|
9
|
-
let(:args) { { players: players, deck: deck } }
|
10
|
-
subject { described_class.new(args) }
|
11
|
-
it { is_expected.to be_a described_class }
|
12
|
-
|
13
|
-
it { expect(subject.deck).to eq deck }
|
14
|
-
it { expect(subject.players).to eq players }
|
15
|
-
it { expect(subject.table).to be_a CardNine::Table }
|
16
|
-
it { expect(subject.stages).to be_a Hash }
|
17
|
-
|
18
|
-
describe '#start(args = nil, &blk)' do
|
19
|
-
it { expect(described_class.start(args)).to be_a described_class }
|
20
|
-
it 'executes block with hand as argument' do
|
21
|
-
hand = described_class.start(args) { |h| h.players << 'Nightwing' }
|
22
|
-
expect(hand.players).to include 'Nightwing'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.at(loc)' do
|
27
|
-
subject { described_class.start(args) }
|
28
|
-
it { is_expected.to be_a described_class }
|
29
|
-
it { expect(subject.at(:shoe).length).to eq 52 }
|
30
|
-
it { expect(subject.at(:discards)).to eq [] }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '.deal_stage(stage_name = nil, &blk)' do
|
34
|
-
context 'with only block' do
|
35
|
-
subject do
|
36
|
-
h = described_class.start(players: players, deck: deck, table: table, stages: stages)
|
37
|
-
h.deal_stage do |h|
|
38
|
-
h.deal(3, to: :discards)
|
39
|
-
end
|
40
|
-
h
|
41
|
-
end
|
42
|
-
it { expect(subject.at(:discards).length).to eq 3 }
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'with only stage' do
|
46
|
-
subject do
|
47
|
-
h = described_class.start(players: players, deck: deck, table: table, stages: stages)
|
48
|
-
h.deal_stage(:deal_five)
|
49
|
-
h
|
50
|
-
end
|
51
|
-
it { expect(subject.at('Batman').length).to eq 5 }
|
52
|
-
it { expect(subject.at('Batgirl').length).to eq 5 }
|
53
|
-
it { expect(subject.at('Robin').length).to eq 5 }
|
54
|
-
end
|
55
|
-
context 'with both stages and block' do
|
56
|
-
subject do
|
57
|
-
h = described_class.start(players: players, deck: deck, table: table, stages: stages)
|
58
|
-
h.deal_stage(:deal_five) { |h| h.deal(6, to: :discards) }
|
59
|
-
h
|
60
|
-
end
|
61
|
-
it { expect(subject.at('Batman').length).to eq 5 }
|
62
|
-
it { expect(subject.at('Batgirl').length).to eq 5 }
|
63
|
-
it { expect(subject.at('Robin').length).to eq 5 }
|
64
|
-
it { expect(subject.at(:discards).length).to eq 6 }
|
65
|
-
it { expect(subject.at(:shoe).length).to eq 31 }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|