How do I call a method without it's constructor first?

This is a discussion on How do I call a method without it's constructor first? within the C# Programming forums, part of the General Programming Boards category; I've attached a console application that is an OO DrawPoker game. My objective is to re-create the deck and shuffle ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    1

    Red face How do I call a method without it's constructor first?

    I've attached a console application that is an OO DrawPoker game. My objective is to re-create the deck and shuffle it after every hand, but it's not working. Instead the system makes multiple DealHand()'s therefore reducing the deck count unnaturally.

    The system was created in VS 2012 / .NET 4.5 FYI.

    Steve/Jazz EngineerDrawPoker.zipDrawPoker.zip

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I don't particularly want to go wading through and debugging your source code without getting paid to do so. Post the relevant code or the area you think the problem is in and then we will be more inclined to help.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Well, it does multiple DealHands because your Regenerate method does that. That, I am assuming, is not at all what it should be doing.

    The Deck class contains two methods that, when called in sequence, will generate and shuffle a new deck. I'd use those.

    FYI, Deck.Shuffle is quite an inefficient shuffle algorithm, moving, on average, 2.6 million card references around in memory just to shuffle 52 cards. There are much better ways to reach the same end result.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    There are a few ways to shuffle efficiently.
    • You could swap the first and last card, second and second to last, third and third to last...all the way till you reach half the deck. This does not result in a very good shuffle if the original deck is in ascending order.
    • You can also select card 1 and any other card except card 1 and swap them. Move to card 2 and swap it with any other card except card 2, etc, etc.


    Incidentally this question is asked frequently in interviews. Given a deck of 52 cards show me an algorithm on the white board that will shuffle the deck in one pass ensuring that every card is shuffled. Note that the question does not state how 'shuffled' the deck must be.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > Given a deck of 52 cards show me an algorithm on the white board that will shuffle the deck in one pass ensuring that every card is shuffled.
    > Note that the question does not state how 'shuffled' the deck must be.
    By this definition, simply moving the first card to the end of the deck moves the ordinal position of every card in the deck, but I wouldn't call it a shuffle.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    By this definition, simply moving the first card to the end of the deck moves the ordinal position of every card in the deck, but I wouldn't call it a shuffle.
    No it is not a shuffle but it does fulfill the requirements if shuffled means the indexes change. Nice answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-23-2012, 10:47 PM
  2. Specialized Constructor call Default Constructor
    By threahdead in forum C++ Programming
    Replies: 15
    Last Post: 08-23-2010, 03:39 PM
  3. Using my own method in a constructor...
    By AngryStyro in forum C++ Programming
    Replies: 13
    Last Post: 06-04-2008, 01:02 PM
  4. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  5. Call constructor within constructor. How to?
    By xErath in forum C++ Programming
    Replies: 10
    Last Post: 11-18-2004, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21