
    Ii
                        S r SSKJr  SSKJrJrJr  SSKJr  \" S5      r	          SS jr
          SS jr            SS	 jrg
)z(Shared showdown helpers for poker games.    )annotations)CallableIterableTypeVar   )order_after_buttonTPlayerc                \   ^^ [        U 5      S::  a  U $ [        X5      m[        U UU4S jS9$ )aD  Order winners deterministically by button position.

Args:
    winners: Winner objects to order.
    active_ids: Active player ids in current hand order.
    button_id: Current dealer/button player id.
    get_id: Callable to extract player id from winner object.

Returns:
    Winners ordered by position after the button.
r   c                `   > T" U 5      T;   a  TR                  T" U 5      5      $ [        T5      $ Nindexlenpget_idorders    ?c:\Users\dbart\PlayPalace11\server\game_utils\poker_showdown.py<lambda>)order_winners_by_button.<locals>.<lambda>!   s,    e9Ku{{6!95[QTUZQ[[    key)r   r   sorted)winners
active_ids	button_idr   r   s      `@r   order_winners_by_buttonr      s3    " 7|qz5E[ r   c                L   ^^ [        X5      m[        [        U 5      UU4S jS9$ )a6  Sort players by showdown order (after button).

Args:
    players: Players to sort.
    active_ids: Active player ids in current hand order.
    button_id: Current dealer/button player id.
    get_id: Callable to extract player id from player object.

Returns:
    Ordered list of players for showdown reveal.
c                `   > T" U 5      T;   a  TR                  T" U 5      5      $ [        T5      $ r   r   r   s    r   r   +sort_players_for_showdown.<locals>.<lambda>8   s,    vayE?QU[[%;%aWZ[`Wa%ar   r   )r   r   list)playersr   r   r   r   s      `@r   sort_players_for_showdownr$   %   s&    " z5EWa r   c                    [        XX#5      n/ nU H&  nU" U5      u  pUR                  U" U5      X45        M(     UR                  S SS9  U$ )a  Format showdown lines and sort by score.

Args:
    players: Players to include in showdown.
    active_ids: Active player ids in current hand order.
    button_id: Current dealer/button player id.
    get_id: Callable to extract player id from player object.
    format_fn: Callable returning (localized line, score tuple).

Returns:
    List of (player_id, line, score) sorted by score descending.
c                    U S   $ )N    )items    r   r   'format_showdown_lines.<locals>.<lambda>T   s    Qr   T)r   reverse)r$   appendsort)
r#   r   r   r   	format_fnorderedlinesr   linescores
             r   format_showdown_linesr3   <   sW    & (YOGMOElfQi-.  
JJ'J6Lr   N)
r   list[TPlayer]r   	list[str]r   
str | Noner   Callable[[TPlayer], str]returnr4   )
r#   Iterable[TPlayer]r   r5   r   r6   r   r7   r8   r4   )r#   r9   r   r5   r   r6   r   r7   r.   zICallable[[TPlayer], tuple[tuple[str, dict], tuple[int, tuple[int, ...]]]]r8   z?list[tuple[str, tuple[str, dict], tuple[int, tuple[int, ...]]]])__doc__
__future__r   typingr   r   r   poker_stater   r	   r   r$   r3   r(   r   r   <module>r>      s    . " . . +
)
  %	
 2  %	
 .  %	
 Y Er   