Skip to content

Commit f3399cd

Browse files
committed
test and fix splitting
1 parent b38cf00 commit f3399cd

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

10_Blackjack/ruby/blackjack.rb

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
require_relative "./game.rb"
22

3-
# TODOS
4-
# 1. check if we should implement insurances
5-
# 2. test splitting
6-
73
def intro
84
puts "Welcome to Blackjack"
95
end

10_Blackjack/ruby/game.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ def settle
7777

7878
def print_players_and_dealer_hands
7979
puts "PLAYER\t#{@players.map(&:id).join("\t")}\tDEALER"
80-
# TODO: Check for split hands
8180
puts " \t#{@players.map {|p| p.hand.cards[0].label}.join("\t")}\t#{@dealer_hand.cards[0].label}"
8281
puts " \t#{@players.map {|p| p.hand.cards[1].label}.join("\t")}"
8382
end
8483

8584
def play_hand player, hand
8685
allowed_actions = ALLOWED_HAND_ACTIONS[(hand.is_split_hand || !hand.can_split?) ? "split" : "normal"]
8786
name = "PLAYER #{player.id}"
87+
if hand.is_split_hand
88+
name += " - HAND #{hand === player.hand ? 1 : 2}"
89+
end
90+
8891
did_hit = false
8992

9093
while hand.is_playing?
@@ -100,8 +103,8 @@ def play_hand player, hand
100103
if action === "/"
101104
player.split
102105

103-
play_hand "#{name} - Hand 1", player.hand
104-
play_hand "#{name} - Hand 2", player.split_hand
106+
play_hand player, player.hand
107+
play_hand player, player.split_hand
105108

106109
return
107110
end

10_Blackjack/ruby/model/hand.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def can_split?
5454
def split
5555
throw "can't split" unless can_split?
5656
[
57-
Hand.new(@bet, @cards[0..1], is_split_hand: true),
57+
Hand.new(@bet, @cards[0...1], is_split_hand: true),
5858
Hand.new(@bet, @cards[1..1], is_split_hand: true)
5959
]
6060
end

10_Blackjack/ruby/model/pack.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def reshuffle_if_necessary
1313
end
1414

1515
def draw
16+
reshuffle_if_necessary
1617
@cards.pop
1718
end
1819

0 commit comments

Comments
 (0)