99_game 3.1.2 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDUxNTFjY2QzNTdmNzgzYjM4ZjQ1ZWQ1OTlkYjQwY2FjMjg4ZjgwYQ==
4
+ Nzc0ODVkYmEzZmMxYTZjNmMzZGYzMTVjYzM3ZWQ1NWJiNjc1OWZlOQ==
5
5
  data.tar.gz: !binary |-
6
- MzQyZjdiZmNkNGI3OGIwNzcyNjJhODY1MTg4Njg5NzFjY2E5YzY0ZA==
6
+ OTMzZjU3MTkwYzE0YmJlNDlmYjA4NzdjZTg1YWUxMGJkODc5MzkxOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDBkZjJjMWQ4ZjQyYzE0MGQ4YjBhNWUxYzA3MGUxOGZiMDY0NGZlMjNhZjNi
10
- MzQzMTI0ZGJiY2QwOTU2Y2Y0MDhkMjIyMWJhNGZhZWMzZDAyNWIyODJkNGQ4
11
- YWE3ZTE1NGMxNTA1MGYzNDU5Yjk0MTU4MTRjOTAxYjI5MmY3Y2M=
9
+ NTNhYjk4NGYwNmE4ZjEwOGNkZjdkNDQ1NjU4NGU4YTZjY2ViOTg3NGY0MDZj
10
+ YjAzOWEwZjE5YTkxM2VkMDdiNmE3ZDdhNzVhYWU4NGY2NzljYWQzODQ3NzVj
11
+ ODlkY2M3NjM1ZjRlYWQ0NGJhM2EwZGI2NDNlYjhkOWVlYmVjMTA=
12
12
  data.tar.gz: !binary |-
13
- ZmNmYzQ3OTNiZTE3OGZmYjIyYjM1MGFkNzc2MjBhMDhiODY4Yzk1ZmEyODAy
14
- YmIzYzcxYmNlMzZjN2Y4NjY3MzY5MTFjMDc1NTQyMzk1NDE2YmVhM2QyZGRl
15
- ZGEyNjY4YmY3ZDFlNzllYzhlZTQ2NGNhOThmYTUxNmFjMGZiNzM=
13
+ YTE3Nzk5NGEwNDIzZWU3NGNmNTE1ODE1ZGQwNDYxZmIxZTg2NDQxMDJjYWMz
14
+ NzE2N2ZiNjk0YjRhYTdlNzBhMmYxZmVmNmY1OWQ2ZGQ4NjNjYjFmNWYxNzJm
15
+ NDU0N2M0YjA3NmVlNDNjNjdjOGVlMDcyNjkyYTNkZDYzMzVlN2Q=
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) {{{2014}}} {{{Zachary Roth Perlmutter}}}
3
+ Copyright (c) 2016 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
@@ -2,8 +2,9 @@
2
2
  require '99_game'
3
3
  include CardDeck
4
4
  deck = Deck.new jokers: true
5
+ deck.cards.shuffle!
5
6
  BEGIN { # Looks at its arguements
6
- ARGV[0] = "-h" if ARGV[0] == "--help"
7
+ ARGV[0] = "-h" if ARGV.first == "--help"
7
8
  ARGV[0] = "-v" if ARGV[0] == "--version"
8
9
  case ARGV[0]
9
10
  when "-v"
@@ -36,33 +37,32 @@ END { # Thanks for playing
36
37
  puts "\n\tThanks for playing 99!"
37
38
  sleep 2.5
38
39
  }
39
- $value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new(deck), Hand.new(deck)
40
+ $value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
40
41
  loop do
41
42
  puts "\n\tIt is the dealer's turn!"
42
43
  i = 1
43
- for card in dealer.hand
44
+ for card in dealer.cards
44
45
  case i
45
- when 1 then test card, $value, value1
46
- when 2 then test card, $value, value2
47
- when 3 then test card, $value, value3
46
+ when 1 then value1 = card_test card, $value
47
+ when 2 then value2 = card_test card, $value
48
+ when 3 then value3 = card_test card, $value
48
49
  end
49
50
  i += 1
50
51
  end
51
52
  if value1 >= value2 && value1 >= value3
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]
53
+ $card = dealer.cards[0].num
54
+ dealer.play dealer.cards[0]
55
+ elsif value2 >= value1 && value2 >= value3
56
+ $card = dealer.cards[1].num
57
+ dealer.play dealer.cards[1]
57
58
  else
58
- $card = dealer.hand[2].num
59
- dealer.play(dealer.hand[2])
59
+ $card = dealer.cards[2].num
60
+ dealer.play dealer.cards[2]
60
61
  end
61
62
  pause 1.5
62
63
  puts "\tThe dealer played a(n) #{$card}"
63
64
  pause(0.5)
64
- puts "\tThe value is now #{$value}"
65
- puts
65
+ puts "\tThe value is now #{$value}\n"
66
66
  pause(1.5)
67
67
  if $value > 99 # Runs when you win and exits loop
68
68
  puts "\tYou win!"
@@ -73,15 +73,15 @@ loop do
73
73
  user.view
74
74
  pause 0.5
75
75
  print "\tPick a card to play by typing in the name of the card => "
76
- input, turn = gets.chomp, true
77
- for card in user.hand
78
- if card.num == converter(input) && turn
76
+ input, playing = gets.chomp, true
77
+ user.cards.each do |card|
78
+ if card.num == converter(input) && playing
79
79
  user.play card
80
- turn = false
80
+ playing = false
81
81
  end
82
82
  end
83
83
  pause 1
84
- puts "\tYou drew a(n) #{user.hand[2].num}"
84
+ puts "\tYou drew a(n) #{user.cards[2].num}"
85
85
  pause(0.5)
86
86
  puts "\tThe value is now #{$value}"
87
87
  pause(1.5)
@@ -1,99 +1,61 @@
1
- require "card_deck"
2
- # Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
3
- def test(card, actual_value, test_value)
1
+ autoload :CardDeck, "card_deck"
2
+ autoload :Card, "card"
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
12
+ def card_test(card, actual_value)
4
13
  if card.num == "King"
5
14
  test_value = 99
6
15
  elsif card.num == "Joker"
7
16
  test_value = 0
8
- else; test_value = actual_value + card.value
17
+ else
18
+ test_value = actual_value + card.value
9
19
  end
10
20
  test_value = -100 if test_value > 99
11
21
  return test_value
12
22
  end
13
23
  # Tests if obj is not nil.
14
24
  def not_nil?(obj)
15
- if obj.nil?
16
- return false
17
- else
18
- return true
19
- end
25
+ !obj.nil?
20
26
  end
21
27
  # 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
37
28
  # Expected errors
38
- class CardError < Exception; end
39
- class CardDeck::Card # Represents a card in the deck
40
- # Value of the card
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
55
- end
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
80
- end
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
- alias inspect hand
87
- end
88
- # Combines sleep and a newline. 'p' is the amount of time waited.
89
- def pause(p)
29
+ class CardError < Exception; end
30
+ =begin
31
+ Combines sleep and a newline
32
+ @param p [Integer] amount of time to sleep
33
+ @return [void]
34
+ =end
35
+ def pause(p)
90
36
  sleep p
91
37
  puts
38
+ end
39
+ =begin
40
+ @param input [String]
41
+ @return [String, Integer]
42
+ If parameter input is an abbreviation, input is converted to what it stands for.
43
+ Otherwise, it simply returns a capitalized version of input.
44
+ @raise [CardError] if input is nil or an emtpy string
45
+ =end
46
+ def converter(input)
47
+ abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"}
48
+ raise(CardError, "Input cannot be blank") if input == String.new
49
+ if input.to_i.zero?
50
+ case input.capitalize
51
+ when ?$ then "Joker"
52
+ when ?K then "King"
53
+ when ?J then "Jack"
54
+ when ?Q then "Queen"
55
+ when ?A then "Ace"
56
+ end
57
+ else
58
+ input.to_i
92
59
  end
93
- class CardDeck::Deck # Cards are stored in these objects
94
- # Draw from the deck
95
- def draw; @cards.shift; end
96
- # Adds 'card' to the deck. Used with Hand#play.
97
- def discard(card); @cards.push card; end
98
60
  end
99
61
 
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,2 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
@@ -1,36 +1,12 @@
1
- create_deck = proc {Deck.new jokers: 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
1
+ require "spec_helper"
2
+ require "99_game"
8
3
  describe "converter" do
9
4
  context "when a number" do
10
- it "should return the input as a number" do
11
- expect(converter("5")).to eq 5
12
- end
5
+ subject { converter ?5 }
6
+ it { is_expected.to eq 5 }
13
7
  end
14
8
  context "when an abbreveation" do
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
9
+ subject { converter ?K }
10
+ it {is_expected.to eq "King"}
35
11
  end
36
12
  end
@@ -0,0 +1,9 @@
1
+ require "spec_helper.rb"
2
+ require "99_game"
3
+ create_deck = proc {Deck.new jokers: true}
4
+ deck = create_deck.call
5
+ describe Deck do
6
+ describe create_deck.call.cards.length do
7
+ it {is_expected.to eq 54}
8
+ end
9
+ end
@@ -0,0 +1,27 @@
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| card_test(s.cards[index], 50)}
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
@@ -1,3 +1,4 @@
1
+ require_relative "codeclimate.rb"
1
2
  require "99_game"
2
3
  include CardDeck
3
4
  # This file was generated by the `rspec --init` command. Conventionally, all
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: 3.1.2
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - Zachary Perlmutter
7
+ - Zachary Roth Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: card_deck
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '4.0'
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
- version: '1.1'
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
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description: ! 'This is a text-based interpretation of the card game 99. Comes with
28
56
  the gem in the form of an executable. Make sure to read the rules in `99_game -h`
29
57
  before playing.
@@ -34,15 +62,19 @@ executables:
34
62
  - 99_game
35
63
  extensions: []
36
64
  extra_rdoc_files:
65
+ - LICENSE.md
37
66
  - README.md
38
- - LICENSE.txt
39
67
  files:
40
- - .rspec
41
- - LICENSE.txt
68
+ - LICENSE.md
42
69
  - README.md
43
70
  - bin/99_game
44
71
  - lib/99_game.rb
72
+ - lib/card.rb
73
+ - lib/hand.rb
74
+ - spec/codeclimate.rb
45
75
  - spec/lib/99_game_spec.rb
76
+ - spec/lib/deck_spec.rb
77
+ - spec/lib/hand_spec.rb
46
78
  - spec/spec_helper.rb
47
79
  homepage: https://rubygems.org/gems/99_game
48
80
  licenses:
@@ -64,11 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
96
  version: '0'
65
97
  requirements: []
66
98
  rubyforge_project:
67
- rubygems_version: 2.4.2
99
+ rubygems_version: 2.4.5
68
100
  signing_key:
69
101
  specification_version: 4
70
102
  summary: The game of 99.
71
103
  test_files:
104
+ - spec/codeclimate.rb
72
105
  - spec/lib/99_game_spec.rb
73
- - .rspec
106
+ - spec/lib/deck_spec.rb
107
+ - spec/lib/hand_spec.rb
74
108
  - spec/spec_helper.rb
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --require spec_helper.rb
3
- --warnings
4
- --format doc