嗨,我已经编写了各种赌博程序,例如轮盘赌二十一点,现在我正在做扑克
我正在抽 5 张牌并试图在抽牌前确定我的手是否是顺子
我是一个简单的程序员,我没有受过教育。现在我正在尝试通过找到最高和最低的牌并查看牌是否匹配来确定顺子
如果最高牌 = 最低牌 + 5 并且手中没有重复数字,这不应该准确找到顺子吗?
我的代码非常基本且很长,所以我不会在这里发布我会尽一切努力找到最高/最低和匹配的卡
我认为这是我找到的最简单的方法,但它可能太简单了
both solutions work.
I would do something like this.
Dim cards As List(Of Integer) = New List(Of Integer)
Dim isStraight as Boolean = False
cards.Add(1)
cards.Add(3)
cards.Add(2)
cards.Add(4)
cards.Add(5)
Dim areMultipleNumbersInList As Boolean = cards.GroupBy(Function(x) x).Any(Function(x) x.Count() > 1)
Dim max As Integer = cards.Max()
Dim min As Integer = cards.Min()
If (max - min = 4 AndAlso Not areMultipleNumbersInList) Then
isStraight = True
End If
You need .NET 4.0 in order to use the Enumerable.Max/Min Methods. If you need a solution for another .NET Framework let me know
EDIT: added areMultipleNumbersInList to code