mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-05 20:40:25 -08:00
test and fix splitting
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
require_relative "./game.rb"
|
||||
|
||||
# TODOS
|
||||
# 1. check if we should implement insurances
|
||||
# 2. test splitting
|
||||
|
||||
def intro
|
||||
puts "Welcome to Blackjack"
|
||||
end
|
||||
|
||||
@@ -77,7 +77,6 @@ class Game
|
||||
|
||||
def print_players_and_dealer_hands
|
||||
puts "PLAYER\t#{@players.map(&:id).join("\t")}\tDEALER"
|
||||
# TODO: Check for split hands
|
||||
puts " \t#{@players.map {|p| p.hand.cards[0].label}.join("\t")}\t#{@dealer_hand.cards[0].label}"
|
||||
puts " \t#{@players.map {|p| p.hand.cards[1].label}.join("\t")}"
|
||||
end
|
||||
@@ -85,6 +84,10 @@ class Game
|
||||
def play_hand player, hand
|
||||
allowed_actions = ALLOWED_HAND_ACTIONS[(hand.is_split_hand || !hand.can_split?) ? "split" : "normal"]
|
||||
name = "PLAYER #{player.id}"
|
||||
if hand.is_split_hand
|
||||
name += " - HAND #{hand === player.hand ? 1 : 2}"
|
||||
end
|
||||
|
||||
did_hit = false
|
||||
|
||||
while hand.is_playing?
|
||||
@@ -100,8 +103,8 @@ class Game
|
||||
if action === "/"
|
||||
player.split
|
||||
|
||||
play_hand "#{name} - Hand 1", player.hand
|
||||
play_hand "#{name} - Hand 2", player.split_hand
|
||||
play_hand player, player.hand
|
||||
play_hand player, player.split_hand
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ class Hand
|
||||
def split
|
||||
throw "can't split" unless can_split?
|
||||
[
|
||||
Hand.new(@bet, @cards[0..1], is_split_hand: true),
|
||||
Hand.new(@bet, @cards[0...1], is_split_hand: true),
|
||||
Hand.new(@bet, @cards[1..1], is_split_hand: true)
|
||||
]
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ class Pack
|
||||
end
|
||||
|
||||
def draw
|
||||
reshuffle_if_necessary
|
||||
@cards.pop
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user