
    Ii                     |    S r SSKJrJr  SSKJr  SSKJr  SSKJr  \ " S S\5      5       r	\ " S S	\5      5       r
g
)z
Game result dataclass for unified game end handling and statistics.

Provides a structured way to capture game results, enabling:
- Consistent end screen presentation
- Database persistence for statistics
- Helper utilities for leaderboards and ratings
    )	dataclassfield)datetime)Any)DataClassJSONMixinc                   F    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\\S'   Sr	g	)
PlayerResult   zPlayer result in a completed game.

Attributes:
    player_id: Player UUID.
    player_name: Display name.
    is_bot: True for bot players.
    is_virtual_bot: True for server-level bots (included in stats).
	player_idplayer_nameis_botFis_virtual_bot N)
__name__
__module____qualname____firstlineno____doc__str__annotations__boolr   __static_attributes__r       <c:\Users\dbart\PlayPalace11\server\game_utils\game_result.pyr	   r	      s#     NL ND r   r	   c                      \ rS rSr% Sr\\S'   \\S'   \\S'   \" \	S9r
\	\   \S'   \" \S9r\\\4   \S'   \ SS\S\S
\	\\\\4      S\\\4   S	-  SS 4
S jj5       rS\4S jrS\4S jrS\	\   4S jrS\	\   4S jrS\4S jrSrg	)
GameResult"   z`Structured result of a completed game.

Game-specific data goes in custom_data for flexibility.
	game_type	timestampduration_ticks)default_factoryplayer_resultscustom_dataNplayersreturnc                     U " U[         R                  " 5       R                  5       UU VVVs/ s H  u  pVn[        XVUS9PM     snnnU=(       d    0 S9$ s  snnnf )a2  
Convenience factory for creating a GameResult.

Args:
    game_type: The game type identifier (e.g., "pig", "farkle")
    duration_ticks: Game duration in ticks
    players: List of (player_id, player_name, is_bot) tuples
    custom_data: Game-specific result data

Returns:
    A new GameResult instance
)r   r   r   )r   r   r    r"   r#   )r   now	isoformatr	   )clsr   r    r$   r#   pidnamer   s           r   createGameResult.create/   sa    ( lln..0) *1)0%Cv sVL)0 $)r	
 		
s   Ac                      U R                   S-  $ )z3Get game duration in seconds (20 ticks = 1 second).g      4@)r    selfs    r   get_duration_secondsGameResult.get_duration_secondsN   s    ""T))r   c                 X    [        U R                  5       5      nUS-  nUS-  nU SUS 3$ )z7Get game duration as a formatted string (e.g., '5:32').<   :02d)intr1   )r0   total_secondsminutessecondss       r   get_duration_formatted!GameResult.get_duration_formattedR   s<    D55782%"$!GC=))r   c                 X    U R                    Vs/ s H  oR                  PM     sn$ s  snf )zGet list of all player IDs.)r"   r   r0   ps     r   get_player_idsGameResult.get_player_idsY   s$    %)%8%89%8%8999s   'c                     U R                    Vs/ s H2  oR                  (       a  UR                  (       d  M&  UR                  PM4     sn$ s  snf )zCGet list of human and virtual bot player IDs (excludes table bots).)r"   r   r   r   r>   s     r   get_human_player_idsGameResult.get_human_player_ids]   s4    %)%8%8]%8AL\L\%8]]]s
   %AAc                 :    [        S U R                   5       5      $ )z7Check if any human or virtual bot players participated.c              3   h   #    U  H(  oR                   (       + =(       d    UR                  v   M*     g 7fN)r   r   ).0r?   s     r   	<genexpr>/GameResult.has_human_players.<locals>.<genexpr>c   s$     Q=Pxx<31#3#33=Ps   02)anyr"   r/   s    r   has_human_playersGameResult.has_human_playersa   s    QT=P=PQQQr   r   rG   )r   r   r   r   r   r   r   r7   r   listr"   r	   dictr#   r   classmethodtupler   r,   floatr1   r;   r@   rC   rL   r   r   r   r   r   r   "   s    
 NN).t)DND&D"'"=Kc3h= .2

 
 eCdN+,	

 #s(^d*
 

 
<*e ** *:S	 :^d3i ^R4 Rr   r   N)r   dataclassesr   r   r   typingr   mashumaro.mixins.jsonr   r	   r   r   r   r   <module>rV      sV    )   4 !% ! !  @R# @R @Rr   