cardshark 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cardshark.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,8 @@
1
+ CardShark
2
+
3
+ CardShark is a library for representing decks of cards.
4
+
5
+ Deck Types
6
+ - Uno
7
+ - French
8
+ - Canasta
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cardshark/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cardshark"
7
+ s.version = Cardshark::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["John Britton - @johndbritton"]
10
+ s.email = ["public@johndbritton.com"]
11
+ s.homepage = "http://www.johndbritton.com"
12
+ s.summary = %q{A library for various types of card decks}
13
+ s.description = %q{Supports Canasta, French, Piquet, and Uno Decks}
14
+
15
+ s.rubyforge_project = "cardshark"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Cardshark
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'cardshark/deck'
2
+ require 'cardshark/card'
3
+
4
+ module Cardshark
5
+ # Representation of the 108 Card deck used to play Canasta. Essentially it is two French Decks with the Jokers included.
6
+ class CanastaDeck
7
+ include Deck
8
+ RANKS = [:ace, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :jack, :queen, :king]
9
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
10
+ JOKERS = [:joker]
11
+ JOKER_SUITS = [:red, :black]
12
+
13
+ def initialize
14
+ @cards = Array.new()
15
+ 2.times do
16
+ @cards += create_cards(SUITS, RANKS)
17
+ @cards += create_cards(JOKER_SUITS, JOKERS)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Cardshark
2
+ class Card
3
+ attr_reader :rank, :suit
4
+ def initialize(card)
5
+ @rank = card[:rank]
6
+ @suit = card[:suit]
7
+ self.freeze
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ module Cardshark
2
+ module Deck
3
+ def size
4
+ @cards.size
5
+ end
6
+
7
+ def cards
8
+ @cards
9
+ end
10
+
11
+ def shuffle!
12
+ @cards.shuffle!
13
+ @shuffled = true
14
+ end
15
+
16
+ def shuffled?
17
+ return false unless @shuffled
18
+ true
19
+ end
20
+
21
+ # Helper method that builds cards
22
+ def create_cards(suits, ranks)
23
+ created_cards = Array.new
24
+ suits.each do |suit|
25
+ ranks.each do |rank|
26
+ created_cards.push Card.new(:rank => rank, :suit => suit)
27
+ end
28
+ end
29
+ created_cards
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ require 'cardshark/deck'
2
+ require 'cardshark/card'
3
+
4
+ module Cardshark
5
+ class FrenchDeck
6
+ include Deck
7
+ RANKS = [:ace, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :jack, :queen, :king]
8
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
9
+ JOKERS = [:joker]
10
+ JOKER_SUITS = [:red, :black]
11
+
12
+ def initialize(opts={:include_jokers => false})
13
+ @cards = Array.new()
14
+ @cards += create_cards(SUITS, RANKS)
15
+ if opts[:include_jokers] then
16
+ @cards += create_cards(JOKER_SUITS, JOKERS)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'cardshark/deck'
2
+ require 'cardshark/card'
3
+
4
+ module Cardshark
5
+ # Representation of the 32 Card deck used to play Piquet. http://en.wikipedia.org/wiki/Playing_card#Piquet
6
+ class PiquetDeck
7
+ include Deck
8
+ RANKS = [:ace, :seven, :eight, :nine, :ten, :jack, :queen, :king]
9
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
10
+
11
+ def initialize
12
+ @cards = Array.new()
13
+ @cards += create_cards(SUITS, RANKS)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'cardshark/deck'
2
+ require 'cardshark/card'
3
+
4
+ module Cardshark
5
+ class UnoDeck
6
+ include Deck
7
+ RANKS = [:one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :skip, :draw_two, :reverse]
8
+ ZERO = [:zero]
9
+ SUITS = [:red, :green, :blue, :yellow]
10
+ SPECIALS = [ :wild, :wild_draw_four]
11
+ SPECIAL_SUITS = [:black]
12
+
13
+ def initialize()
14
+ @cards = Array.new()
15
+ 2.times { @cards += create_cards(SUITS, RANKS) }
16
+ @cards += create_cards(SUITS, ZERO)
17
+ 4.times { @cards += create_cards(SPECIAL_SUITS, SPECIALS)}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Cardshark
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'cardshark/canasta_deck'
2
+
3
+ describe Cardshark::CanastaDeck do
4
+ #create a canasta deck
5
+ before :all do
6
+ @canasta = Cardshark::CanastaDeck.new
7
+ end
8
+
9
+ it 'should contain 108 cards' do
10
+ @canasta.size.should == 108
11
+ end
12
+
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'cardshark/card'
2
+
3
+ describe Cardshark::Card do
4
+ before :all do
5
+ @card = Cardshark::Card.new(:rank => :K, :suit => :H)
6
+ end
7
+
8
+ it 'has a rank' do
9
+ @card.rank.should == :K
10
+ end
11
+
12
+ it 'has a suit' do
13
+ @card.suit.should == :H
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require 'cardshark/deck'
2
+
3
+ describe Cardshark::Deck do
4
+ #define a simple deck for testing basic functionality of the module
5
+ module Cardshark
6
+ class SimpleDeck
7
+ include Deck
8
+ def initialize
9
+ @cards = Array.new
10
+ for i in 1..10 do
11
+ @cards.push Card.new(:rank => i, :suit => :anything)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ before :each do
18
+ @simple = Cardshark::SimpleDeck.new
19
+ end
20
+
21
+ it 'should contain 10 cards' do
22
+ @simple.size.should == 10
23
+ end
24
+
25
+ it 'should not be shuffled' do
26
+ @simple.shuffled?.should == false
27
+ end
28
+
29
+ it 'should be in order' do
30
+ for i in 0..9 do
31
+ @simple.cards[i].rank.should == i+1
32
+ end
33
+ end
34
+
35
+ it 'should be shuffled' do
36
+ @simple.shuffle!
37
+ @simple.shuffled?.should == true
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ require 'cardshark/french_deck'
2
+
3
+ describe Cardshark::FrenchDeck do
4
+ #create a french (standard) deck
5
+ before :all do
6
+ @french = Cardshark::FrenchDeck.new
7
+ @french_with_jokers = Cardshark::FrenchDeck.new(:include_jokers => true)
8
+ end
9
+
10
+ it 'should contain 52 cards' do
11
+ @french.size.should == 52
12
+ end
13
+
14
+ it 'should contain 54 cards' do
15
+ @french_with_jokers.size == 54
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'cardshark/piquet_deck'
2
+
3
+ describe Cardshark::PiquetDeck do
4
+ #create a piquet deck
5
+ before :all do
6
+ @piquet = Cardshark::PiquetDeck.new
7
+ end
8
+
9
+ it 'should contain 32 cards' do
10
+ @piquet.size.should == 32
11
+ end
12
+
13
+ end
@@ -0,0 +1,47 @@
1
+ require 'cardshark/uno_deck'
2
+
3
+ describe Cardshark::UnoDeck do
4
+ #create a uno deck
5
+ before :all do
6
+ @uno = Cardshark::UnoDeck.new
7
+ end
8
+
9
+ it 'should contain 108 cards' do
10
+ @uno.size.should == 108
11
+ end
12
+
13
+ it 'should contain one zero in each suit' do
14
+ zeros = Hash.new
15
+ Cardshark::UnoDeck::SUITS.each do |suit|
16
+ zeros[suit] = 0
17
+ end
18
+ @uno.cards.each do |card|
19
+ if card.rank == :zero then
20
+ zeros[card.suit] += 1
21
+ end
22
+ end
23
+ Cardshark::UnoDeck::SUITS.each do |suit|
24
+ zeros[suit].should == 1
25
+ end
26
+ end
27
+
28
+ it 'should contain two of each rank other than zero in each suit' do
29
+ cards = Hash.new
30
+ Cardshark::UnoDeck::RANKS.each do |rank|
31
+ cards[rank] = Hash.new
32
+ Cardshark::UnoDeck::SUITS.each do |suit|
33
+ cards[rank][suit] = 0
34
+ end
35
+ end
36
+ @uno.cards.each do |card|
37
+ if Cardshark::UnoDeck::RANKS.include?(card.rank)
38
+ cards[card.rank][card.suit] += 1
39
+ end
40
+ end
41
+ Cardshark::UnoDeck::RANKS.each do |rank|
42
+ Cardshark::UnoDeck::SUITS.each do |suit|
43
+ cards[rank][suit].should == 2 unless rank == :zero
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cardshark
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Britton - @johndbritton
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 62196431
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ - beta
34
+ - 22
35
+ version: 2.0.0.beta.22
36
+ type: :development
37
+ version_requirements: *id001
38
+ description: Supports Canasta, French, Piquet, and Uno Decks
39
+ email:
40
+ - public@johndbritton.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - README
51
+ - Rakefile
52
+ - cardshark.gemspec
53
+ - lib/cardshark.rb
54
+ - lib/cardshark/canasta_deck.rb
55
+ - lib/cardshark/card.rb
56
+ - lib/cardshark/deck.rb
57
+ - lib/cardshark/french_deck.rb
58
+ - lib/cardshark/piquet_deck.rb
59
+ - lib/cardshark/uno_deck.rb
60
+ - lib/cardshark/version.rb
61
+ - spec/canasta_deck_spec.rb
62
+ - spec/card_spec.rb
63
+ - spec/deck_spec.rb
64
+ - spec/french_deck_spec.rb
65
+ - spec/piquet_deck_spec.rb
66
+ - spec/uno_deck_spec.rb
67
+ homepage: http://www.johndbritton.com
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project: cardshark
96
+ rubygems_version: 1.7.2
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A library for various types of card decks
100
+ test_files:
101
+ - spec/canasta_deck_spec.rb
102
+ - spec/card_spec.rb
103
+ - spec/deck_spec.rb
104
+ - spec/french_deck_spec.rb
105
+ - spec/piquet_deck_spec.rb
106
+ - spec/uno_deck_spec.rb