card_nine 0.5.1 → 0.6.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/cards/playing_card.rb +1 -0
- data/lib/card_nine/cards/simple_card.rb +1 -0
- data/lib/card_nine/dealer.rb +14 -2
- data/lib/card_nine/dealers/simple.rb +0 -2
- data/lib/card_nine/dealers/texas_holdem.rb +3 -2
- data/lib/card_nine/deck.rb +2 -0
- data/lib/card_nine/table.rb +18 -24
- data/spec/card_nine/dealers/simple_spec.rb +5 -6
- data/spec/card_nine/table_spec.rb +63 -60
- data/spec/card_nine_spec.rb +1 -4
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d801904950c45689dbe83317c5fcd4f025f36b9e
|
4
|
+
data.tar.gz: 9395b4a5fa1bc8672e94194846a2d03c30f4bc0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76354cab073b3b811ce4670ce2f4ac490e03977ee1b13fd54495c6bae822585c8322f80ecc4a30bed323846edaea9a03e5d147662146b233e138002dac998d51
|
7
|
+
data.tar.gz: abf13a96403a2a7649d0dc10afd73f298ff8c5ac3883cf20dff4668de4f54322181899c7611e68d3a87e336cf7f87f3d8163ced64574c236927f2a253eaa3843
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/card_nine/dealer.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
module CardNine
|
2
2
|
class Dealer
|
3
3
|
|
4
|
+
# @!attribute [rw] deck
|
5
|
+
# @return [CardNine::Deck]
|
6
|
+
# @!attribute [rw] locations
|
7
|
+
# @return [Array<Symbol>]
|
8
|
+
# @!attribute [rw] players
|
9
|
+
# @return [Hash<Symbol => Proc>]
|
4
10
|
attr_reader :deck, :locations, :stages
|
5
11
|
|
12
|
+
# @param [CardNine::Deck] deck
|
13
|
+
# @param [Array<Symbol>] locations
|
14
|
+
# @param [stages]
|
6
15
|
def initialize(deck, locations, stages = {})
|
7
16
|
@deck = deck
|
8
17
|
@locations = locations
|
9
18
|
@stages = stages
|
10
19
|
end
|
11
20
|
|
21
|
+
# Create a CardNine::Table
|
22
|
+
# @param [Array<String,Object>] players
|
23
|
+
# @return [CardNine::Table] using deck, players, locations and stages
|
12
24
|
def deal(players)
|
13
|
-
|
25
|
+
locs = (locations + players).reduce({}) { |h, e| h[e] = []; h }
|
26
|
+
CardNine::Table.new(deck.shuffle, locs, stages)
|
14
27
|
end
|
15
|
-
|
16
28
|
end
|
17
29
|
end
|
@@ -23,6 +23,8 @@ module CardNine
|
|
23
23
|
# wager(:resolve, hand)
|
24
24
|
class TexasHoldem < CardNine::Dealer
|
25
25
|
|
26
|
+
# A hash of stages
|
27
|
+
# @return [Hash<Symbol => Proc>]
|
26
28
|
STAGES = {
|
27
29
|
deal_hole_cards: ->(t) { t.deal_players(2) },
|
28
30
|
flop: ->(t) { t.discard; t.deal(3, to: :community) },
|
@@ -31,11 +33,10 @@ module CardNine
|
|
31
33
|
fold: ->(t, p) { t.remove_player(p) }
|
32
34
|
}
|
33
35
|
|
36
|
+
# create a new dealer using a PlayingCard Deck
|
34
37
|
def initialize
|
35
38
|
super CardNine::Cards::PlayingCard.deck, [:community], STAGES
|
36
39
|
end
|
37
|
-
|
38
40
|
end
|
39
|
-
|
40
41
|
end
|
41
42
|
end
|
data/lib/card_nine/deck.rb
CHANGED
data/lib/card_nine/table.rb
CHANGED
@@ -1,48 +1,42 @@
|
|
1
1
|
module CardNine
|
2
2
|
class Table
|
3
|
-
|
3
|
+
attr :shoe, :discards, :stages
|
4
4
|
|
5
|
-
def initialize(shoe,
|
6
|
-
@shoe
|
7
|
-
@
|
5
|
+
def initialize(shoe, locations, stages: {})
|
6
|
+
@shoe = shoe
|
7
|
+
@discards = []
|
8
8
|
@locations = locations
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
(@players + @locations).each { |l| register_loc(l) }
|
9
|
+
@stages = stages
|
10
|
+
register_location(:shoe, shoe)
|
11
|
+
register_location(:discards, @discards)
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def register_location(loc_name, loc_container)
|
15
|
+
@locations[loc_name] = loc_container
|
16
|
+
end
|
17
|
+
|
18
|
+
def locations
|
19
|
+
@locations.keys
|
18
20
|
end
|
19
21
|
|
20
22
|
# @param [String,Symbol] loc which location to see
|
21
23
|
# @return Array[Card] cards for that loc
|
22
24
|
def cards_for(loc)
|
23
|
-
@
|
25
|
+
@locations[loc]
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
28
|
def deal(count = 1, from: :shoe, to:)
|
28
29
|
cards_for(to).push(*cards_for(from).pop(count))
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
count.times {
|
32
|
+
def deal_each_matching(count = 1, &blk)
|
33
|
+
count.times { match_locations(&blk).each { |p| deal(to: p) } }
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
36
|
+
def match_locations(&blk)
|
37
|
+
locations.select { |e| blk.call(e, cards_for(e)) }
|
37
38
|
end
|
38
39
|
|
39
|
-
def deal_stage(stage_name)
|
40
|
-
@stages[stage_name].call(self)
|
41
|
-
end
|
42
40
|
|
43
|
-
private
|
44
|
-
def register_loc(loc)
|
45
|
-
@hands[loc] = []
|
46
|
-
end
|
47
41
|
end
|
48
42
|
end
|
@@ -3,18 +3,17 @@ require 'card_nine/dealers/simple'
|
|
3
3
|
|
4
4
|
describe CardNine::Dealers::Simple do
|
5
5
|
let(:card_names) { %w{Batman Nightwing Batgirl Robin} }
|
6
|
-
let(:cards) { card_names.map { |c| CardNine::Cards::SimpleCard.new(c) } }
|
7
6
|
let(:deck) { CardNine::Deck.new(cards: card_names) }
|
8
7
|
|
9
8
|
let(:players) { %w{Tim Dick Jason} }
|
10
|
-
let(:locations) { [
|
11
|
-
let(:expected_attributes)
|
9
|
+
let(:locations) { { batcave: [] } }
|
10
|
+
let(:expected_attributes) do
|
12
11
|
{
|
13
12
|
deck: deck,
|
14
13
|
locations: locations
|
15
14
|
}
|
16
|
-
|
15
|
+
end
|
17
16
|
subject { CardNine::Dealers::Simple.new(deck, locations) }
|
18
|
-
|
19
|
-
|
17
|
+
it { is_expected.to be_a described_class }
|
18
|
+
it { is_expected.to be_a_kind_of CardNine::Dealer }
|
20
19
|
end
|
@@ -2,78 +2,81 @@ require 'rspec'
|
|
2
2
|
require 'card_nine/table'
|
3
3
|
|
4
4
|
describe CardNine::Table do
|
5
|
-
let(:card_names) { %w{Batman
|
6
|
-
let(:cards) { card_names.map { |c| CardNine::Cards::SimpleCard.new(c) } }
|
5
|
+
let(:card_names) { %w{Zorro Batman Batgirl Robin} }
|
7
6
|
let(:shoe) { CardNine::Deck.new(cards: card_names).cards }
|
7
|
+
let(:locations) do
|
8
|
+
h = {}
|
9
|
+
h[:batplane] = []
|
10
|
+
h
|
11
|
+
end
|
12
|
+
subject { described_class.new(shoe, locations) }
|
8
13
|
|
9
|
-
|
10
|
-
|
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) }
|
21
|
-
|
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 [] }
|
14
|
+
it { is_expected.to be_a described_class }
|
15
|
+
it { expect(subject.locations).to eq [:batplane, :shoe, :discards] }
|
28
16
|
|
29
|
-
describe '
|
30
|
-
|
31
|
-
|
32
|
-
|
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'] }
|
17
|
+
describe 'easy stuff' do
|
18
|
+
it 'returns the container for a given location' do
|
19
|
+
subject.register_location(:tim, :drake_manor)
|
20
|
+
expect(subject.cards_for(:tim)).to eq :drake_manor
|
38
21
|
end
|
39
|
-
|
40
|
-
subject
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
it { expect(subject.cards_for('Tim')).to eq ['Robin'] }
|
22
|
+
it 'registers locations' do
|
23
|
+
subject.register_location(:tim, [:drake_manor])
|
24
|
+
expect(subject.cards_for(:tim)).to eq [:drake_manor]
|
25
|
+
end
|
26
|
+
it 'reports locations' do
|
27
|
+
subject.register_location(:tim, [:drake_manor])
|
28
|
+
expect(subject.locations).to eq [:batplane, :shoe, :discards, :tim]
|
47
29
|
end
|
48
30
|
end
|
49
31
|
|
50
|
-
describe '.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
32
|
+
describe '.deal(count = 1, from: :shoe, to:' do
|
33
|
+
context 'with default count' do
|
34
|
+
subject do
|
35
|
+
s = described_class.new(shoe, locations)
|
36
|
+
s.deal(to: :batplane)
|
37
|
+
s
|
38
|
+
end
|
39
|
+
it { expect(subject.shoe.count).to eq 3 }
|
40
|
+
it { expect(subject.cards_for(:batplane).first).to eq 'Robin' }
|
55
41
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
it { expect(subject.shoe).to eq
|
63
|
-
it { expect(subject.cards_for(
|
42
|
+
context 'with given count' do
|
43
|
+
subject do
|
44
|
+
s = described_class.new(shoe, locations)
|
45
|
+
s.deal(2, to: :batplane)
|
46
|
+
s
|
47
|
+
end
|
48
|
+
it { expect(subject.shoe.count).to eq 2 }
|
49
|
+
it { expect(subject.cards_for(:batplane).first).to eq 'Batgirl' }
|
50
|
+
it { expect(subject.cards_for(:batplane).last).to eq 'Robin' }
|
64
51
|
end
|
65
52
|
end
|
53
|
+
describe '.deal_each_matching(count = 1){|location, container|}' do
|
54
|
+
context 'with default count' do
|
55
|
+
subject do
|
56
|
+
locations['Alfred'] = []
|
57
|
+
locations['James'] = []
|
58
|
+
s = described_class.new(shoe, locations)
|
59
|
+
s.deal_each_matching { |location, container| location.is_a? String }
|
60
|
+
s
|
61
|
+
end
|
62
|
+
it { expect(subject.shoe.count).to eq 2 }
|
63
|
+
it { expect(subject.cards_for('Alfred').first).to eq 'Robin' }
|
64
|
+
it { expect(subject.cards_for('James').first).to eq 'Batgirl' }
|
65
|
+
it { expect(subject.discards).to eq [] }
|
66
|
+
it { expect(subject.cards_for(:batplane)).to eq [] }
|
66
67
|
|
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)
|
74
68
|
end
|
75
|
-
|
69
|
+
context 'with given count' do
|
70
|
+
subject do
|
71
|
+
s = described_class.new(shoe, locations)
|
72
|
+
s.deal_each_matching(2) { |l, c| l.is_a?(Symbol) && l != :shoe }
|
73
|
+
s
|
74
|
+
end
|
75
|
+
it { expect(subject.shoe.count).to eq 0 }
|
76
|
+
it { expect(subject.cards_for(:discards)).to eq ['Batgirl', 'Zorro'] }
|
77
|
+
it { expect(subject.cards_for(:batplane)).to eq ['Robin', 'Batman'] }
|
78
|
+
end
|
76
79
|
end
|
80
|
+
end
|
77
81
|
|
78
82
|
|
79
|
-
end
|
data/spec/card_nine_spec.rb
CHANGED
@@ -5,17 +5,14 @@ require 'card_nine/dealers/simple'
|
|
5
5
|
describe CardNine do
|
6
6
|
|
7
7
|
describe 'texas holdem dealer' do
|
8
|
-
|
9
8
|
end
|
10
9
|
|
11
10
|
describe 'Simple dealer' do
|
12
11
|
let(:deck) { CardNine::Deck.new(cards: %w{Batman Nightwing Batgirl Robin}) }
|
13
12
|
|
14
13
|
let(:players) { %w{Tim Dick Jason} }
|
15
|
-
subject { CardNine::Dealers::Simple.new(deck, [
|
14
|
+
subject { CardNine::Dealers::Simple.new(deck, { batcave: [] }) }
|
16
15
|
|
17
16
|
it { is_expected.to be_a CardNine::Dealers::Simple }
|
18
17
|
end
|
19
|
-
|
20
|
-
|
21
18
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,7 @@ RSpec.configure do |config|
|
|
16
16
|
|
17
17
|
config.filter_run :focus
|
18
18
|
config.run_all_when_everything_filtered = true
|
19
|
-
config.filter_run_excluding :
|
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.
|
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.6.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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
235
|
version: '0'
|
236
236
|
requirements: []
|
237
237
|
rubyforge_project:
|
238
|
-
rubygems_version: 2.4.
|
238
|
+
rubygems_version: 2.4.3
|
239
239
|
signing_key:
|
240
240
|
specification_version: 4
|
241
241
|
summary: Game Dev Toolbox. Cards
|