11"""Hand evaluation logic."""
22
3+ import functools
34from collections import Counter
45from collections .abc import Callable
56from typing import TYPE_CHECKING
1213 from .hand import Hand
1314
1415
16+ @functools .total_ordering
1517class HandEvaluation :
1618 """
1719 Evaluator and Result container for a poker hand.
@@ -156,7 +158,8 @@ def _check_three_of_a_kind(self, ctx: _EvaluationContext) -> bool:
156158 for _ , c in reversed (ctx .rank_indexed )
157159 if c .rank == ctx .ranks_by_freq [0 ]
158160 )
159- self .discard_indices = [idx for idx , _ in ctx .rank_indexed [0 :3 ]]
161+ keep_rank = ctx .ranks_by_freq [0 ]
162+ self .discard_indices = [i for i , c in enumerate (ctx .cards ) if c .rank != keep_rank ]
160163 return True
161164
162165 def _check_two_pair (self , ctx : _EvaluationContext ) -> bool :
@@ -183,7 +186,8 @@ def _check_pair(self, ctx: _EvaluationContext) -> bool:
183186 for _ , c in reversed (ctx .rank_indexed )
184187 if c .rank == ctx .ranks_by_freq [0 ]
185188 )
186- self .discard_indices = [idx for idx , _ in ctx .rank_indexed [0 :3 ]]
189+ keep_rank = ctx .ranks_by_freq [0 ]
190+ self .discard_indices = [i for i , c in enumerate (ctx .cards ) if c .rank != keep_rank ]
187191 return True
188192
189193 def _check_partial_straight (self , ctx : _EvaluationContext ) -> bool :
0 commit comments