
    Ii                         S r SSKJrJr  S\\   S\S\\\      4S jr SS\\   S\S	\S\\\      4S
 jjrS\\\      S\\   4S jr	 SS\\   S\S	\S\
S\
4
S jjrg)zg
Capture logic for Scopa game.

Handles finding valid capture combinations and selecting the best one.
   )Card	card_namecardstargetreturnc                 ~   ^ ^^^ TS::  a  / $ / mS[         S[        [           S[         4UU UU4S jjmT" S/ S5        T$ )z-Find all subsets of cards that sum to target.    startcurrentcurrent_sumc                   > UT:X  a  TR                  [        U5      5        g UT:  a  g [        U [        T5      5       HC  nUR                  TU   5        T" US-   XTU   R                  -   5        UR                  5         ME     g )N   )appendlistrangelenrankpop)r
   r   r   i	backtrackr   resultsr   s       9c:\Users\dbart\PlayPalace11\server\games\scopa\capture.pyr   (find_subsets_with_sum.<locals>.backtrack   sr    & NN4=)uc%j)ANN58$a!eWE!HMM&ABKKM *    )intr   r   )r   r   r   r   s   ``@@r   find_subsets_with_sumr   
   sJ    {	 "G	 	tDz 	 	 	 aQNr   table_cards
card_valueescobac                     U(       a  SU-
  n[        X5      $ U  Vs/ s H  oDR                  U:X  d  M  UPM     nnU(       a  U Vs/ s H  oD/PM     sn$ [        X5      $ s  snf s  snf )a  
Find all valid capture combinations for a card value.

Args:
    table_cards: Cards currently on the table.
    card_value: The rank of the card being played.
    escoba: If True, use escoba rules (sum to 15).

Returns:
    List of possible capture combinations (each is a list of cards).

For standard scopa: rank match first, then sum combinations.
For escoba: find combinations that sum to 15 (including played card).
   )r   r   )r   r   r   r   crank_matchess         r   find_capturesr$       sh    " j$[99 $/G;a&&J2F;G!-.AC..$[== H /s   A A A%capturesc                 0    U (       d  / $ [        U [        S9$ )z%Select the best capture (most cards).)key)maxr   )r%   s    r   select_best_capturer)   ?   s    	xS!!r   cardlocalec                     [        XR                  U5      nU(       d  g[        U5      n[        U5      S:X  a  S[	        US   U5       3$ S[        U5       S3$ )a1  
Get a hint about what cards would be captured.

Args:
    table_cards: Cards currently on the table.
    card: The card being considered for play.
    escoba: If True, use escoba rules.
    locale: Locale for card names.

Returns:
    Hint string like " -> 7 of Coins" or " -> 3 cards", or empty string.
 r   z -> r	   z cards)r$   r   r)   r   r   )r   r*   r   r+   r%   bests         r   get_capture_hintr/   F   s[     [))V<Hx(D
4yA~iQ0122c$i[''r   N)F)Fen)__doc__game_utils.cardsr   r   r   r   r   boolr$   r)   strr/    r   r   <module>r6      s    0d S T$t*=M . >C>d>),>6:>	$t*>>"$tDz"2 "tDz " NR(d(#'(15(GJ((r   