vb.net - Simple game of Old Maid, not so simple? -


fair warning, going post entire code player 1 because i'm not sure needed in order proceed. in desperate need help. there 49 cards, , player 1 getting 16. when hit deal, there 16 cards displayed user.

my question is: how check these 16 cards doubles , remove cards , put them in discard pile?

public class deckofcardstest     dim playercards integer = 16     dim playermatches integer     dim comp1cards integer = 16     dim comp1matches integer     dim comp2cards integer = 17     dim comp2matches integer       private deck new deckofcards() ' create deck of cards     public class deckofcards     private const number_of_cards integer = 49 ' number of cards    private deck(number_of_cards - 1) card ' array of card objects    private currentcard integer ' index of next card dealt    private shared randomnumbers new random() ' random number generator     ' constructor fills deck of cards    public sub new()       dim faces() string = {"ace", "two", "three", "four", "five",          "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"}       dim suits() string = {"hearts", "diamonds", "clubs", "spades"}         currentcard = 0 ' set currentcard first card dealt deck(0)          ' populate deck array card objects         count = 0 deck.getupperbound(0)             deck(count) = new card(faces(count mod 13), suits(count \ 13))         next     end sub ' new       ' shuffle deck of cards simple one-pass algorithm     public sub shuffle()         ' after shuffling, dealing should start @ deck(0) again         currentcard = 0 ' reinitialize currentcard          ' each card, pick random card , swap them         first = 0 deck.getupperbound(0)             ' select random number between 0 , 51             dim second integer = randomnumbers.next(number_of_cards)              ' swap current card randomly selected card             dim temp card = deck(first) ' store copy of deck(first)             deck(first) = deck(second) ' move deck(second) deck(first)             deck(second) = temp ' move original deck(first) deck(second)         next     end sub ' shuffle      ' deal 1 card     public function dealcard() card         ' determine whether cards remain dealt         if currentcard <= deck.getupperbound(0)             dim lastcard integer = currentcard ' store current card number             currentcard += 1 ' increment current card number              return deck(lastcard)         else             return nothing ' no more cards deal         end if        end function ' dealcard   end class ' deckofcards 

how list(of card) work in code?

dim cards list(of card) 'players hand  if cards.select(function(x) x.value).distinct.count < cards.count     'there duplicates in list     dim duplicates = cards.groupby(function(x) x.value).where(function(g) g.count > 1).select(function(g) g.key).tolist     each in duplicates         debug.writeline("card value " + i.tostring + " match")     next end if 

here errors:

error   1   overload resolution failed because no accessible 'select' can called these arguments: extension method 'public function select(of tresult)(selector system.func(of card, integer, tresult)) system.collections.generic.ienumerable(of tresult)' defined in 'system.linq.enumerable': nested function not have signature compatible delegate 'system.func(of card, integer, tresult)'. extension method 'public function select(of tresult)(selector system.func(of card, integer, tresult)) system.collections.generic.ienumerable(of tresult)' defined in 'system.linq.enumerable': data type(s) of type parameter(s) cannot inferred these arguments. specifying data type(s) explicitly might correct error. extension method 'public function select(of tresult)(selector system.func(of card, tresult)) system.collections.generic.ienumerable(of tresult)' defined in 'system.linq.enumerable': 'value' not member of 'deckofcardstest.card'. extension method 'public function select(of tresult)(selector system.func(of card, tresult)) system.collections.generic.ienumerable(of tresult)' defined in 'system.linq.enumerable': data type(s) of type parameter(s) cannot inferred these arguments. specifying data type(s) explicitly might correct error.   error   2   data type(s) of type parameter(s) in extension method 'public function groupby(of tkey)(keyselector system.func(of card, tkey)) system.collections.generic.ienumerable(of system.linq.igrouping(of tkey, card))' defined in 'system.linq.enumerable' cannot inferred these arguments. specifying data type(s) explicitly might correct error.  error   3   'value' not member of 'deckofcardstest.card'.  error   4   option strict on disallows implicit conversions 'object' 'system.collections.generic.ienumerable(of deckofcardstest.card)'.   error   5   option strict on disallows late binding.     

i not familiar old maid, please excuse ignorance.

if understand question correctly, want check player's hand, remove doubles, , place them in discard pile?

if that's case, deck object need have array (or preferably list) of card object represent discard pile. then, after deal cards, loop through each card in player's hand , compare every other card (not including itself). since card object, if 2 cards identical, point same object. make note of indexes of identical cards, add them discard pile , remove them player's hand.

edit: based on code update, do. didn't check syntax think it's correct. if not, let me know , fix it.

dim cards new list(of card) 'players hand dim discardpile new list(of card) ' discard pile  integer = 1 16    cards.add(deck.dealcard()) next  if cards.select(function(x) x).distinct.count < cards.count 'there duplicates in list     dim duplicates list(of card) = cards.groupby(function(x) x.gwtvalue).where(function(g) g.count > 1).selectmany(function(g) g.toarray).tolist      ' part adds duplicates discard pile     discardpile.addrange(duplicates)     ' part remove duplicates player's hand            cards.removeall(function(y) duplicates.contains(y))  end if 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -