How can I find the highest poker hand from a 9 card hand between 4 players?

I've tried to look through several sources online and they all deal with 5 card and 7 card hands. Also, I'm not really looking for the code, I'll try to do that on my own (although perhaps if you're willing, I'm looking to implement this in either Python or JavaScript). I just want someone to explain to me the steps involved in finding such a hand (using pseudocode).

Basically, what I'm asking is: How can I find the highest poker hand from a 9 card hand between 4 players?

Should I just assign all the highest poker hand numbers in ranking and then parsing through each player's hand and see if their hand contains that number? That seems a little tedious and I'm not sure that's the right way to do it.

Also, I noticed other hand evaluators are set for optimization and some count the number of bits per card played which confused me.

EDIT: Here's the game I'm working on:

It's a game with a 6x6 grid in which four players pick up cards where wherever their player piece lands on, they pick up that card. Cards are from a standard 52 card deck but the cards are face up and only 36 randomly selected cards from the deck are used.

Eventually, toward the end of the game, the player could at most contain 9 cards in their hands.

The way to win the game is to contain the highest poker hand amongst the four players around you.

So, essentially, if you have a royal flush and everyone else has a pair or a straight, they lose.

In another game where the highest hand is a straight and the rest have a three of a kind or a two pair, then the person with the straight wins.

So, highest poker hand is the hand highest relative to other player's hand. It is the hand that has the highest ranking cards among 4 players.

poker hand is just regular hand that may or may not be the highest in rank.


There are only 126 possible 5-cards combinations for a 9-cards hand. So you can just iterate over them to find the highest. itertools.combinations(9_cards, 5) can generate all of them.

To find the highest, a trivial implement could be define a function which gives a hand a score. Then use this function as key: max(all_5_cards_hands, key=hand_score)

You can use a tuple to represent the score. Leading by hand ranking and followed by card rankings.

An example:

STRAIGHT_FLUSH = 9
...
TWO_PAIR = 2
ONE_PAIR = 1
HIGH_CARD = 0

hand_score('A7532')  # I omit suits here
# => (HIGH_CARD, 14,7,5,3,2)
hand_score('KK333')
# => (FULL_HOUSE, 3, 13)
hand_score('33444')
# => (FULL_HOUSE, 4, 3)
hand_score('AKQJ0')
# => (STRAIGHT, 14)

# Tuples can be easily compared:
(HIGH_CARD, 14,7,5,3,2) < (STRAIGHT, 14)
# => True
链接地址: http://www.djcxy.com/p/40198.html

上一篇: 卡拼图的算法解决方案

下一篇: 我如何从4名牌手之间的9张牌中找到最高的牌手?