0

Hi I've written all kinds of programs for gambling like roulette blackjack and now I'm doing Poker

I'm doing 5 card draw and trying to determine if my hand is a straight before the draw

I'm a simple programmer and I've had no schooling. Right now I'm trying to determine a straight by finding the highest and lowest card and seeing if cards match

if the highest card is = the lowest card + 5 and there are no reapeating numbers in the hand shouldn't this accurately find a straight?

My code is very basic and long so I won't post it here I do everything brute force method to find the highest/lowest and matching cards

I think this is the simpliest way I've found but it may be too simple

1 Answers1

0

both solutions work.

I would do something like this.

    Dim cards As List(Of Integer) = New List(Of Integer)
    Dim isStraight as Boolean = False

    cards.Add(1)
    cards.Add(3)
    cards.Add(2)
    cards.Add(4)
    cards.Add(5)

    Dim areMultipleNumbersInList As Boolean = cards.GroupBy(Function(x) x).Any(Function(x) x.Count() > 1)

    Dim max As Integer = cards.Max()
    Dim min As Integer = cards.Min()

    If (max - min = 4 AndAlso Not areMultipleNumbersInList) Then
        isStraight = True
    End If

You need .NET 4.0 in order to use the Enumerable.Max/Min Methods. If you need a solution for another .NET Framework let me know

EDIT: added areMultipleNumbersInList to code

Silvio Marcovic
  • 495
  • 4
  • 18
  • Thanks for assuring me that my method works there must be something wrong with my code because right now im getting about 1% straights and wikiepedia says I should get 0.39% straights when randomly drawing 5 cards and ranking them as a straight – Matthew Mahoney Oct 24 '13 at 05:29
  • with the method i posted royal flush and straight flush would be counted as a straight as well. but they do not describe the offset you mentioned. But don't forget to consider it (: maybe you have a bug somewhere else, or you are calculating wrong. i forget to check for double cards in my code, thats important. you posted min + 5 = max but actually its + 4! – Silvio Marcovic Oct 24 '13 at 07:25