Thread: Finding straight draws in poker

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    25

    Finding straight draws in poker

    Moderator note: This thread was moved as it was an inapproprioate reply that resurrected Finding a 'straight' in poker.

    I'm reviving this thread as I'm in the process of trying to find straights and straight draws on a board.

    The latest code in this thread works great if I want to find a straight in any way, but what I really want to find is straight draws. Both inside and outside straightdraws.
    Eg. a board consisting of: "2h3c4h" is a straightdraw, and this obviously I can find. But if the board looks like: "2h4c5h" (an inside straightdraw) I'm not sure how to handle it.

    My mind is blank and I can not seem to come up with a solution.
    Anyone who has any ideas?

    Code:
    /* straight.c */
    
    #define MAXN        13
    #define CARDSINHAND  7
    #define IN_A_ROW     5
    
    int is_straight( int* cards, int ncards ) {
    
        int seen[ MAXN ];
        int in_a_row;
        int i;
    
        for (i = 0; i < MAXN; i++) seen[ i ] = 0;    /* zero "seen" array */
    
        for (i = 0; i < ncards; i++)                 /* set values seen to non-zero */
            seen[ cards[ i ] - 1 ]++;
    
        in_a_row = 0;                                /* see if there are IN_A_ROW in a row */
        for (i = 0; i < MAXN; i++) {
            if (seen[ i ]) {
                if (++in_a_row >= IN_A_ROW)
                    return 1;
            }
            else
                in_a_row = 0;
        }
        return 0;
    }
    
    int main() {
        int c[] = { 4, 6, 3, 5, 7, 9, 11 };
        int d[] = { 4, 6, 2, 5, 7, 9, 11 };
        printf( "c: " );
        printf( is_straight( c, CARDSINHAND ) ? "yes" : "no" );
        printf( "\nd: " );
        printf( is_straight( d, CARDSINHAND ) ? "yes" : "no" );
        printf( "\n" );
    }
    Last edited by laserlight; 03-19-2010 at 11:18 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you loop through the hand, from low card - 1 to high card + 1, and assign a temporary card to the looping temp card value, and put it into the hand, you will find the "straight draw", possibilities.

    Look up tables are faster, but poker is not a game of blinding speed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a Poker Game
    By krazyxazn in forum C Programming
    Replies: 4
    Last Post: 04-07-2009, 06:45 PM
  2. Finding a 'straight' in poker.
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-18-2008, 05:16 AM
  3. Help!For poker game simulation
    By tx1988 in forum C++ Programming
    Replies: 24
    Last Post: 05-25-2007, 09:59 PM
  4. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM