公正な警告ですが、先に進むために何が必要なのかわからないという理由だけで、プレーヤー 1 のコード全体を投稿します。どうしても助けが必要です。49 枚のカードがあり、プレイヤー 1 は 16 枚を受け取ります。ディールをヒットすると、16 枚のカードがユーザーに表示されます。
私の質問は、これらの 16 枚のカードをチェックしてダブルを確認し、それらのカードを取り除いて捨て札に置くにはどうすればよいですか?
Public Class DeckOfCardsTest
Dim playercards As Integer = 16
Dim playermatches As Integer
Dim comp1cards As Integer = 16
Dim comp1matches As Integer
Dim comp2cards As Integer = 17
Dim comp2matches As Integer
Private deck As New DeckOfCards() ' create the deck of cards
Public Class DeckOfCards
Private Const NUMBER_OF_CARDS As Integer = 49 ' number of cards
Private deck(NUMBER_OF_CARDS - 1) As Card ' array of Card objects
Private currentCard As Integer ' index of next Card to be dealt
Private Shared randomNumbers As New Random() ' random number generator
' constructor fills deck of Cards
Public Sub New()
Dim faces() As String = {"Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
Dim suits() As String = {"Hearts", "Diamonds", "Clubs", "Spades"}
currentCard = 0 ' set currentCard so first Card dealt is deck(0)
' populate deck array with Card objects
For count = 0 To deck.GetUpperBound(0)
deck(count) = New Card(faces(count Mod 13), suits(count \ 13))
Next
End Sub ' New
' shuffle deck of Cards with simple one-pass algorithm
Public Sub Shuffle()
' after shuffling, dealing should start at deck(0) again
currentCard = 0 ' reinitialize currentCard
' for each Card, pick another random Card and swap them
For first = 0 To deck.GetUpperBound(0)
' select a random number between 0 and 51
Dim second As Integer = randomNumbers.Next(NUMBER_OF_CARDS)
' swap current Card with randomly selected Card
Dim temp As Card = deck(first) ' store copy of deck(first)
deck(first) = deck(second) ' move deck(second) to deck(first)
deck(second) = temp ' move original deck(first) to deck(second)
Next
End Sub ' Shuffle
' deal one Card
Public Function DealCard() As Card
' determine whether Cards remain to be dealt
If currentCard <= deck.GetUpperBound(0) Then
Dim lastCard As Integer = currentCard ' store current card number
currentCard += 1 ' increment current card number
Return deck(lastCard)
Else
Return Nothing ' no more cards to deal
End If
End Function ' DealCard
End Class ' DeckOfCards
この List(Of Card) をコードで動作させるにはどうすればよいですか?
Dim Cards As List(Of Card) 'Players hand
If Cards.Select(Function(x) x.Value).Distinct.Count < Cards.Count Then
'there are some duplicates in the list
Dim duplicates = Cards.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(g) g.Key).ToList
For Each i In duplicates
Debug.WriteLine("Card value " + i.ToString + " is a match")
Next
End If
エラーは次のとおりです。
Error 1 Overload resolution failed because no accessible 'Select' can be called with these arguments: Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of Card, Integer, TResult)'.
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error. Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': 'Value' is not a member of 'DeckOfCardsTest.Card'. Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Error 2 Data type(s) of the type parameter(s) in extension method 'Public Function GroupBy(Of TKey)(keySelector As System.Func(Of Card, TKey)) As System.Collections.Generic.IEnumerable(Of System.Linq.IGrouping(Of TKey, Card))' defined in 'System.Linq.Enumerable' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Error 3 'Value' is not a member of 'DeckOfCardsTest.Card'.
Error 4 Option Strict On disallows implicit conversions from 'Object' to 'System.Collections.Generic.IEnumerable(Of DeckOfCardsTest.Card)'.
Error 5 Option Strict On disallows late binding.