aboutsummaryrefslogtreecommitdiff
path: root/poker/models.py
diff options
context:
space:
mode:
authorPaul Harrison <paul@harrison.sh>2022-11-18 21:00:37 +0000
committerPaul Harrison <paul@harrison.sh>2022-12-15 16:02:14 +0000
commitd924e39608861362e08c5e3706ff46a7a1af919b (patch)
tree93a3db318a4f46fed2a545afea8474f7193d7308 /poker/models.py
parent5393e7b79939f7da36d55570af3374cef2db2d51 (diff)
feat: Get hand rank
Method to get rank of a given hand.
Diffstat (limited to 'poker/models.py')
-rw-r--r--poker/models.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/poker/models.py b/poker/models.py
index 1d6af05..bbb474c 100644
--- a/poker/models.py
+++ b/poker/models.py
@@ -1,5 +1,7 @@
from __future__ import annotations
+from collections import Counter
+
from pydantic import BaseModel, validator
from poker.constants import Rank, Suit, Value
@@ -43,6 +45,11 @@ class Hand(BaseModel):
raise ValueError("Hand must have five cards.")
return cards
+ @property
+ def value_counts(self) -> list[tuple[Value, int]]:
+ """Return count of each card value in hand."""
+ return Counter([card.value for card in self.cards]).most_common()
+
class RankedHand(Hand):
"""Ranked hand domain model class."""