Results 1 to 18 of 18

Thread: I need help with my Texas HoldEm program.

  1. #1

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    I need help with my Texas HoldEm program.

    Hello, I am trying to make a Texas HoldEm program and I need a little help with generating the cards.

    When the play presses Button1 I want it to randomly generate 2 cards. These cards will generate in TextBox1 and TextBox2.

    This is all I have so far. (I know, it's pathetic.)
    Code:
        Dim Rand As New Random
        Dim Cards As String = ("A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K")
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End Sub
    Any help is appreciated. I am not good with VB.NET at all. (Yet.)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Follow the CodeBank link in my signature and check out the two threads there on selecting random items from lists.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    I still don't understand, I read through your threads but they are too confusing to me. I am only a beginner.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Did you actually try executing the code to see what it did? What exactly confused you? I'm afraid that it doesn't get too much simpler than what I provided there so you need to suck it up and learn. If you can indicate exactly what the stumbling block was then I can try to explain in more detail but I'm not going to just explain again what I've already explained with no particular indication that you'd understand that either.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by jmcilhinney View Post
    Did you actually try executing the code to see what it did? What exactly confused you? I'm afraid that it doesn't get too much simpler than what I provided there so you need to suck it up and learn. If you can indicate exactly what the stumbling block was then I can try to explain in more detail but I'm not going to just explain again what I've already explained with no particular indication that you'd understand that either.
    I read through all of it, and I understand it.

    I am trying to make it so that when you press Button1 you will get 2 "cards" from [A-2-3-4-5-6-7-8-9-10-J-Q-K] and each one of these cards have 4 different backcolors.

    I understand your code, I am just not sure how to implement my idea into your code. That is what I am trying to get help with.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by Flavor Flav View Post
    I understand your code, I am just not sure how to implement my idea into your code. That is what I am trying to get help with.
    Maybe that's what you should have said in the first place then, instead of saying that you didn't understand it when you actually did. I'm not going to simply divine things like that. I only know what you tell me.

    Anyway, use the extension method provided in the thread on randomising a list. Create your array of all cards, call that Randomise method on that, call Take on the result and specify the number of items that you want to take from the randomised list, i.e. 2, and then call ToArray on the result. That will give you an array containing two random cards and you can do with them what you will.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by jmcilhinney View Post
    Maybe that's what you should have said in the first place then, instead of saying that you didn't understand it when you actually did. I'm not going to simply divine things like that. I only know what you tell me.

    Anyway, use the extension method provided in the thread on randomising a list. Create your array of all cards, call that Randomise method on that, call Take on the result and specify the number of items that you want to take from the randomised list, i.e. 2, and then call ToArray on the result. That will give you an array containing two random cards and you can do with them what you will.
    A noob like me has no idea what you just said. I am thankful you are helping but I don't understand.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Are you saying that you don't know how to call a method?

  9. #9
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: I need help with my Texas HoldEm program.

    I'll assume you read the codebank on Randoms and understand how they work. I'll also assume that you know how arrays work...

    The simplest form of taking a Random is to pull the item at a random index of the array. I assume that you know how arrays are indexed? So, initialize a class level Random variable in your Form_Load method. Then, call randomVariableYouSet.Random(0,array.Length) to pick a random index value of the current array. Remove the item from the array, and do it again. This will leave you with your original array - the 2 randomly picked elements (ie your cards).

  10. #10

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    Ok, so instead of me wanting to randomize the number and the backcolor of the textbox I just made 52 pictureboxes and inside of them are cards i made in photoshop.

    How would i randomize these pictureboxes now...?

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: I need help with my Texas HoldEm program.

    For Texas Hold'em you won't need to show 52 cards at one time. 5 common cards + 2 additional for each player.

    Have you looked at the CardGameStarterKit for MS?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by Flavor Flav View Post
    Ok, so instead of me wanting to randomize the number and the backcolor of the textbox I just made 52 pictureboxes and inside of them are cards i made in photoshop.

    How would i randomize these pictureboxes now...?
    Even though it's not really the right question, I'll answer that anyway. You already have everything you need in the CodeBank threads I've already directed you to. If you have 52 Images and 52 PictureBoxes then you would put the Images in a list and then randomise it exactly as I demonstrate in one of my CodeBank threads. You can put those randomised Images into an array by calling ToArray on the result of OrderBy and you can put the PictureBoxes into an array too. Tada! You have two arrays each with 52 elements. You can now use a For loop to assign each Image in one array to the Image property of the PictureBox at the same index in the other array.

    You seem determined to look at what you're doing as some special case that is somehow fundamentally different to other such cases. It's not. I've shown you how to randomise a list and I've shown you how to make unique, random selections from a list. What that list contains and what those items will be used for is COMPLETELY IRRELEVANT to the act of randomising them.

    If you want to make this more realistic then would not be showing 52 cards at the same time. What you would more likely do would be to store your card objects in a list and then "shuffle" them, which is exactly what the randomising techniques that I've demonstrated correlate to. Just like a real card game, you would then "deal" the cards, which would involve getting a card object from the randomised list and putting into another list that represents a player's hand. For example, here's some code that shuffles a deck of Card objects and deals them out to four players, five cards to a player:
    vb.net Code:
    1. Private rng As New Random
    2.  
    3. Private Sub InitiateGame()
    4.     Dim deck = GetShuffledDeck()
    5.     Dim hand1 As New List(Of Card)
    6.     Dim hand2 As New List(Of Card)
    7.     Dim hand3 As New List(Of Card)
    8.     Dim hand4 As New List(Of Card)
    9.  
    10.     Deal(deck, 5, hand1, hand2, hand3, hand4)
    11.  
    12.     '...
    13. End Sub
    14.  
    15. Private Function GetShuffledDeck() As List(Of Card)
    16.     Dim deck = Enumerable.Range(1, 52).Select(Function(i) New Card).ToList()
    17.  
    18.     ShuffleDeck(deck)
    19.  
    20.     Return deck
    21. End Function
    22.  
    23. Private Sub ShuffleDeck(deck As List(Of Card))
    24.     Dim shuffledDeck = deck.OrderBy(Function(c) Me.rng.NextDouble()).ToArray()
    25.  
    26.     For i = 0 To shuffledDeck.GetUpperBound(0)
    27.         deck(i) = shuffledDeck(i)
    28.     Next
    29. End Sub
    30.  
    31. Private Sub Deal(deck As List(Of Card), cardCount As Integer, ParamArray hands As List(Of Card)())
    32.     For i = 1 To cardCount
    33.         For Each hand In hands
    34.             Dim card = deck(0)
    35.  
    36.             deck.RemoveAt(0)
    37.             hand.Add(card)
    38.         Next
    39.     Next
    40. End Sub
    That's a bit of a simplification but, again, it shows how your specific case is inherently based on the general case. You start with the general case and then you add and modify details to match your particular needs.

  13. #13

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    Ugh, I really want to make this game but I don't understand at all what you guys are teaching me.

    It's like trying to teach me calculus even though I'm in grade 3.

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    I'd be inclined to say that you're having trouble with the LINQ part, which is something that you would not have encountered before, except that my CodeBank on Unique Random Selections doesn't include any LINQ and was, in fact, written before LINQ even existed. Using that thread (http://www.vbforums.com/showthread.p...ns-from-a-List) as a basis, what exactly is your issue? For instance, if you had a deck of cards, what exactly is stopping you using that code to select, say, 5 cards at random from that deck to make a hand?

  15. #15

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: I need help with my Texas HoldEm program.

    I don't understand a lot of what the code is doing. I am not that experienced with VB.

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by Flavor Flav View Post
    I don't understand a lot of what the code is doing. I am not that experienced with VB.
    The code is about as simple as it can be for what it does and it has comments all through it so I'm afraid that, if you don't understand it and you can tell me what you don't understand, then I can only conclude that what you're trying to achieve is beyond your capabilities at present and you should try something easier.

  17. #17
    New Member
    Join Date
    Nov 2015
    Posts
    14

    Re: I need help with my Texas HoldEm program.

    In the code sample you give is there a away of using an image list for picture boxes?

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: I need help with my Texas HoldEm program.

    Quote Originally Posted by nmagner View Post
    In the code sample you give is there a away of using an image list for picture boxes?
    There are certain circumstances in which you must use an ImageList, e.g. with a ListView. With a PictureBox though, if you were to use an ImageList, there's no direct connection between the two so you would have to manually retrieve the Image from the ImageList and assign it to the Image property of the PictureBox. As such there's not really any great advantage to using an ImageList so I wouldn't. The only thing it does for you is enable you to populate it at design time rather than run time, if that's what you want. I would tend to just use a List(Of Image) or Image array populated at run time. You'd then use that in exactly the same way as you would the Images collection of an ImageList.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width