blackjack1 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (8) hide show
  1. checksums.yaml +13 -5
  2. data/LICENSE +22 -22
  3. data/README.md +5 -4
  4. data/bin/blackjack1 +61 -63
  5. data/lib/blackjack1.rb +16 -16
  6. data/lib/card.rb +13 -13
  7. data/lib/hand.rb +32 -32
  8. metadata +11 -12
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7c1d779dcde71a700696d492427e1ceb1f965532
4
- data.tar.gz: 8bdc62c837233802283a0a81138f259eed31f1b0
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWNmZTU5YzM4YmM5MWI3MWExMWZjM2ZiYTRlMWU1ODYzOTI5YTc5Yw==
5
+ data.tar.gz: !binary |-
6
+ ZGZkY2IzZGUwZTRjNWU5NzJiYjk2ZTU3MmExYmU3MjQ2YmVlMzgzYw==
5
7
  SHA512:
6
- metadata.gz: ed6fcaf5144f2f250c839f3b75075d37d31a6c8714f1b50fc7ae34012f57b4b141f659956438ab48cb001ab8cf0c96dec450eac31366c0008db8e815de520e0b
7
- data.tar.gz: 1ba0fa906ba408565137d52c7348082a223d484037813c13e432e6ab25c910f7f1c75d45f8c49a9d9e041dde5595fa099b89f3e80b0c16000029c330ca003712
8
+ metadata.gz: !binary |-
9
+ MzcxYjdhNjIzMGQ0YWY0MmNmMjE0YTc3NjE1MTcwNTgxMzM0OGI0N2MwMWE4
10
+ OTdkYTYyZGM2MTBlZjQ4ZDNjOWFhZDMyZjE4OTc3MDZmMmUxZTU5MjcwM2Zi
11
+ ODdjN2Q3MDM4MzMwNmU2N2I1YTAyYzg5ZjQxMWIwZWM2YjI3NTQ=
12
+ data.tar.gz: !binary |-
13
+ NTY1NDM1ZjdjMDc5YWVjN2I3MTE4MTkzZWVjOGE3MGM4MDNmMGQwMTFlZDYy
14
+ M2IzMDQ1MTQ3ZTExODU2MzhiYmRlZWI3ODY5NmJmYzY5ODkxZTk3MjQ2ZWNl
15
+ MGQzYWUyNDQxZDlkY2YzZTQ4Yjg2ZGY3ZmRlMjMyNzM4YjVhMWM=
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Zachary Perlmutter
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Zachary Perlmutter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # blackjack
2
- ## Badges
3
- [![Build Status](https://travis-ci.org/Zrp200/blackjack1.svg?branch=master)](https://travis-ci.org/Zrp200/blackjack1)
4
- [![Code Climate](https://codeclimate.com/github/Zrp200/blackjack1/badges/gpa.svg)](https://codeclimate.com/github/Zrp200/blackjack1)
1
+ # blackjack
2
+ The commonly played card game in casinos and for fun.
3
+ ## Badges
4
+ [![Build Status](https://travis-ci.org/Zrp200/blackjack1.svg?branch=master)](https://travis-ci.org/Zrp200/blackjack1)
5
+ [![Code Climate](https://codeclimate.com/github/Zrp200/blackjack1/badges/gpa.svg)](https://codeclimate.com/github/Zrp200/blackjack1)
data/bin/blackjack1 CHANGED
@@ -1,63 +1,61 @@
1
- #!/usr/bin/env ruby
2
- require "blackjack1"
3
- Hand.deck = CardDeck::Deck.new
4
- dealer, player, view = Hand.new, Hand.new, proc do |player|
5
- puts "You have: #{player.view}"
6
- sleep(0.5)
7
- puts "Value: #{player.value}"
8
- sleep(1)
9
- end
10
- view.call player
11
- unless player.blackjack?
12
- puts "The dealer is showing #{dealer.cards[1].abbr}\n"
13
- sleep 1
14
- print "Hit or stay? "
15
- action = gets.chomp.downcase
16
- f = true if action == "hit"
17
- while action == "hit" and !player.bust?
18
- unless f
19
- puts
20
- print "Hit or stay? "
21
- action == gets.chomp.downcase
22
- break unless action == "hit"
23
- else
24
- f = false
25
- end
26
- sleep(1)
27
- player.hit
28
- print view.call(player)
29
- sleep(1.5)
30
- end
31
- puts ""
32
- unless player.bust?
33
- puts "You finished with #{player.value}."
34
- else
35
- puts "You busted."
36
- end
37
- sleep 2
38
- if dealer.blackjack?
39
- puts "Dealer got blackjack."
40
- sleep 0.5
41
- puts "Dealer wins."
42
- sleep 2
43
- exit
44
- end
45
- puts
46
- while dealer.value <= Hand::MDHV
47
- puts "The dealer hit!"
48
- dealer.hit
49
- sleep 0.5
50
- end
51
- puts
52
- if dealer.bust? then puts "The dealer busted!"
53
- else
54
- puts "The dealer stays at #{dealer.value}"
55
- end
56
- sleep 2
57
- puts compare_score player, dealer
58
- else
59
- puts "You got blackjack!"
60
- sleep 1
61
- puts "You win!"
62
- sleep 0.5
63
- end
1
+ #!/usr/bin/env ruby
2
+ require "blackjack1"
3
+ Hand.deck, :inputerror = CardDeck::Deck.new, "Invalid input. Please input '(h)it' or '(s)tay'"
4
+ dealer, player, view = Hand.new, Hand.new, proc do |player|
5
+ puts "You have: #{player.view}"
6
+ sleep(0.5)
7
+ puts "Value: #{player.value}"
8
+ sleep 1
9
+ end
10
+ view.call player
11
+ unless player.blackjack?
12
+ puts "The dealer is showing #{dealer.cards[1].abbr}\n"
13
+ sleep 1
14
+ loop do
15
+ puts
16
+ catch :inputerror do
17
+ print "(h)it or (s)tay? "
18
+ action = gets.chomp.downcase
19
+ if action.include?("s") then break
20
+ elsif !action.include?("h") then throw :inputerror
21
+ end
22
+ end
23
+ sleep(1)
24
+ player.hit
25
+ print view.call player
26
+ sleep(1.5)
27
+ break if player.value == 21
28
+ end
29
+ puts ""
30
+ unless player.bust?
31
+ puts "You finished with #{player.value}."
32
+ else
33
+ puts "You busted."
34
+ end
35
+ sleep 2
36
+ if dealer.blackjack?
37
+ puts "Dealer got blackjack."
38
+ sleep 0.5
39
+ puts "Dealer wins."
40
+ sleep 2
41
+ exit
42
+ end
43
+ puts
44
+ while dealer.value <= Hand::MDHV
45
+ puts "The dealer hit!"
46
+ dealer.hit
47
+ sleep 0.5
48
+ end
49
+ puts
50
+ if dealer.bust? then puts "The dealer busted!"
51
+ else
52
+ puts "The dealer stays at #{dealer.value}"
53
+ end
54
+ sleep 2
55
+ puts compare_score player, dealer
56
+ else
57
+ puts "You got blackjack!"
58
+ sleep 1
59
+ puts "You win!"
60
+ sleep 0.5
61
+ end
data/lib/blackjack1.rb CHANGED
@@ -1,16 +1,16 @@
1
- require_relative "hand.rb"
2
- def compare_score(p1, p2, args=Hash.new(false)) # Determines who wins. parameter p1 is the player and parameter p2 is the dealer.
3
- unless args[:compare]
4
- win, lose, tie = "You win!", "Dealer wins.", "Tie"
5
- else
6
- win, lose, tie = true, false, nil
7
- end
8
- if p1.bust? and p2.bust? then return tie
9
- elsif p2.bust? then return win
10
- elsif p1.bust? then return lose
11
- elsif p1.value > p2.value then return win
12
- elsif p2.value > p1.value then return lose
13
- else
14
- return tie
15
- end
16
- end
1
+ require_relative "hand.rb"
2
+ def compare_score(p1, p2, args=Hash.new(false)) # Determines who wins. parameter p1 is the player and parameter p2 is the dealer.
3
+ unless args[:compare]
4
+ win, lose, tie = "You win!", "Dealer wins.", "Tie"
5
+ else
6
+ win, lose, tie = true, false, nil
7
+ end
8
+ if p1.bust? and p2.bust? then return tie
9
+ elsif p2.bust? then return win
10
+ elsif p1.bust? then return lose
11
+ elsif p1.value > p2.value then return win
12
+ elsif p2.value > p1.value then return lose
13
+ else
14
+ return tie
15
+ end
16
+ end
data/lib/card.rb CHANGED
@@ -1,13 +1,13 @@
1
- require "card_deck"
2
- class CardDeck::Card
3
- def value # The points a card is worth
4
- case num
5
- when 2..10 then num.to_i
6
- when "Ace" then 11
7
- when "Jack" then 10
8
- when "Queen" then 10
9
- when "King" then 10
10
- end
11
- end
12
- end
13
-
1
+ require "card_deck"
2
+ class CardDeck::Card
3
+ def value # The points a card is worth
4
+ case num
5
+ when 2..10 then num.to_i
6
+ when "Ace" then 11
7
+ when "Jack" then 10
8
+ when "Queen" then 10
9
+ when "King" then 10
10
+ end
11
+ end
12
+ end
13
+
data/lib/hand.rb CHANGED
@@ -1,32 +1,32 @@
1
- require_relative "card.rb" rescue require "card_deck"
2
- class Hand # The player
3
- attr_accessor :cards # The cards in the hand
4
- MDHV = 16 # Maximum Dealer Hit Value; If the dealer's hand is valued more than this number, he will stay.
5
- def self.deck=(deck) # Set which deck the game is using. Also shuffles the deck.
6
- @@deck = deck.cards.shuffle
7
- end
8
- def self.deck # The deck the game is using
9
- @@deck
10
- end
11
- def bust?; value > 21; end # Returns true if the value is greater than 21.
12
- def blackjack?; value == 21 && @cards.length == 2; end # Returns true if you have blackjack.
13
- def initialize(cards=[@@deck.shift, @@deck.shift])
14
- @cards = cards
15
- end
16
- def view # The view of the cards
17
- @cards.each {|card| "#{card.abbr}\t"}
18
- end
19
- def hit; @cards.push @@deck.shift; end # Add a card to @cards from @@deck
20
- def value # The value of the cards in @cards
21
- v, aces = 0, 0
22
- for card in @cards
23
- v += card.value
24
- aces += 1 if card.num == "Ace"
25
- end
26
- while v > 21 && aces > 0
27
- v -= 10
28
- aces -= 1
29
- end
30
- return v
31
- end
32
- end
1
+ require_relative "card.rb" rescue require "card_deck"
2
+ class Hand # The player
3
+ attr_accessor :cards # The cards in the hand
4
+ MDHV = 16 # Maximum Dealer Hit Value; If the dealer's hand is valued more than this number, he will stay.
5
+ def self.deck=(deck) # Set which deck the game is using. Also shuffles the deck.
6
+ @@deck = deck.cards.shuffle
7
+ end
8
+ def self.deck # The deck the game is using
9
+ @@deck
10
+ end
11
+ def bust?; value > 21; end # Returns true if the value is greater than 21.
12
+ def blackjack?; value == 21 && @cards.length == 2; end # Returns true if you have blackjack.
13
+ def initialize(cards=[@@deck.shift, @@deck.shift])
14
+ @cards = cards
15
+ end
16
+ def view # The view of the cards
17
+ @cards.each {|card| "#{card.abbr}\t"}
18
+ end
19
+ def hit; @cards.push @@deck.shift; end # Add a card to @cards from @@deck
20
+ def value # The value of the cards in @cards
21
+ v, aces = 0, 0
22
+ for card in @cards
23
+ v += card.value
24
+ aces += 1 if card.num == "Ace"
25
+ end
26
+ while v > 21 && aces > 0
27
+ v -= 10
28
+ aces -= 1
29
+ end
30
+ return v
31
+ end
32
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackjack1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-08 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: card_deck
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-its
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description:
@@ -77,12 +77,12 @@ require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.9.2
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ">="
85
+ - - ! '>='
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements:
@@ -91,6 +91,5 @@ rubyforge_project:
91
91
  rubygems_version: 2.4.2
92
92
  signing_key:
93
93
  specification_version: 4
94
- summary: The classic game of blackjack
94
+ summary: The classic game of blackjack, commonly played in casinos
95
95
  test_files: []
96
- has_rdoc: