I am fairly new to Python, but trying to make a poker game. How do I determine the winner? I have 'scored' the hands 1-8, and given sub-scores for the high card, but how do I compare the scores of 4 players and then in the event of a tie, compare the sub-scores of the tied players? I have been contimplating this for 3 days now, and still come up blank. I wish I could post the code I have so far, but it is simply an empty def statement. Does anyone know a simple algorithm for this? Or even a long drawn out process would be fine at this point. Thanks.

That's an interesting challenge... If it were me I would use a two-tiered scoring system, whereby you could assign a value to the hand itself, ie:

high card = 1
pair = 2
two pair = 3
three of kind = 4
etc...

Then, in the event of a tie, you'd need to compare the actual value of the hand. Do you get my meaning?

Is that what you were asking or am I misinterpreting your question?

Well, I assigned scores like you mentioned, "High card" = 1, "Pair" = 2..."4 of a Kind" = 7, "Straight Flush" = 8. And I assigned sub-values to the high card. "Ace" =13, "King" = 12..."2"=2. But I'm not sure how to write the script to compare them to determine the 'winner'. I thought of putting them into a list and using max(list), but then, how do I associate the high score with the player?

If I understand correctly, you want to have a strict order of poker hands. That means, there can be a tie only, when all the cards are the same, except the colour (pikk, tref ...)

The hand value can be a 6 member tuple:

  • First the formation value 0-9, poker twopairs etc...
  • Second the the value of the cards in the formation in descending order. In case of full, the 3 member part comes before (I think a 3xJ-2x10 full beats a 3x9-2xQ full). In case of a flush or straight beginning with ace, the ace comes at last (with value 1) etc ...
  • Third the values of the other cards in descending order.

So the compare function is simply the comparison of the value.

case 1: K,Q,10,8,2 (not the same colour)
value: 0,13,12,10,8,2

case 2: a,2,3,4,5 (not the same colour)
value 4,5,4,3,2,1

case 3: 10,10,10,J,J (not the same colour)
value 6,10,10,10,11,11

And so on...

I am not a big player, but I could not find the exact rules on the net.
I hope I have given some help with this.

This article has been dead for over six months. Start a new discussion instead.