Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Basic为直接组合评估卡片列表_C#_Vb.net_Linq_Poker - Fatal编程技术网

C# Visual Basic为直接组合评估卡片列表

C# Visual Basic为直接组合评估卡片列表,c#,vb.net,linq,poker,C#,Vb.net,Linq,Poker,我正在创建一个扑克评估器,但我很难弄清楚如何检查“直”组合(我还需要知道是什么卡组成了组合) 我有一张卡片列表,所以我需要弄清楚以下几点: 该列表是否包含ace 如果是: 创建ace较高的新列表 在ace较低的位置创建一个新列表 对两个列表进行检查,并返回直接组合中具有较高数量的卡 如果否: 运行检查列表,并返回直接组合的卡 如何检查直线组合: 浏览列表,检查当前卡的排名+1是否等于上一张卡的排名 使用这种方法,我们将遇到一个问题 考虑以下因素: 国王 女王 杰克 三 两个 结果将是:

我正在创建一个扑克评估器,但我很难弄清楚如何检查“直”组合(我还需要知道是什么卡组成了组合)

我有一张卡片列表,所以我需要弄清楚以下几点:

该列表是否包含ace

如果是:

  • 创建ace较高的新列表
  • 在ace较低的位置创建一个新列表
  • 对两个列表进行检查,并返回直接组合中具有较高数量的卡
如果否:

  • 运行检查列表,并返回直接组合的卡
如何检查直线组合:

浏览列表,检查当前卡的排名+1是否等于上一张卡的排名

使用这种方法,我们将遇到一个问题

考虑以下因素:

  • 国王
  • 女王
  • 杰克
  • 两个
  • 结果将是:

  • 金=无=假
  • 女王=国王=真
  • 杰克=女王=真
  • 三=杰克=假
  • 二=三=正确
  • 这个结果不好,那样的结果应该是:国王,王后,杰克

    我不知道如何以一种聪明的方式,或者仅仅是以一种可行的方式,将其转化为代码。我试过使用LINQ,也试过使用for循环

    以下是我制作的卡片类:

    Public Enum CardRank
        Two = 2
        Three = 3
        Four = 4
        Five = 5
        Six = 6
        Seven = 7
        Eight = 8
        Nine = 9
        Ten = 10
        Jack = 11
        Queen = 12
        King = 13
        Ace = 14
    End Enum
    
    Public Enum CardSuit
        Club = 1
        Diamond = 2
        Heart = 3
        Spade = 4
    End Enum
    
    Public Class Card
        Public Rank As CardRank
        Public Suit As CardSuit
    
    #Region "Constructor"
        Sub New()
    
        End Sub
    
        Sub New(ByVal Rank As CardRank, ByVal Suit As CardSuit)
            Me.Rank = Rank
            Me.Suit = Suit
        End Sub
    #End Region
    
        Public Overrides Function ToString() As String
            Return [Enum].GetName(GetType(CardRank), Rank) + " of " + [Enum].GetName(GetType(CardSuit), Suit)
        End Function
    End Class
    
    复制此文件以快速开始:

    Dim Deck As New List(Of Card)
    Dim Cards As List(Of Card) = New Card() {New Card(CardRank.King, CardSuit.Spade), New Card(CardRank.Queen, CardSuit.Heart), New Card(CardRank.Jack, CardSuit.Club), New Card(CardRank.Three, CardSuit.Spade), New Card(CardRank.Two, CardSuit.Diamond)}.ToList()
    
    'Add deck
    For Each Suit As CardSuit In [Enum].GetValues(GetType(CardSuit))
        For Each Rank As CardRank In [Enum].GetValues(GetType(CardRank))
            Deck.Add(New Card(Rank, Suit))
        Next
    Next
    
    For Each Card As Card In Cards
        Deck.Remove(Card)
    Next
    
    也许我走错了方向

    编辑:一张直牌是连续排列的五张牌。请注意,在holdem中,ACE可以是高或低。 编辑:以下是我如何在atm机上列出我的卡。(当然可以修改以适应其他方法)


    你能做的就是找到最小值和最大值的卡,然后用总和来检查它是否是一张直卡。伪代码:

    def isStraight(cards)
        isStraight = true;
    
        // Check for cases except ace has value 1.
        min = cards.min()
        for (index = min + 1; index < min + 5; index++)
            isStraight &= cards.exist(index);
    
        if not isStraight:
           // Check for case ace has value 1
           isStraight = cards.exist(14) and
                        cards.exist(2) and 
                        cards.exist(3) and 
                        cards.exist(4) and
                        cards.exist(5)
    
        return isStraight
    
    def isStraight(卡片)
    isStraight=正确;
    //检查除ace值为1以外的情况。
    min=cards.min()
    对于(索引=min+1;索引
    Hmmm。这不是小事,但以下是我将如何处理它

    首先,按如下方式更新您的面值:

    Public Enum CardRank
        Ace = 0
        Two = 1
        Three = 2
        Four = 3
        Five = 4
        Six = 5
        Seven = 6
        Eight = 7
        Nine = 8
        Ten = 9
        Jack = 10
        Queen = 11
        King = 12
    End Enum
    
    因此,您的值从Ace的0到King的12。在许多情况下,如果您习惯了基于0的索引,您的生活会变得更轻松()

    现在,如果你的牌是按升序排列的,那么很容易判断你的牌是不是直牌。(我已经多年没有写VB了,所以这将是伪代码)

    因为我们的mod是13,所以King后面的卡将是(12+1)mod 13=13 mod 13=0,这是王牌,正如预期的那样

    我真的不懂扑克,所以我不确定一个直杆是否可以通过a盘旋(意思是Q,K,a,2,3 a直杆?)。如果没有,那么检查两种情况下的ACE高和ACE低仍然非常容易。Aces low很琐碎,就是这段代码。对于aces high,必须从10开始。排序后,Ace将成为第一张卡片(这并不理想),因此任何开始[Ace,10,…]的序列都可以快速重新排列为[10,…,Ace],然后通过相同的算法运行


    M

    我要感谢每一位为我提供时间和帮助的人,这是我已经挣扎了好几天的问题

    最后我自己想出来了。我这样做的方法涵盖了所有的可能性,不仅仅是一些,它还返回了创建组合的卡片列表

    基本功能:

        Private Function ReturnStraight(ByVal tempList As List(Of Card)) As List(Of Card)
        Dim cardslist As New List(Of List(Of Card)) 'Lists of lists of cards in sequential rank
        Dim temporaryList As New List(Of Card) 'Temporary list to add seqeuntial ranked cards to, to later add to the above list
        Dim previousCard As Card = tempList(0) 'Gotta start somewhere
    
        For i = 0 To tempList.Count - 1
            Dim Card As Card = tempList(i)
    
            If Card.Rank + 1 = previousCard.Rank Then 'If the queen + 1 equals king
                If temporaryList.Find(Function(c) c.Rank = previousCard.Rank) Is Nothing Then : temporaryList.Add(previousCard) : End If 'If it doesn't already contain the previous card, add it (we want the king, which we wouldn't get without this)
                temporaryList.Add(Card) 'Add the card (the queen)
    
                If i = tempList.Count - 1 Then 'We need this if because of certain scenarios, e.g. King, Queen, Jack, Three, Two - King, Queen, Jack would be added, but three and two would not because we would not enter the else below when Two + 1 = 3...
                    If temporaryList.Count > 0 Then : cardslist.Add(temporaryList) : End If 'If the list is not empty, add it to the list of list of cards
                    temporaryList = New List(Of Card) 'Assign it a new empty list of cards to elimate referencing
                End If
            Else 'If the sequential list breaks (goes from jack to 3), add the temporary list of cards to the list of list of cards
                If temporaryList.Count > 0 Then : cardslist.Add(temporaryList) : End If  'If the list is not empty, add it to the list of list of cards
                temporaryList = New List(Of Card) 'Assign it a new empty list of cards to elimate referencing
            End If
    
            previousCard = Card 'Assign the current card to the previousCard holder
        Next
    
        cardslist = cardslist.OrderByDescending(Function(list) list.Count()).ToList() 'We want to list them in descending order by the count of cards
    
        If Not cardslist.Count = 0 Then 'We have to check to see if the cardlist is empty or not, because if it is and we return it, we get an error.... 
            Return cardslist(0) 'Return the highest count card list
        End If
    
        Return tempList 'Function failed because there are not enough cards, so return the original list
    End Function
    
    我如何使用它:

        Dim tempList = Cards.GroupBy(Function(card) card.Rank).OrderByDescending(Function(group) group.Count()).SelectMany(Function(group) group).ToList()
    
        If tempList.Find(Function(Card) Card.Rank = CardRank.Ace) IsNot Nothing Then 'We have an ace
            Dim noAce = (From Card As Card In tempList Where Card.Rank <> CardRank.Ace Select Card).ToList()
            Dim lst = ReturnStraight(noAce)
            If lst(lst.Count - 1).Rank = CardRank.Two Or lst(0).Rank = CardRank.King Then
                lst.Add((From Card As Card In tempList Where Card.Rank = CardRank.Ace Select Card).ToList(0))
            End If
        Else
    
            Dim lst = ReturnStraight(tempList)
            For Each Card As Card In lst
                MsgBox(Card.ToString())
            Next
        End If
    
    Dim templast=Cards.GroupBy(函数(卡片)card.Rank).OrderByDescending(函数(组)group.Count()).SelectMany(函数(组)group.ToList())
    如果tempList.Find(函数(卡片)Card.Rank=CardRank.Ace)不是空的,那么“我们有一张Ace”
    Dim noAce=(从圣殿骑士中的卡作为卡,其中Card.Rank CardRank.Ace选择卡)。ToList()
    尺寸lst=返回直线(noAce)
    如果lst(lst.Count-1).Rank=CardRank.Two或lst(0).Rank=CardRank.King,则
    第一次添加((从圣殿骑士中的卡片作为卡片,其中Card.Rank=CardRank.Ace选择卡片)。ToList(0))
    如果结束
    其他的
    Dim lst=返回直线(圣殿骑士)
    对于每个卡,作为lst中的卡
    MsgBox(Card.ToString())
    下一个
    如果结束
    
    您的代码显示您的类,但不显示您试图对它们进行排序的方式。你有更多的代码要显示吗?我已经编辑了我的主要帖子,请再看一看。谢谢:)这不是忽略了诉讼的存在吗?例如,由4H+4S+6D+8C+8H组成的手。最小值=4,最大值=8,(最小值+最大值)*5/2=30。总和=30。但不是直的。@Damien_不信者你是完全正确的;我更改了算法。我认为您需要
    &=
    或在这些循环中插入一些早期中断。同一只手再次赋值
    isStraight
    true、false、true、false、true
    ,然后返回true。@Damien\u不信者true。。并且修复了(如果附近没有编译器和测试用例,很难做到)。
        Private Function ReturnStraight(ByVal tempList As List(Of Card)) As List(Of Card)
        Dim cardslist As New List(Of List(Of Card)) 'Lists of lists of cards in sequential rank
        Dim temporaryList As New List(Of Card) 'Temporary list to add seqeuntial ranked cards to, to later add to the above list
        Dim previousCard As Card = tempList(0) 'Gotta start somewhere
    
        For i = 0 To tempList.Count - 1
            Dim Card As Card = tempList(i)
    
            If Card.Rank + 1 = previousCard.Rank Then 'If the queen + 1 equals king
                If temporaryList.Find(Function(c) c.Rank = previousCard.Rank) Is Nothing Then : temporaryList.Add(previousCard) : End If 'If it doesn't already contain the previous card, add it (we want the king, which we wouldn't get without this)
                temporaryList.Add(Card) 'Add the card (the queen)
    
                If i = tempList.Count - 1 Then 'We need this if because of certain scenarios, e.g. King, Queen, Jack, Three, Two - King, Queen, Jack would be added, but three and two would not because we would not enter the else below when Two + 1 = 3...
                    If temporaryList.Count > 0 Then : cardslist.Add(temporaryList) : End If 'If the list is not empty, add it to the list of list of cards
                    temporaryList = New List(Of Card) 'Assign it a new empty list of cards to elimate referencing
                End If
            Else 'If the sequential list breaks (goes from jack to 3), add the temporary list of cards to the list of list of cards
                If temporaryList.Count > 0 Then : cardslist.Add(temporaryList) : End If  'If the list is not empty, add it to the list of list of cards
                temporaryList = New List(Of Card) 'Assign it a new empty list of cards to elimate referencing
            End If
    
            previousCard = Card 'Assign the current card to the previousCard holder
        Next
    
        cardslist = cardslist.OrderByDescending(Function(list) list.Count()).ToList() 'We want to list them in descending order by the count of cards
    
        If Not cardslist.Count = 0 Then 'We have to check to see if the cardlist is empty or not, because if it is and we return it, we get an error.... 
            Return cardslist(0) 'Return the highest count card list
        End If
    
        Return tempList 'Function failed because there are not enough cards, so return the original list
    End Function
    
        Dim tempList = Cards.GroupBy(Function(card) card.Rank).OrderByDescending(Function(group) group.Count()).SelectMany(Function(group) group).ToList()
    
        If tempList.Find(Function(Card) Card.Rank = CardRank.Ace) IsNot Nothing Then 'We have an ace
            Dim noAce = (From Card As Card In tempList Where Card.Rank <> CardRank.Ace Select Card).ToList()
            Dim lst = ReturnStraight(noAce)
            If lst(lst.Count - 1).Rank = CardRank.Two Or lst(0).Rank = CardRank.King Then
                lst.Add((From Card As Card In tempList Where Card.Rank = CardRank.Ace Select Card).ToList(0))
            End If
        Else
    
            Dim lst = ReturnStraight(tempList)
            For Each Card As Card In lst
                MsgBox(Card.ToString())
            Next
        End If