
    Ii                    l    S SK Jr  S SKJrJr  S SKJr  \ " S S\5      5       r\ " S S\5      5       rg)	    )annotations)	dataclassfield)DataClassJSONMixinc                  :    \ rS rSr% SrS\S'   \" \S9rS\S'   Sr	g	)
PokerPot   zRepresent a single main/side pot.

Attributes:
    amount: Total chips in this pot.
    eligible_player_ids: Players eligible to win this pot.
intamountdefault_factoryset[str]eligible_player_ids N)
__name__
__module____qualname____firstlineno____doc____annotations__r   setr   __static_attributes__r       :c:\Users\dbart\PlayPalace11\server\game_utils\poker_pot.pyr   r      s     K$)#$>>r   r   c                  x    \ rS rSr% Sr\" \S9rS\S'   \" \	S9r
S\S'   SS jrSS	 jrSS
 jrSS jrSS jrSrg)PokerPotManager   zTrack contributions and compute main/side pots.

Attributes:
    contributions: Player id -> chips contributed.
    folded: Player ids that have folded.
r   zdict[str, int]contributionsr   foldedc                l    U R                   R                  5         U R                  R                  5         g)z)Clear all contributions and folded state.N)r   clearr   selfs    r   resetPokerPotManager.reset!   s$      "r   c                j    US::  a  gU R                   R                  US5      U-   U R                   U'   g)z;Add chips to a player's contribution if amount is positive.r   N)r   get)r#   	player_idr   s      r   add_contribution PokerPotManager.add_contribution&   s4    Q;(,(:(:(>(>y!(Lv(U9%r   c                :    U R                   R                  U5        g)z,Mark a player as folded for pot eligibility.N)r   add)r#   r(   s     r   mark_foldedPokerPotManager.mark_folded,   s    	"r   c                H    [        U R                  R                  5       5      $ )z0Return the total chips across all contributions.)sumr   valuesr"   s    r   	total_potPokerPotManager.total_pot0   s    4%%,,.//r   c                   U R                   R                  5        Vs/ s H  oS:  d  M
  UPM     nnU(       d  / $ [        [        U5      5      n/ nSnU H  nU R                   R	                  5        VVs/ s H  u  pqX:  d  M  UPM     nnnXe-
  [        U5      -  n	U	S::  a  UnMR  U Vs1 s H  owU R                  ;  d  M  UiM     n
nUR                  [        XS95        UnM     U$ s  snf s  snnf s  snf )z*Compute main/side pots from contributions.r   )r   r   )	r   r1   sortedr   itemslenr   appendr   )r#   amtamountslevelspotsprevlevelpidcontributors
pot_amounteligibles              r   get_potsPokerPotManager.get_pots4   s    "&"4"4";";"=I"=3q3"=IIG%!E040B0B0H0H0J[0JHCclC0JL[,#l*;;JQ'3N|$++7M|HNKK
QRD  ! J \
 Os"   	C*C*5C/C/+C5C5r   N)returnNone)r(   strr   r
   rE   rF   )r(   rG   rE   rF   )rE   r
   )rE   zlist[PokerPot])r   r   r   r   r   r   dictr   r   r   r   r$   r)   r-   r2   rC   r   r   r   r   r   r      sA     %*$$?M>?S1FH1
V#0r   r   N)	
__future__r   dataclassesr   r   mashumaro.mixins.jsonr   r   r   r   r   r   <module>rL      sF    " ( 4 	?! 	? 	? 0( 0 0r   