ruby-blackjack 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efe3747adde761eea4f77c2afa6855c569c4288a
4
- data.tar.gz: 819656988aba32192bdecda5ec00ac03e63a7631
3
+ metadata.gz: cdea56b85c116fc3a4b57dbdf766f305f3af2832
4
+ data.tar.gz: 67b6addb052e8378a377a17771e631173546816f
5
5
  SHA512:
6
- metadata.gz: 55a3e2a588222eb38d1219e65770bc947d14d162c4da6c76528c753caa9cc21a1bebd11c8a1586721ce1595c2a478c198354dde1aa666070e87f6e0d72267304
7
- data.tar.gz: 320f47ecda727b8264749a8b846db8a9fa0a381d5a071c6d71941c90b33c48c62ced35c6ed24ec1a6a52eeb18e4656399fee8d9036caeef548d1b2e1ad3987fa
6
+ metadata.gz: 244b423811bd6719f546ea89970502ee1161af9637f6c5d837b02f76d2955e114635e4c2307b8cb2cf114a9e8a6a282e5b80c9835300aff34e51644b46569242
7
+ data.tar.gz: 790a84700c025bd9da3a817f46212189fd9f476da9912c5774328a266b1adcc7e818c48902d9ed007043a3aa32ac03cd5a0161e8b4dab7cfaa9f9c5b470239ba
data/Rakefile CHANGED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -61,7 +61,7 @@ class BlackjackCli
61
61
  elsif result[2] == 'loss'
62
62
  puts ' You lost :( '.set_attributes([RED_BG, BLACK_FG])
63
63
  elsif result[2] == 'draw'
64
- puts " It's a draw ".set_attributes([[YELLOW_BG, BLACK_FG]])
64
+ puts " It's a draw ".set_attributes([YELLOW_BG, BLACK_FG])
65
65
  end
66
66
 
67
67
  if result[2] != 'undecided'
@@ -100,10 +100,15 @@ class Game
100
100
  # @return [Card Array, Card Array, string] the result of the drawing. Refer to evaluate() for details
101
101
  def stand
102
102
  @dealer_cards[1].flip_over
103
- while @dealer_score < 17
104
- hit(true)
103
+ result = [@player_cards.clone, @dealer_cards.clone, 'undecided']
104
+ while @dealer_score < 17 and result[2] == 'undecided'
105
+ result = hit(true)
106
+ end
107
+ if result[2] == 'undecided'
108
+ evaluate(true)
109
+ else
110
+ result
105
111
  end
106
- evaluate(true)
107
112
  end
108
113
 
109
114
 
@@ -143,11 +148,12 @@ class Game
143
148
  # Resets the game to enable starting a new game.
144
149
  # @return [Card Array, Card Array] the user's cards and the dealer's cards
145
150
  def cleanup
151
+ if @dealer_cards[1].is_flipped
152
+ @dealer_cards[1].flip_over
153
+ end
146
154
  @used_cards += @player_cards + @dealer_cards
147
155
  @player_score = 0
148
156
  @dealer_score = 0
149
- @player_ace_count = 0
150
- @dealer_ace_count = 0
151
157
  old_player_cards = @player_cards.clone
152
158
  old_dealer_cards = @dealer_cards.clone
153
159
  @player_cards = []
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class HomeControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index
6
+ assert_response :success
7
+ end
8
+
9
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-blackjack
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Krumrey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Blackjack CLI game
14
14
  email: hermann@krumreyh.com
@@ -21,11 +21,17 @@ files:
21
21
  - README.md
22
22
  - Rakefile
23
23
  - bin/blackjack
24
+ - bin/bundle
25
+ - bin/rails
26
+ - bin/rake
27
+ - bin/setup
24
28
  - lib/blackjack/blackjack_cli.rb
25
29
  - lib/blackjack/game.rb
26
30
  - lib/blackjack/objects/card.rb
27
31
  - lib/blackjack/strings/string.rb
28
32
  - lib/ruby-blackjack.rb
33
+ - test/controllers/home_controller_test.rb
34
+ - test/test_helper.rb
29
35
  homepage: http://gitlab.namibsun.net/namboy94/ruby-blackjack
30
36
  licenses:
31
37
  - GPL-3.0