99_game 2.1.0 → 3.0.0.pre.84
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rspec +4 -0
- data/{LICENSE.md → LICENSE.txt} +1 -1
- data/bin/99_game +18 -17
- data/lib/99_game.rb +76 -43
- data/spec/lib/99_game_spec.rb +30 -6
- data/spec/spec_helper.rb +0 -1
- metadata +13 -47
- data/lib/card.rb +0 -18
- data/lib/hand.rb +0 -44
- data/spec/codeclimate.rb +0 -2
- data/spec/lib/deck_spec.rb +0 -9
- data/spec/lib/hand_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjAwMThmZGRlYzViNmMyOWZlYzI5MjE2NGZiYTE4ZThhOGFiNjhlNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2YzYmM0NDc2M2UxYzFmN2M2ZTVkNjU4ZTZiYzU3ODhmYTE3MjM5Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2Y3NjliMWRmNzM1MGExMDcxZDQxMGNiMjlhMWYzMGJmYjFmOTI2YTMwNjRh
|
10
|
+
NmE4ODQ2YWU4MTk5Yzg5YzM0OTg1YzVlYTI2MWU1YmZlM2Y2ZDk2NDgyYzQ0
|
11
|
+
ODgyYWJhYTIyMGNlNjEzYTcwMTYyZjNhZGJjZGY3MTA1MWRjMDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDVlYWUxNDdlY2E4MWJhODZiODJhNzA0NDE0NTE4YjcwNWVlODVkNzhjZGRh
|
14
|
+
OTExNjU1NTgxMGE2MDEwMTAxMzZkZmJjNjdkYjRmNzc2MDJhMDU3YmNmNTM1
|
15
|
+
ZTk0ZGY3ZDI4ZWMyMjJhNGZmNmIyN2U3YzU4OGU4ZDY1ZjcwMmE=
|
data/.rspec
ADDED
data/{LICENSE.md → LICENSE.txt}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) {{{2014}}} {{{Zachary Roth Perlmutter}}}
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/bin/99_game
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require '99_game'
|
3
3
|
include CardDeck
|
4
|
-
deck = Deck.new
|
4
|
+
deck = Deck.new true
|
5
5
|
BEGIN { # Looks at its arguements
|
6
6
|
ARGV[0] = "-h" if ARGV[0] == "--help"
|
7
7
|
ARGV[0] = "-v" if ARGV[0] == "--version"
|
8
8
|
case ARGV[0]
|
9
9
|
when "-v"
|
10
|
-
puts "
|
10
|
+
puts "2.0.1"
|
11
11
|
exit
|
12
12
|
when "-h"
|
13
13
|
puts "\u00B7 Commands"
|
@@ -32,15 +32,15 @@ BEGIN { # Looks at its arguements
|
|
32
32
|
end
|
33
33
|
}
|
34
34
|
END { # Thanks for playing
|
35
|
-
sleep
|
35
|
+
sleep(1.5)
|
36
36
|
puts "\n\tThanks for playing 99!"
|
37
|
-
sleep
|
37
|
+
sleep(2.5)
|
38
38
|
}
|
39
|
-
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
|
39
|
+
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new(deck), Hand.new(deck)
|
40
40
|
loop do
|
41
41
|
puts "\n\tIt is the dealer's turn!"
|
42
42
|
i = 1
|
43
|
-
for card in dealer.
|
43
|
+
for card in dealer.hand
|
44
44
|
case i
|
45
45
|
when 1 then test card, $value, value1
|
46
46
|
when 2 then test card, $value, value2
|
@@ -49,19 +49,20 @@ loop do
|
|
49
49
|
i += 1
|
50
50
|
end
|
51
51
|
if value1 >= value2 && value1 >= value3
|
52
|
-
$card = dealer.
|
53
|
-
dealer.play dealer.
|
54
|
-
elsif
|
55
|
-
$card = dealer.
|
56
|
-
dealer.play dealer.
|
52
|
+
$card = dealer.hand[0].num
|
53
|
+
dealer.play dealer.hand[0]
|
54
|
+
elsif value1 <= value2 && value2 >= value3
|
55
|
+
$card = dealer.hand[1].num
|
56
|
+
dealer.play dealer.hand[1]
|
57
57
|
else
|
58
|
-
$card = dealer.
|
59
|
-
dealer.play
|
58
|
+
$card = dealer.hand[2].num
|
59
|
+
dealer.play(dealer.hand[2])
|
60
60
|
end
|
61
|
-
pause
|
61
|
+
pause(1.5)
|
62
62
|
puts "\tThe dealer played a(n) #{$card}"
|
63
63
|
pause(0.5)
|
64
|
-
puts "\tThe value is now #{$value}
|
64
|
+
puts "\tThe value is now #{$value}"
|
65
|
+
puts
|
65
66
|
pause(1.5)
|
66
67
|
if $value > 99 # Runs when you win and exits loop
|
67
68
|
puts "\tYou win!"
|
@@ -73,9 +74,9 @@ loop do
|
|
73
74
|
pause 0.5
|
74
75
|
print "\tPick a card to play by typing in the name of the card => "
|
75
76
|
input, turn = gets.chomp, true
|
76
|
-
for card in user.
|
77
|
+
for card in user.hand
|
77
78
|
if card.num == converter(input) && turn
|
78
|
-
user.play
|
79
|
+
user.play(card)
|
79
80
|
turn = false
|
80
81
|
end
|
81
82
|
end
|
data/lib/99_game.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
autoload :Hand, "hand"
|
4
|
-
|
5
|
-
=begin
|
6
|
-
@param card [CardDeck::Card]
|
7
|
-
@param actual_value [Integer]
|
8
|
-
@param test_value [Integer]
|
9
|
-
@return [Integer]
|
10
|
-
@note Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
11
|
-
=end
|
1
|
+
require "card_deck"
|
2
|
+
# Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
12
3
|
def test(card, actual_value, test_value)
|
13
4
|
if card.num == "King"
|
14
5
|
test_value = 99
|
15
6
|
elsif card.num == "Joker"
|
16
7
|
test_value = 0
|
17
|
-
else
|
18
|
-
test_value = actual_value + card.value
|
8
|
+
else; test_value = actual_value + card.value
|
19
9
|
end
|
20
10
|
test_value = -100 if test_value > 99
|
21
11
|
return test_value
|
@@ -23,43 +13,86 @@ autoload :Hand, "hand"
|
|
23
13
|
# Tests if obj is not nil.
|
24
14
|
def not_nil?(obj)
|
25
15
|
if obj.nil?
|
26
|
-
false
|
16
|
+
return false
|
27
17
|
else
|
28
|
-
true
|
18
|
+
return true
|
29
19
|
end
|
30
20
|
end
|
31
21
|
# Converts input to an integer if String#capitalize does something. If parameter input is an abbreviation, _input_ is converted to what it stands for. Otherwise, it simply returns a capitalized version of _input_. If _input_ is nil or an emtpy string, raises a CardError
|
22
|
+
def converter(input)
|
23
|
+
abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"}
|
24
|
+
raise(CardError, "Input cannot be blank") if input == String.new
|
25
|
+
if input.to_i == 0
|
26
|
+
case input.capitalize
|
27
|
+
when "$" then "Joker"
|
28
|
+
when "K" then "King"
|
29
|
+
when "J" then "Jack"
|
30
|
+
when "Q" then "Queen"
|
31
|
+
when "A" then "Ace"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
input.to_i
|
35
|
+
end
|
36
|
+
end
|
32
37
|
# Expected errors
|
33
|
-
class CardError < Exception; end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
class CardError < Exception; end
|
39
|
+
class CardDeck::Card # Represents a card in the deck
|
40
|
+
# Backup method for Card#value
|
41
|
+
def value
|
42
|
+
return case @num
|
43
|
+
when "Ace" then 1
|
44
|
+
when 2..3 then @num
|
45
|
+
when 4 then 0
|
46
|
+
when 5..8 then @num
|
47
|
+
when 9 then 0
|
48
|
+
when 10 then 10
|
49
|
+
when "Jack" then 0
|
50
|
+
when "Queen" then -10
|
51
|
+
when "King" then 99
|
52
|
+
when "Joker" then 0
|
53
|
+
end
|
54
|
+
end
|
42
55
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
|
57
|
+
# The actual hand
|
58
|
+
attr_accessor :hand
|
59
|
+
# Creates a new Hand. The deck argument tells the object which deck to use in Hand#play
|
60
|
+
def initialize(deck_in_use)
|
61
|
+
@hand, @deck = [deck_in_use.draw, deck_in_use.draw, deck_in_use.draw], deck_in_use
|
62
|
+
end
|
63
|
+
# Gameplay method. The parameter 'card' is the card being played.
|
64
|
+
def play(card)
|
65
|
+
if card.num == "King"; $value = 99
|
66
|
+
elsif card.num == "Joker"; $value = 0
|
67
|
+
else; $value += card.value
|
68
|
+
end
|
69
|
+
i, done = 0, false
|
70
|
+
for index in @hand
|
71
|
+
if index.num == card.num and not done
|
72
|
+
discard = @hand[ i ]
|
73
|
+
@hand.delete_at i
|
74
|
+
@hand.push @deck.draw
|
75
|
+
@deck.discard discard
|
76
|
+
done = true
|
77
|
+
end
|
78
|
+
i += 1
|
79
|
+
end
|
60
80
|
end
|
61
|
-
|
62
|
-
|
81
|
+
# Allows you to see your cards.
|
82
|
+
def view
|
83
|
+
print "\tThese are your cards: "
|
84
|
+
@hand.each {|card| print "\t#{card.num}"}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
# Combines sleep and a newline. 'p' is the amount of time waited.
|
88
|
+
def pause(p)
|
89
|
+
sleep p
|
90
|
+
puts
|
63
91
|
end
|
92
|
+
class CardDeck::Deck # Cards are stored in these objects
|
93
|
+
# Draw from the deck
|
94
|
+
def draw; @cards.shift; end
|
95
|
+
# Adds 'card' to the deck. Used with Hand#play.
|
96
|
+
def discard(card); @cards.push card; end
|
64
97
|
end
|
65
98
|
|
data/spec/lib/99_game_spec.rb
CHANGED
@@ -1,12 +1,36 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
create_deck = proc {Deck.new true}
|
2
|
+
deck = create_deck.call
|
3
|
+
describe Deck do
|
4
|
+
describe create_deck.call.cards.length do
|
5
|
+
it {is_expected.to eq(54)}
|
6
|
+
end
|
7
|
+
end
|
3
8
|
describe "converter" do
|
4
9
|
context "when a number" do
|
5
|
-
|
6
|
-
|
10
|
+
it "should return the input as a number" do
|
11
|
+
expect(converter("5")).to eq 5
|
12
|
+
end
|
7
13
|
end
|
8
14
|
context "when an abbreveation" do
|
9
|
-
|
10
|
-
|
15
|
+
it "should expand it" do
|
16
|
+
expect(converter("K")).to eq "King"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe Hand do
|
21
|
+
hand = Hand.new create_deck.call
|
22
|
+
describe "#hand" do
|
23
|
+
describe "#length" do
|
24
|
+
subject { hand.hand.length }
|
25
|
+
it "should == 3" do; expect( subject ).to eq 3; end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
describe "#initialize" do
|
29
|
+
describe "Deck#length" do
|
30
|
+
it "should have three less cards after initialization" do
|
31
|
+
deck1, hand, deck2 = deck.cards.length, Hand.new( deck ), deck.cards.length
|
32
|
+
expect( deck1 ).to be > deck2
|
33
|
+
end
|
34
|
+
end
|
11
35
|
end
|
12
36
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,51 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 99_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.pre.84
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Zachary
|
7
|
+
- Zachary Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: card_deck
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '4.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.1'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec-its
|
14
|
+
name: card_deck>= 0.0.0
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
requirements:
|
45
17
|
- - ! '>='
|
46
18
|
- !ruby/object:Gem::Version
|
47
19
|
version: '0'
|
48
|
-
type: :
|
20
|
+
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
@@ -62,19 +34,15 @@ executables:
|
|
62
34
|
- 99_game
|
63
35
|
extensions: []
|
64
36
|
extra_rdoc_files:
|
65
|
-
- LICENSE.md
|
66
37
|
- README.md
|
38
|
+
- LICENSE.txt
|
67
39
|
files:
|
68
|
-
-
|
40
|
+
- .rspec
|
41
|
+
- LICENSE.txt
|
69
42
|
- README.md
|
70
43
|
- bin/99_game
|
71
44
|
- lib/99_game.rb
|
72
|
-
- lib/card.rb
|
73
|
-
- lib/hand.rb
|
74
|
-
- spec/codeclimate.rb
|
75
45
|
- spec/lib/99_game_spec.rb
|
76
|
-
- spec/lib/deck_spec.rb
|
77
|
-
- spec/lib/hand_spec.rb
|
78
46
|
- spec/spec_helper.rb
|
79
47
|
homepage: https://rubygems.org/gems/99_game
|
80
48
|
licenses:
|
@@ -88,21 +56,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
56
|
requirements:
|
89
57
|
- - ! '>='
|
90
58
|
- !ruby/object:Gem::Version
|
91
|
-
version: 1.9.
|
59
|
+
version: 1.9.3
|
92
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
61
|
requirements:
|
94
|
-
- - ! '
|
62
|
+
- - ! '>'
|
95
63
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
64
|
+
version: 1.3.1
|
97
65
|
requirements: []
|
98
66
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.4.
|
67
|
+
rubygems_version: 2.4.2
|
100
68
|
signing_key:
|
101
69
|
specification_version: 4
|
102
70
|
summary: The game of 99.
|
103
71
|
test_files:
|
104
|
-
- spec/codeclimate.rb
|
105
72
|
- spec/lib/99_game_spec.rb
|
106
|
-
-
|
107
|
-
- spec/lib/hand_spec.rb
|
73
|
+
- .rspec
|
108
74
|
- spec/spec_helper.rb
|
data/lib/card.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require "card_deck"
|
2
|
-
class CardDeck::Card # Represents a card in the deck
|
3
|
-
# Value of the card
|
4
|
-
def value
|
5
|
-
case @num
|
6
|
-
when "Ace" then 1
|
7
|
-
when 2..3 then @num
|
8
|
-
when 4 then 0
|
9
|
-
when 5..8 then @num
|
10
|
-
when 9 then 0
|
11
|
-
when 10 then 10
|
12
|
-
when "Jack" then 0
|
13
|
-
when "Queen" then -10
|
14
|
-
when "King" then 99
|
15
|
-
when "Joker" then 0
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/hand.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative "card.rb"
|
2
|
-
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
|
3
|
-
@@deck = Deck.new.cards.shuffle!
|
4
|
-
attr_accessor :cards # @return [Array<CardDeck::Card>]
|
5
|
-
def initialize
|
6
|
-
@cards = Array.new(3) {@@deck.shift}
|
7
|
-
end
|
8
|
-
|
9
|
-
=begin
|
10
|
-
@param card [CardDeck::Card] the card played
|
11
|
-
@return [void]
|
12
|
-
@note Gameplay method
|
13
|
-
=end
|
14
|
-
def play(card)
|
15
|
-
if card.num == "King"
|
16
|
-
$value = 99
|
17
|
-
elsif card.num == "Joker"
|
18
|
-
$value = 0
|
19
|
-
else
|
20
|
-
$value += card.value
|
21
|
-
end
|
22
|
-
i, done = 0, false
|
23
|
-
for index in @cards
|
24
|
-
if index.num == card.num and not done
|
25
|
-
discard = @cards[i]
|
26
|
-
@cards.delete_at i
|
27
|
-
@cards.push @@deck.shift
|
28
|
-
@@deck.push discard
|
29
|
-
done = true
|
30
|
-
end
|
31
|
-
i += 1
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
=begin
|
36
|
-
@return [void]
|
37
|
-
Displays cards
|
38
|
-
=end
|
39
|
-
def view
|
40
|
-
print "\tThese are your cards: "
|
41
|
-
@cards.each {|card| print "\t#{card.num}"}
|
42
|
-
end
|
43
|
-
alias inspect cards
|
44
|
-
end
|
data/spec/codeclimate.rb
DELETED
data/spec/lib/deck_spec.rb
DELETED
data/spec/lib/hand_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "hand"
|
3
|
-
describe "CPU" do
|
4
|
-
s = Hand.new
|
5
|
-
s.cards = [Card.new("King", Card::Spades), Card.new("Joker"), Card.new(2, Card::Diamonds)]
|
6
|
-
describe "test" do
|
7
|
-
tests = proc {|index| test(s.cards[index], 50, nil)}
|
8
|
-
v1 = tests.call 0
|
9
|
-
v2 = tests.call 1
|
10
|
-
v3 = tests.call 2
|
11
|
-
describe v1 do
|
12
|
-
it {is_expected.to be > v2}
|
13
|
-
it {is_expected.to be > v3}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
describe Hand do
|
18
|
-
describe "#new" do
|
19
|
-
describe "#cards" do
|
20
|
-
subject {Hand.new.cards}
|
21
|
-
describe "#length" do
|
22
|
-
subject {Hand.new.cards.length}
|
23
|
-
it {is_expected.to be 3}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|