4 Replies - 342 Views - Last Post: 14 July 2014 - 01:10 AM Rate Topic: -----

#1 MORITSUKI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 12-July 14

Need help with a poker hand code

Posted 13 July 2014 - 07:51 PM

Here is what I have so far
Public Class PokerHands

    Sub FourOfaKind() 'Four of a Kind

    End Sub

    Sub ThreeOfaKind() 'Three of a Kind

    End Sub

    Sub Pair() 'A pair

    End Sub

    Sub Flush() 'A flush

    End Sub

    Sub Straight() ' A straight, if ace is low

    End Sub

    Sub AceStraight() 'An ace-high straight; 10, J, Q, K, A

    End Sub


    Private Sub InputDisplay_TextChanged(ByVal sender As Object, e As EventArgs) Handles InputDisplay.TextChanged
        Dim hands(4, 13) As String
        Dim SuiteValue(4) As String 'Suite
        SuiteValue(0) = "S" 'Spade
        SuiteValue(1) = "D" 'Diamond
        SuiteValue(2) = "C" 'Club
        SuiteValue(3) = "H" 'Hearts
        Dim FaceValue(13) As String 'Face value
        FaceValue(0) = "A" 'Ace
        FaceValue(1) = "2" '2
        FaceValue(2) = "3" '3
        FaceValue(3) = "4" '4
        FaceValue(4) = "5" '5
        FaceValue(5) = "6" '6
        FaceValue(6) = "7" '7
        FaceValue(7) = "8" '8
        FaceValue(8) = "9" '9
        FaceValue(9) = "10" '10
        FaceValue(10) = "J" 'J
        FaceValue(11) = "Q" 'Q
        FaceValue(12) = "K" 'K


    End Sub

    Private Sub Button1_Click(ByValsender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

End Class


I will have to take an input from the user for 5 cards, let say "aH, AS, 2D, 3C, 4C" which correspond to ace of hearts, ace of spades, two of diamonds, three of clubs, and four of clubs. My question is how can the program, after getting the inputs from the user, to determine the suite and face value from the array 'hands'? I have been thinking of using the IndexOf function (I have a sub program to remove the "," and " " which is working).

Thank you :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with a poker hand code

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9479
  • View blog
  • Posts: 35,743
  • Joined: 12-June 08

Re: Need help with a poker hand code

Posted 13 July 2014 - 09:18 PM

Why not just use an array of 52 ints? Impose the logical constraints on it.. so that 0-12 is ace through king of spades, 13-25 hearts, etc?
Was This Post Helpful? 0
  • +
  • -

#3 MORITSUKI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 12-July 14

Re: Need help with a poker hand code

Posted 13 July 2014 - 10:08 PM

Well for this one the user will input the card value in the text box, let say "let say "aH, AS, 2D, 3C, 4C" which correspond to ace of hearts, ace of spades, two of diamonds, three of clubs, and four of clubs. I have a sub program that will make the string change to "AH,AS,2D,3C,4C" so basically the program will need to read the combination of OfIndex"0,2", "3,2", "6,2", "9,2" and "12,2", if my logic is correct.
Was This Post Helpful? 0
  • +
  • -

#4 MORITSUKI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 12-July 14

Re: Need help with a poker hand code

Posted 13 July 2014 - 11:31 PM

What I don't understand is how can I code so that the program will take in the user input and then recognize the card using the FaceValue and SuitsValue Array. Sorry if I am asking stupid questions here but I have been reading my textbook but I still don't get a clue. :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#5 MORITSUKI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 12-July 14

Re: Need help with a poker hand code

Posted 14 July 2014 - 01:10 AM

I have rewrite my code

Public Class PokerHands


    Function InputFormat(ByVal MyString As String) As String 'Function to remove space and change characters to UPPER CASE
        MyString = InputDisplay.Text.Replace(" ", "").ToUpper
        Return MyString
    End Function

    Sub FourOfaKind() 'Four of a Kind

    End Sub

    Sub ThreeOfaKind() 'Three of a Kind

    End Sub

    Sub Pair() 'A pair

    End Sub

    Sub Flush() 'A flush

    End Sub

    Sub Straight() ' A straight, if ace is low

    End Sub

    Sub AceStraight() 'An ace-high straight; 10, J, Q, K, A

    End Sub


    Private Sub InputDisplay_TextChanged(ByVal sender As Object, e As EventArgs) Handles InputDisplay.TextChanged



    End Sub

    Private Sub Button1_Click(ByValsender As Object, e As EventArgs) Handles Button1.Click
        Dim hands(4, 13) As Integer 'Example: If (2,11) = 1 then is JD
        Dim SuitsValue(4) As String 'Suite
        SuitsValue(0) = "" 'Not using
        SuitsValue(1) = "S" 'Spade
        SuitsValue(2) = "D" 'Diamond
        SuitsValue(3) = "C" 'Club
        SuitsValue(4) = "H" 'Hearts
        Dim FaceValue(13) As String 'Face value
        FaceValue(0) = "" 'Not using
        FaceValue(1) = "A" 'Ace
        FaceValue(2) = "2" '2
        FaceValue(3) = "3" '3
        FaceValue(4) = "4" '4
        FaceValue(5) = "5" '5
        FaceValue(6) = "6" '6
        FaceValue(7) = "7" '7
        FaceValue(8) = "8" '8
        FaceValue(9) = "9" '9
        FaceValue(10) = "10" '10
        FaceValue(11) = "J" 'J
        FaceValue(12) = "Q" 'Q
        FaceValue(13) = "K" 'K
        'Splits user-entered string into separate strings using empty space as indicator

        Dim fiveCard As String = InputDisplay.Text
        Dim split As String() = fiveCard.Split(New Char() {" "c})

        Dim cardSuits As String = "HSDC"
        Dim cardValues As String = "A23456789JQK"

        Dim card As String = fiveCard
        Dim value, suite As Integer
        Dim valueChar As String = card.Substring(0, 1)
        Dim suiteChar As String = card.Substring(1, 1)
        value = cardValues.IndexOf(valueChar) + 1
        suite = cardSuits.IndexOf(suiteChar) + 1
        hands(value, suite) = 1

    End Sub


End Class



Now my question would be, how should I code it that the result can be displayed onto the listbox "OutputDisplay"? I know the code to add outputDisplay.Items.Add but I am not sure what to put inside the ().

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1