2
我想在Ruby中創建一個簡單的多人撲克程序,但我覺得我重新發明輪子:確定撲克手兩列
table = [card1, card2, card3, card4, card5]
mike = [card6, card7]
john = [card8, card9]
card6.face = "A"
card6.suit = "spades"
我有一個很難寫一個算法決定每個玩家可能擁有的牌。
例如,以確定如果一個球員被交易沖洗我寫了這樣的事情:
together = table + hand
# Populate hash with number of times each suit was found
$suits.each do |suit|
matched[suit] = together.select{|card| card.suit == suit}.size
end
matched.each do |k,v|
if v == 5
puts "#{k} were seen five times, looks like a flush."
end
end
這似乎不是很全面(沒有辦法知道它是一個王牌高或一個6高的沖水),也不是非常紅寶石般的。
是否有更明顯的方式來確定撲克牌手?
你可以看看這個寶石:https://開頭的github https://github.com/aherve/Euler/blob/master/pb54.rb
簡而言之,
Hand
是由Card
陣列,即以Card.value
和Card.type
響應定義.COM/robolson /紅寶石撲克 – siekfried