运行下面的代码时出现错误“堆栈级别太深”。如果随机选择的卡不存在,它会选择另一张随机卡。我想我应该以某种方式尝试代码,但我不确定如何。有什么建议么?
def hit
choice_of_card = rand($deck.length); #choose a random card out of the deck
drawn_card = $deck[choice_of_card]; #draw that random card from the deck
if drawn_card != 0 #if there is a card there
$deck[choice_of_card] = 0; #remove that card from the deck by making the space blank
if drawn_card == 11 #if you draw an ace
self.ace_count += 1;
end
self.hand_value += drawn_card ;
else hit; #if there is no card at that space then redraw (recursion)
end
end