Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:37:14+00:00 2026-06-18T09:37:14+00:00

Odd little project I am working on. Before you answer, yes, I know that

  • 0

Odd little project I am working on. Before you answer, yes, I know that vbscript is probably the worst language to use for this.

I need help determining what each player has. Each card has a unique number (which I ‘translate’ into it’s poker value with a ♥♦♣♠ next to it). For example:

A♥ = 0
2♥ = 1
3♥ = 2
...

and so on. I need help determining what hand I have. I have thought of a few ways. The first is using the delta between each card value. For example, a straight would be:

n
n +/- (1+ (13 * (0 or 1 or 2 or 3)))
n +/- (2 + (13 * (0 or 1 or 2 or 3 )))
... 

and so on. For example cards 3, 3+1+0, 3+2+13, 3+3+(13*3), 3+4+(13*2)

would give me:
4♥ 5♥ 6♦ 7♠ 8♣

My questions is, should I attempt to use regex for this? What is the best way to tell the computer what hand he has without hardcoding every hand?

EDIT: FULL CODE HERE: https://codereview.stackexchange.com/questions/21338/how-to-tell-the-npc-what-hand-it-has

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:37:15+00:00Added an answer on June 18, 2026 at 9:37 am

    Poker hands all depend on the relative ranks and/or suits of cards.

    I suggest writing some utility functions, starting with determining a rank and suit.

    So a card in your representation is an int from 0..51. Here are some useful functions (pseudo-code):

    // returns rank 0..12, where 0 = Ace, 12 = King
    getRank(card) {
        return card % 13;
    }
    
    
    // returns suit 0..3, where 0 = Heart, 1 = Diamond, 2 = Club, 3 = Spade
    getSuit(card) {
        return card / 13;  // or floor(card / 13) if lang not using floored division
    }
    

    Now that you can obtain the rank and suit of a set of hands you can write some utilities to work with those.

    // sort and return the list of cards ordered by rank
    orderByRank(cards) {
        // ranked = []
        // for each card in cards:
        //   get the rank
        //   insert into ranked list in correct place
    }
    
    // given a ranked set of cards return highest number of identical ranks
    getMaxSameRank(ranked) {
        duplicates = {}  // map / hashtable
        for each rank in ranked {
            duplicates[rank] += 1
        }
        return max(duplicates.vals())
    }
    
    // count the number of cards of same suit
    getSameSuitCount(cards) {
        suitCounts = {} // a map or hashtable if possible
        // for each card in cards:
        //   suitCounts{getSuit(card)} += 1
        // return max suit count (highest value of suitCounts)
    }
    

    You will need some more utility functions, but with these you can now look for a flush or straight:

    isFlush(cards) {
        if (getSameSuitCount(cards) == 5) {
            return true
        }
        return false
    }
    
    isStraight(cards) {
        ranked = orderByRank(cards)
        return ranked[4] - ranked[0] == 3 && getMaxSameRank(ranked) == 1     
    }
    
    isStraightFlush(cards) {
        return isFlush(cards) && isStraight(cards)
    }
    

    And so on.

    In general, you will need to check each hand against the possible poker hands, starting with the best, working down to high card. In practice you will need more than that to differentiate ties (two players have a fullhouse, the winner is the player with the higher ranked three of a kind making their fullhouse). So you need to store a bit more information for ranking two hands against one another, such as kickers.

    // simplistic version
    getHandRanking(cards) {
      if (isStraightFlush()) return STRAIGHT_FLUSH
      if (isQuads()) return QUADS
      ...
      if (isHighCard) return HIGH_CARD
    }
    
    getWinner(handA, handB) {
      return max(getHandRanking(handA), getHandRanking(handB))
    }
    

    That would be my general approach. There is a wealth of information on poker hand ranking algorithms out there. You might enjoy the Unit 1: Winning Poker Hands from Peter Norvig’s Udacity course Design of Computer Programs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on this legacy project that has a rather odd setup that I'm
This one might be a little odd, but I'm working around a system already
I've got an odd little dilemma in this jQuery slideshow plugin that I am
I know this may sound a little odd, but is it possible to create
I'm currently working on a JavaScript project that's a little larger than what I'm
This is a little odd but I need to know all subclasses of a
I know that question sounds a little odd but i will try to explain
I ran into something a little odd this morning and thought I'd submit it
I'm just diving into WPF and find this a little odd and frustrating to
This might be a little bit odd question, but Im trying to figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.