99_game 1.3.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/README.md +9 -6
- data/bin/99_game +21 -28
- data/lib/99_game.rb +125 -90
- data/spec/{99spec.rb → lib/99_game.rb} +14 -14
- data/spec/spec_helper.rb +2 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79c3b36f954a1926f4e319e3584ce62d397af750
|
4
|
+
data.tar.gz: 23d12f11a841e502c980cb64750c66ab5790d439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d563dec8728ab21af85908c7cea2520375ce326b4b9c410d21133781f0d8552f9b4fedf40177c264994eea75603ef7d49b9c2727d8fabf87e0bb20652a7a0966
|
7
|
+
data.tar.gz: d381e887c98a7825e64526ae42578057ea55e06b3b7a5d08ca4854fb73f4c0c7c7cce93b1648f284547f1b1d3085cffb529aa599dfa8f0d6b6e1a1da72313ed4
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
|
2
|
+
# 99_game
|
3
|
+
|
4
|
+
To install: `gem install 99_game`
|
5
|
+
|
6
|
+
For the rules and arguments: `99_game -h`
|
7
|
+
|
8
|
+
## Badges
|
1
9
|
[](http://badge.fury.io/rb/99_game)
|
2
10
|
[](https://coveralls.io/r/Zrp200/99_game)
|
3
11
|
[](https://codeclimate.com/github/Zrp200/99_game)
|
4
12
|
[](https://gemnasium.com/Zrp200/99_game)
|
5
13
|
[](http://inch-ci.org/github/Zrp200/99_game)
|
6
|
-
99_game
|
7
|
-
=======
|
8
|
-
|
9
|
-
To install: `gem install 99_game`
|
10
|
-
|
11
|
-
For the rules and arguments: `gem '99_game'`
|
14
|
+
[](https://codeclimate.com/github/Zrp200/99_game)
|
data/bin/99_game
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require '99_game'
|
3
|
+
deck = Deck.new
|
3
4
|
BEGIN { # Looks at its arguements
|
4
5
|
ARGV[0] = "-h" if ARGV[0] == "--help"
|
5
6
|
ARGV[0] = "-v" if ARGV[0] == "--version"
|
6
|
-
|
7
|
-
|
8
|
-
puts "
|
7
|
+
case ARGV[0]
|
8
|
+
when "-v"
|
9
|
+
puts "2.0.0"
|
9
10
|
exit
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
when "-h"
|
12
|
+
puts "\u00B7 Commands"
|
13
|
+
puts "\t\u00b7 -v/--version - display version"
|
14
|
+
puts "\t\u00B7 -h/--help - shows this message\n"
|
15
|
+
puts "\u00B7 Abbrevations"
|
16
|
+
puts "\t\u00B7 J -> Jack"
|
17
|
+
puts "\t\u00b7 Q -> Queen"
|
18
|
+
puts "\t\u00b7 K -> King"
|
19
|
+
puts "\t\u00b7 A -> Ace"
|
20
|
+
puts "\t\u00b7 $ -> Joker"
|
20
21
|
puts "\u00B7 Gameplay"
|
21
22
|
puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
|
22
23
|
puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
|
@@ -34,35 +35,27 @@ END { # Thanks for playing
|
|
34
35
|
puts "\n\tThanks for playing 99!"
|
35
36
|
sleep(3)
|
36
37
|
}
|
37
|
-
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
|
38
|
+
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new(deck), Hand.new(deck)
|
38
39
|
loop do
|
39
|
-
$deck.shuffle!
|
40
40
|
puts
|
41
41
|
puts "\tIt is the dealer's turn!"
|
42
|
-
def test(card, value) # argument 'card' needs to be an instance of Card
|
43
|
-
if card.num == "King"; value = 99
|
44
|
-
elsif card.num == "Joker"; value = -1
|
45
|
-
else; value = $value + card.value
|
46
|
-
end
|
47
|
-
value = -100 if value > 99
|
48
|
-
end
|
49
42
|
i = 1
|
50
43
|
for card in dealer.hand
|
51
44
|
case i
|
52
|
-
when 1 then test
|
53
|
-
when 2 then test
|
54
|
-
when 3 then test
|
45
|
+
when 1 then test card, $value, value1
|
46
|
+
when 2 then test card, $value, value2
|
47
|
+
when 3 then test card, $value, value3
|
55
48
|
end
|
56
49
|
i += 1
|
57
50
|
end
|
58
51
|
if value1 >= value2 and value1 >= value3
|
59
|
-
|
52
|
+
$card = dealer.hand[0].num
|
60
53
|
dealer.play(dealer.hand[0])
|
61
54
|
elsif value2 >= value3
|
62
|
-
|
55
|
+
$card = dealer.hand[1].num
|
63
56
|
dealer.play(dealer.hand[1])
|
64
57
|
else
|
65
|
-
|
58
|
+
$card = dealer.hand[2].num
|
66
59
|
dealer.play(dealer.hand[2])
|
67
60
|
end
|
68
61
|
pause(2)
|
data/lib/99_game.rb
CHANGED
@@ -1,101 +1,136 @@
|
|
1
|
+
# Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
2
|
+
def test(card, actual_value, test_value)
|
3
|
+
if card.num == "King"
|
4
|
+
test_value = 99
|
5
|
+
elsif card.num == "Joker"
|
6
|
+
test_value = 0
|
7
|
+
else; test_value = actual_value + card.value
|
8
|
+
end
|
9
|
+
test_value = -100 if test_value > 99
|
10
|
+
end
|
1
11
|
# Tests if obj is not nil.
|
2
|
-
def not_nil?(obj)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
12
|
+
def not_nil?(obj)
|
13
|
+
if obj.nil?
|
14
|
+
return false
|
15
|
+
else
|
16
|
+
return true
|
17
|
+
end
|
7
18
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
# 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
|
20
|
+
def converter(input)
|
21
|
+
abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"}
|
22
|
+
raise(CardError, "Input cannot be blank") if input == String.new
|
23
|
+
if input.to_i == 0
|
24
|
+
case input.capitalize
|
25
|
+
when "$" then "Joker"
|
26
|
+
when "K" then "King"
|
27
|
+
when "J" then "Jack"
|
28
|
+
when "Q" then "Queen"
|
29
|
+
when "A" then "Ace"
|
30
|
+
end
|
31
|
+
else
|
32
|
+
input.to_i
|
33
|
+
end
|
20
34
|
end
|
21
|
-
|
22
|
-
class CardError < Exception; end
|
35
|
+
# Expected errors
|
36
|
+
class CardError < Exception; end
|
23
37
|
class Card # Represents a card in the deck
|
24
|
-
|
25
|
-
|
26
|
-
# Gives the Card's value
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# Gives the number on the card
|
39
|
+
attr_reader :num
|
40
|
+
# Gives the Card's value
|
41
|
+
attr_reader :value
|
42
|
+
# Backup method for Card#value
|
43
|
+
def _value
|
44
|
+
return case @num
|
45
|
+
when "Ace" then 1
|
46
|
+
when 2..3 then @num
|
47
|
+
when 4 then 0
|
48
|
+
when 5..8 then @num
|
49
|
+
when 9 then 0
|
50
|
+
when 10 then 10
|
51
|
+
when "Jack" then 0
|
52
|
+
when "Queen" then -10
|
53
|
+
when "King" then 99
|
54
|
+
when "Joker" then 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
# Creates a new card with num as the attribute :num
|
58
|
+
def initialize(num)
|
59
|
+
@num, @value = num, case num
|
60
|
+
when "Ace" then 1
|
61
|
+
when 4 then 0
|
62
|
+
when 9 then 0
|
63
|
+
when "Jack" then 0
|
64
|
+
when "Joker" then 0
|
65
|
+
when "King" then 99
|
66
|
+
when "Queen" then -10
|
67
|
+
else
|
68
|
+
num.to_i
|
69
|
+
end
|
44
70
|
end
|
45
|
-
end
|
46
|
-
# Creates a new card
|
47
|
-
def initialize(card); @num = card; end
|
48
71
|
end
|
49
|
-
class Hand # Creates an object that holds and can play cards
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if card.num == "King"; $value = 99
|
56
|
-
elsif card.num == "Joker"; $value = 0
|
57
|
-
else; $value += card.value
|
72
|
+
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
|
73
|
+
# The actual hand
|
74
|
+
attr_reader :hand
|
75
|
+
# Creates a new Hand. The deck argument tells the object which deck to use in Hand#play
|
76
|
+
def initialize(deck_in_use)
|
77
|
+
@hand, @deck = [deck_in_use.draw, deck_in_use.draw, deck_in_use.draw], deck_in_use
|
58
78
|
end
|
59
|
-
|
60
|
-
|
61
|
-
if
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
# Gameplay method. The parameter 'card' is the card being played.
|
80
|
+
def play(card)
|
81
|
+
if card.num == "King"; $value = 99
|
82
|
+
elsif card.num == "Joker"; $value = 0
|
83
|
+
else; $value += card.value
|
84
|
+
end
|
85
|
+
i, done = 0, false
|
86
|
+
for index in @hand
|
87
|
+
if index.num == card.num and not done
|
88
|
+
discard = @hand[ i ]
|
89
|
+
@hand.delete_at i
|
90
|
+
@hand.push @deck.draw
|
91
|
+
@deck.discard discard
|
92
|
+
done = true
|
93
|
+
end
|
94
|
+
i += 1
|
68
95
|
end
|
69
|
-
i += 1
|
70
96
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
97
|
+
# Allows you to see your cards.
|
98
|
+
def view
|
99
|
+
print "\tThese are your cards: "
|
100
|
+
@hand.each {|card| print "\t#{card.num}"}
|
101
|
+
end
|
77
102
|
end
|
78
|
-
# Combines sleep and a newline.
|
79
|
-
def pause(p)
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
103
|
+
# Combines sleep and a newline. 'p' is the amount of time waited.
|
104
|
+
def pause(p)
|
105
|
+
sleep p
|
106
|
+
puts
|
107
|
+
end
|
108
|
+
class Deck # Cards are stored in these objects
|
109
|
+
# The contents of the deck
|
110
|
+
attr_reader :cards
|
111
|
+
def initialize # Creates a new deck that can now be used for playing the game
|
112
|
+
@cards = Array.new
|
113
|
+
4.times do # Add the cards to the deck
|
114
|
+
@cards.push Card.new("Ace")
|
115
|
+
@cards.push Card.new("King")
|
116
|
+
@cards.push Card.new("Queen")
|
117
|
+
@cards.push Card.new("Jack")
|
118
|
+
@cards.push Card.new(10)
|
119
|
+
@cards.push Card.new(9)
|
120
|
+
@cards.push Card.new(8)
|
121
|
+
@cards.push Card.new(7)
|
122
|
+
@cards.push Card.new(6)
|
123
|
+
@cards.push Card.new(5)
|
124
|
+
@cards.push Card.new(4)
|
125
|
+
@cards.push Card.new(3)
|
126
|
+
@cards.push Card.new(2)
|
127
|
+
end
|
128
|
+
2.times {@cards.push Card.new("Joker")}
|
129
|
+
50.times {@cards.shuffle!}
|
130
|
+
end
|
131
|
+
# Draw from the deck
|
132
|
+
def draw; @cards.shift; end
|
133
|
+
# Adds 'card' to the deck. Used with Hand#play.
|
134
|
+
def discard(card); @cards.push card; end
|
98
135
|
end
|
99
|
-
|
100
|
-
$deck.shuffle!
|
101
|
-
__END__
|
136
|
+
|
@@ -1,11 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
deck = Deck.new
|
2
|
+
describe Deck do
|
3
|
+
subject {Deck.new}
|
4
4
|
describe "#length" do
|
5
|
-
it "should == 54" do; expect(
|
5
|
+
it "should == 54" do; expect(subject.cards.length).to eq 54; end
|
6
6
|
end
|
7
7
|
end
|
8
|
-
describe
|
8
|
+
describe Card do
|
9
9
|
cards = ["Ace", "King", "Queen", "Jack", "Joker"] + (2..10).to_a
|
10
10
|
describe "#value" do
|
11
11
|
for card in cards
|
@@ -20,29 +20,29 @@ end
|
|
20
20
|
describe "converter" do
|
21
21
|
context "when a number" do
|
22
22
|
it "should return the input as a number" do
|
23
|
-
expect(converter("5")).to eq
|
23
|
+
expect(converter("5")).to eq 5
|
24
24
|
end
|
25
25
|
end
|
26
26
|
context "when an abbreveation" do
|
27
27
|
it "should expand it" do
|
28
|
-
expect(converter("
|
28
|
+
expect(converter("K")).to eq "King"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
describe
|
33
|
-
hand = Hand.new
|
32
|
+
describe Hand do
|
33
|
+
hand = Hand.new Deck.new
|
34
34
|
describe "#hand" do
|
35
35
|
describe "#length" do
|
36
|
-
|
36
|
+
subject { hand.hand.length }
|
37
|
+
it "should == 3" do; expect( subject ).to eq 3; end
|
37
38
|
end
|
38
39
|
end
|
39
40
|
describe "#initialize" do
|
40
|
-
describe "
|
41
|
+
describe "Deck#length" do
|
41
42
|
it "should have three less cards after initialization" do
|
42
|
-
deck1, hand, deck2 =
|
43
|
-
expect(deck1).to > deck2
|
43
|
+
deck1, hand, deck2 = deck.cards.length, Hand.new( deck ), deck.cards.length
|
44
|
+
expect( deck1 ).to be > deck2
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
48
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
CodeClimate::TestReporter.start
|
1
|
+
require "99_game"
|
3
2
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
3
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
4
|
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
@@ -14,7 +13,7 @@ CodeClimate::TestReporter.start
|
|
14
13
|
#
|
15
14
|
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
15
|
# users commonly want.
|
17
|
-
|
16
|
+
require_relative "lib/99_game.rb"
|
18
17
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
18
|
RSpec.configure do |config|
|
20
19
|
# The settings below are suggested to provide a good initial experience
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 99_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
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
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
This is a text-based interpretation of the card game 99. Comes with the gem in the form of an executable. Make sure to read the rules in `99_game -h` before playing
|
@@ -25,7 +25,7 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- bin/99_game
|
27
27
|
- lib/99_game.rb
|
28
|
-
- spec/
|
28
|
+
- spec/lib/99_game.rb
|
29
29
|
- spec/spec_helper.rb
|
30
30
|
homepage: https://rubygems.org/gems/99_game
|
31
31
|
licenses:
|
@@ -40,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: '0'
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -53,6 +53,7 @@ signing_key:
|
|
53
53
|
specification_version: 4
|
54
54
|
summary: The game of 99.
|
55
55
|
test_files:
|
56
|
-
- spec/
|
56
|
+
- spec/lib/99_game.rb
|
57
57
|
- ".rspec"
|
58
58
|
- spec/spec_helper.rb
|
59
|
+
has_rdoc:
|