
    Ii                      R   S r SSKJrJr  SSKrSSKJrJr  SSKJ	r	  SSK
JrJrJr  SS	KJr  SS
KJrJrJrJr  SSKJr  SSKJr  SSKJr  SSKJrJrJrJrJ r   SSK!J"r"J#r#J$r$J%r%  SSK&J'r'J(r(J)r)J*r*J+r+  \ " S S\5      5       r,\ " S S\5      5       r-\\	 " S S\5      5       5       r.g)zSorry game for PlayPalace.    )	dataclassfieldN   )GamePlayer)register_game   )Action	ActionSet
Visibility)	BotHelper)
BoolOptionGameOptions
MenuOptionoption_field)Localization)KeybindState   )choose_move)CaptureEvent	SorryMove
apply_movegenerate_legal_movesgenerate_split_options_for_pair)Classic00390RulesSorryRulesProfileget_rules_profile_by_idget_supported_profile_ids)SorryGameStateSorryPlayerStatebuild_initial_game_statediscard_current_carddraw_next_cardc                   6    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	g)	SorryPlayer%   zPlayer state for Sorry.   pawns_in_startr   pawns_in_home N)
__name__
__module____qualname____firstlineno____doc__r(   int__annotations__r)   __static_attributes__r*       6c:\Users\dbart\PlayPalace11\server\games\sorry\game.pyr%   r%   %   s    !NCM3r3   r%   c                       \ rS rSr% Sr\" \" SS\" \" 5       5      SSS.SS	S
S95      r	\
\S'   \" \" SSSSS95      r\\S'   \" \" SSSSS95      r\\S'   Srg)SorryOptions-   zConfigurable options for Sorry.classic_00390rules_profilez!sorry-rules-profile-classic-00390zsorry-rules-profile-a5065-core)r8   
a5065_corezsorry-option-rules-profilez!sorry-option-select-rules-profilez"sorry-option-changed-rules-profile)default	value_keychoiceschoice_labelslabelprompt
change_msgTauto_apply_single_movez#sorry-option-auto-apply-single-movez+sorry-option-changed-auto-apply-single-move)r;   r<   r?   rA   Ffaster_setup_one_pawn_outz&sorry-option-faster-setup-one-pawn-outz.sorry-option-changed-faster-setup-one-pawn-outr*   N)r+   r,   r-   r.   r/   r   r   listr   r9   strr1   r   rB   boolrC   r2   r*   r3   r4   r6   r6   -   s    )%#%245!D> /6;	
M3  $0.7D		
$D  '31:G		
't r3   r6   c                     ^  \ rS rSr% Sr\" \S9r\\   \	S'   \" \
S9r\
\	S'   Sr\\	S'   \" \S9r\\	S'   S	r\\	S
'   \S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       rSOS\S\S\S\4S jjrS\4S jrS\4S jrS\S\S-  4S jrS\S\4S jrS\S\S\4S jr S\S-  S\4S jr!S\S \"S\4S! jr# SPS\S"\S-  S#\S\$\\%4   4S$ jjr&S\S \"SS4S% jr'S&\S'\\(   SS4S( jr)S\S \"SS4S) jr*S\S\+S-  4S* jr,S\S\S\\"   4S+ jr-S\S\\"   4S, jr.S\S \"S\\(   4S- jr/SQS. jr0S\S\4S/ jr1S \"SS4S0 jr2SQS1 jr3S2\SS4S3 jr4S4S5.S6\SS4S7 jjr5S\SS4S8 jr6S\S\74S9 jr8SQU 4S: jjr9S\S\S-  4S; jr:S\S\;4S< jr<S\S\S-  4S= jr=S\S\;4S> jr>S?S@S\S\4SA jr?S\S\SS4SB jr@S\S\SS4SC jrAS\S\\"   4SD jrBS\S\S\S-  4SE jrCS\S\S\;4SF jrDS\S\S\4SG jrES\S\SS4SH jrFS\S\\"   4SI jrGS\S\SS4SJ jrHSQSK jrISQU 4SL jjrJS\S\S-  4SM jrKSNrLU =rM$ )R	SorryGameQ   z1Classic Sorry with rules-profile extension point.)default_factoryplayersoptionsr8   rules_profile_id
game_state@   max_move_slotsreturnc                     g)NzSorry!r*   clss    r4   get_nameSorryGame.get_name]   s    r3   c                     g)Nsorryr*   rS   s    r4   get_typeSorryGame.get_typea   s    r3   c                     g)Nzcategory-board-gamesr*   rS   s    r4   get_categorySorryGame.get_categorye   s    %r3   c                     g)Nr   r*   rS   s    r4   get_min_playersSorryGame.get_min_playersi       r3   c                     g)Nr'   r*   rS   s    r4   get_max_playersSorryGame.get_max_playersm   ra   r3   	player_idnameis_botc                 J    [        UUUU R                  5       R                  S9$ )zCreate a new Sorry player.)idrf   rg   r(   )r%   get_rules_profilepawns_per_player)selfre   rf   rg   s       r4   create_playerSorryGame.create_playerq   s*    113DD	
 	
r3   c                     U R                   R                  =(       d    U R                  n[        U5      c  [	        5       R
                  nXl        XR                   l        U$ N)rL   r9   rM   r   r   
profile_id)rl   	requesteds     r4   _resolve_rules_profile_id#SorryGame._resolve_rules_profile_idz   sK    LL..G$2G2G	"9-5)+66I )%."r3   c                 V    U R                  5       n[        U5      nUb  U$ [        5       $ )z#Return active rules profile object.)rs   r   r   )rl   rq   profiles      r4   rj   SorryGame.get_rules_profile   s.    335
)*5N ""r3   	action_idNc                     UR                  S5      (       d  g  [        UR                  S5      S   5      nUS:  a  g U$ ! [         a     g f = f)N
move_slot__r   )
startswithr0   split
ValueError)rl   rx   slots      r4   _parse_move_slotSorryGame._parse_move_slot   sX    ##L11	ys+B/0D !8	  		s   ? 
AAplayerc                 L    U R                  U5      nU(       a  UR                  $ g)Nen)get_userlocale)rl   r   users      r4   _player_localeSorryGame._player_locale   s     }}V$;;r3   r   	card_facec                 @    US:X  a  [         R                  " US5      $ U$ )NrX   zsorry-card-sorry)r   get)rl   r   r   s      r4   _card_display_textSorryGame._card_display_text   s$    ##F,>??r3   c                 ^    U(       d  gU R                  U5      nU(       a  UR                  $ U$ )NUnknown)get_player_by_idrf   )rl   re   targets      r4   _target_player_nameSorryGame._target_player_name   s+    &&y1;;r3   movec           	         UR                   S:X  a)  [        R                  " USUR                  =(       d    SS9$ UR                   S;   a=  [        R                  " USUR                  =(       d    SUR                  =(       d    SS9$ UR                   S:X  a=  [        R                  " US	UR                  =(       d    SUR                  =(       d    SS9$ UR                   S
:X  aW  [        R                  " USUR                  =(       d    SU R                  UR                  5      UR                  =(       d    SS9$ UR                   S:X  aW  [        R                  " USUR                  =(       d    SU R                  UR                  5      UR                  =(       d    SS9$ UR                   S:X  a=  [        R                  " USUR                  =(       d    SUR                  =(       d    SS9$ UR                   S:X  ae  [        R                  " USUR                  =(       d    SUR                  =(       d    SUR                  =(       d    SUR                  =(       d    SS9$ UR                  $ )Nstartzsorry-move-startr   )pawn>   forwardsorry_fallback_forwardzsorry-move-forwardr   stepsbackwardzsorry-move-backwardswapzsorry-move-swapr   target_playertarget_pawnrX   zsorry-move-sorrysplit7_pickzsorry-move-split7-pick)pawn_apawn_bsplit7zsorry-move-split7-optionr   steps_ar   steps_b)	move_typer   r   
pawn_indexr   r   target_player_idtarget_pawn_indexsecondary_pawn_indexsecondary_stepsdescription)rl   r   r   s      r4   _move_labelSorryGame._move_label   s   >>W$##"__) 
 >>BB##$__)jjoA	  >>Z'##%__)jjoA	  >>V###!__)"66t7L7LM 227a  >>W$##"__)"66t7L7LM 227a  >>]*##(+!005A	  >>X%##*+!

a005A,,1  r3   r   prefixc                    U R                  U5      nUbf  Ubc  UR                   HS  nUR                  U:X  d  M  U S3UR                  U S3UR                  =(       d    SS-   U S3UR
                  S-   0s  $    U S3SU S3SU S3S0$ )zOReturn zone/position/home_steps kwargs for a pawn, for localized announcements.zonepositionr   r   
home_stepsr   )get_player_statepawnsr   r   track_positionr   )rl   r   r   r   psr   s         r4   _pawn_location_kwargsSorryGame._pawn_location_kwargs   s     ""6*>j4??j0!($!((+d.A.A.FQ!-K!(*-t/B  ! ($VHH*=qVHJBWYZ[[r3   c           
      T   UR                   S:X  aD  U R                  " USS4SUR                  =(       d    S0U R                  XR                  5      D6  g UR                   S;   aX  U R                  " USS4UR                  =(       d    SUR                  =(       d    SS	.U R                  XR                  5      D6  g UR                   S
:X  aX  U R                  " USS4UR                  =(       d    SUR                  =(       d    SS	.U R                  XR                  5      D6  g UR                   S:X  a  UR
                  (       a  U R                  UR
                  5      OS nU(       a  U R                  X2R                  SS9OSSSS.nU R                  " USS4UR                  =(       d    SU R                  UR
                  5      UR                  =(       d    SS.U R                  XR                  5      DUD6  g UR                   S:X  ar  U R                  " USS4UR                  =(       d    SU R                  UR
                  5      UR                  =(       d    SS.U R                  XR                  5      D6  g UR                   S:X  a  U R                  " USS4UR                  =(       d    SUR                  =(       d    SUR                  =(       d    SUR                  =(       d    SS.U R                  XR                  SS9DU R                  XR                  SS9D6  g g )Nr   zsorry-you-play-startzsorry-play-startr   r   >   r   r   zsorry-you-play-forwardzsorry-play-forwardr   r   zsorry-you-play-backwardzsorry-play-backwardr   target_)r   track)target_zonetarget_positiontarget_home_stepszsorry-you-play-swapzsorry-play-swapr   rX   zsorry-you-play-sorryzsorry-play-sorryr   zsorry-you-play-split7zsorry-play-split7r   a_b_)r   broadcast_personal_lr   r   r   r   r   r   r   r   r   )rl   r   r   r   	target_kws        r4   _announce_moveSorryGame._announce_move   s   >>W$%%&" __)	
 ,,V__E >>BB%%($ __)jjoA ,,V__E >>Z'%%)% __)jjoA ,,V__E >>V#@D@U@U%%d&;&;<[_ 
 ! **=:P:PYb*c $+'()*  %%%!	 __)"66t7L7LM 227a	 ,,V__E	 	 >>W$%%&" __)"66t7L7LM 227a ,,V__E >>X%%%'#
 +!

a005A,,1
 ,,V__T,R
 ,,V5N5NW[,\
  &r3   actorcapturesc           	      ~   U GH6  nU R                  UR                  5      nU(       a  UR                  OUR                  nUR                  nU(       a3  U R                  U5      nU(       a  UR	                  SUR
                  US9  U R                  U5      nU(       a  UR	                  SUUR
                  S9  U R                   Ho  n	U	R                  UR                  :X  d  U	R                  UR                  :X  a  M9  U R                  U	5      n
U
(       d  MS  U
R	                  SUUUR
                  S9  Mq     GM9     g)z&Announce each pawn sent back to start.zsorry-your-pawn-captured)r   	by_playerzsorry-you-captured-pawn)r   r   zsorry-pawn-captured)r   r   r   N)r   captured_player_idrf   r   speak_lcaptured_pawn_indexrK   ri   )rl   r   r   eventr   target_name
actor_nametarget_user
actor_userr   r   s              r4   _announce_capturesSorryGame._announce_captures@  s   E 11%2J2JKM0=-,,5C[C[KJ"mmM:''2"66", (  u-J""-"-22 #  ,,99(FII9Q9Q,Q}}V,4LL-)&1"66	 !  '- r3   c                 p   U R                  U5      nUc  g[        5       nUR                  b  UR                  UR                  5        UR                  b  UR                  UR                  5        UR
                   H7  nUR                  U;   d  M  UR                  S:X  d  M'  U R                  SSS9  M9     g)z&Play a sound when a pawn arrives home.Nhomezmention.ogg2   )volume)r   setr   addr   r   r   
play_sound)rl   r   r   r   pawn_indexesr   s         r4   _play_home_arrival_sound"SorryGame._play_home_arrival_soundd  s    ""6*:u??&T__-$$0T667HHD,.4993Fb9 r3   c                 `    U R                   R                  R                  UR                  5      $ )z-Return serializable board state for a player.)rN   player_statesr   ri   rl   r   s     r4   r   SorryGame.get_player_stater  s!    ,,00;;r3   c                 v    U R                  U5      nUc  / $ [        U R                  UUU R                  5       S9$ )z5Get legal moves for the player's current board state.)stateplayer_stater   rules)r   r   rN   rj   )rl   r   r   r   s       r4   get_legal_moves_for_card"SorryGame.get_legal_moves_for_cardv  sE     ,,V4I#//%((*	
 	
r3   c                     U R                   R                  S:w  a  / $ U R                   R                  c  / $ U R                  XR                   R                  5      $ )Nr   )rN   
turn_phasecurrent_cardr   r   s     r4   _get_current_legal_moves"SorryGame._get_current_legal_moves  sI    ??%%6I??''/I,,V__5Q5QRRr3   c                     U R                  U5      nUc  [        S5      e[        U R                  UUU R	                  5       S9$ )z/Apply a move chosen from legal move generation.z)Player state missing for move application)r   r   r   r   )r   r   r   rN   rj   )rl   r   r   r   s       r4   apply_legal_moveSorryGame.apply_legal_move  sJ    ,,V4HII//%((*	
 	
r3   c                     U R                    H[  nU R                  U5      nUc  M  [        S UR                   5       5      Ul        [        S UR                   5       5      Ul        M]     g)z?Recompute start/home pawn counts from serializable board state.Nc              3   H   #    U  H  oR                   S :X  d  M  Sv   M     g7f)r   r   Nr   .0r   s     r4   	<genexpr>0SorryGame._sync_player_counts.<locals>.<genexpr>  s     'ZkdYYRYEYk   "	"c              3   H   #    U  H  oR                   S :X  d  M  Sv   M     g7f)r   r   Nr   r   s     r4   r   r     s     &X[TIIQWDWqq[r   )rK   r   sumr   r(   r)   rl   r   r   s      r4   _sync_player_countsSorryGame._sync_player_counts  sV    llF))&1E}$''Zekk'Z$ZF!#&&XU[[&X#XF  #r3   c                 d    U R                  U5      nUc  g[        S UR                   5       5      $ )NFc              3   >   #    U  H  oR                   S :H  v   M     g7f)r   Nr   r   s     r4   r   ,SorryGame._has_player_won.<locals>.<genexpr>  s     ?;499&;s   )r   allr   r   s      r4   _has_player_wonSorryGame._has_player_won  s/    %%f-=?5;;???r3   c                    UR                   S;   a(  UR                  =(       d    SnU R                  USSSS9  gUR                   S:X  a(  UR                  =(       d    SnU R                  USSSS9  gUR                   S:X  a  U R                  S	5        gUR                   S
;   a  U R                  S	5        gUR                   S:X  a  U R                  S5        gg)z&Play the appropriate sound for a move.>   r   r   r   zgame_squares/token{variant}.ogg
   r   )sound_templatevariant_countstep_interval_ticksr   r   zgame_squares/token1.ogg>   r   r   rX   zgame_chess/capture1.oggN)r   r   'schedule_standard_token_movement_soundsr   )rl   r   r   s      r4   _play_move_soundSorryGame._play_move_sound  s    >>BBJJO!E88@ $%	 9  ^^z)JJO!E88@ $%	 9  ^^w&OO56^^11OO56^^w&OO56 'r3   c                 \    [         R                  " SS5      nU R                  SU S35        g)z+Play a capture sound when a pawn is bumped.r   r   zgame_chess/capturez.oggN)randomrandintr   )rl   variants     r4   _play_capture_soundSorryGame._play_capture_sound  s(    ..A&,WIT:;r3   winnerc                     SU l         SU l        U R                  S5        U R                  SUR                  S9  U R                  5         g )NFfinishedzgame_pig/wingame.oggzgame-winner)r   )game_activestatusr   broadcast_lrf   rebuild_all_menus)rl   r  s     r4   _finish_gameSorryGame._finish_game  sA      ./v{{; r3   Tannouncer  c                    U R                  5         SU R                  l        S U R                  l        S U R                  l        S U R                  l        U(       a  U R                  5         U R                  5         g )Ndraw)rs   rN   r   r   split_pawn_asplit_pawn_bannounce_turnr  )rl   r  s     r4   _start_turnSorryGame._start_turn  sY    &&(%+"'+$'+$'+$  r3   c                    U R                   =R                  S-  sl        SU R                   l        S U R                   l        US:X  an  U R	                  5       R                  5       (       aK  U R                  5         U R                  5         [        R                  " U [        R                  " SS5      S9  g U R                  SS9  [        R                  " U [        R                  " SS5      S9  g )	Nr   r!  2      ticksTr  )rN   turn_numberr   r   rj   card_two_grants_extra_turnr$  r  r   	jolt_botsr  r  advance_turn)rl   r   s     r4   _end_turn_after_cardSorryGame._end_turn_after_card  s    ##q(#%+"'+$ 6 6 8 S S U U ""$FNN2r,BC4(Dr2(>?r3   c                    U R                  U5      n[        SS9nUR                  [        S[        R
                  " US5      SSSSS	95        UR                  [        S
[        R
                  " US5      SSSS95        UR                  [        S[        R
                  " US5      SSSS95        [        SU R                  S-   5       H8  nUR                  [        SU 3[        R
                  " USUS9SSSSSS95        M:     U$ )zGCreate turn actions: draw + move slots + board view (dynamic by phase).turn)rf   	draw_cardzsorry-draw-card_action_draw_card_is_draw_enabled_is_draw_hiddenF)ri   r?   handler
is_enabled	is_hiddenshow_in_actions_menu
view_boardzsorry-view-board_action_view_board_is_view_board_enabled_is_view_board_hidden)ri   r?   r9  r:  r;  
view_pawnszsorry-view-pawns_action_view_pawnsr   rz   sorry-move-slotr   _action_choose_move_is_move_slot_enabled_is_move_slot_hidden_get_move_slot_label)ri   r?   r9  r:  r;  	get_labelr<  )r   r   r   r
   r   r   rangerP   )rl   r   r   
action_setr   s        r4   create_turn_action_set SorryGame.create_turn_action_set  s   $$V,F+
"&&v/@A+-+%*		
 	"&&v/AB,31	
 	"&&v/AB,31	
 !T00145DNN#D6*&**63D4P1644).
 6 r3   c                   > [         TU ]  5         U R                  SSS/[        R                  S9  U R                  SSS/[        R                  S9  U R                  SSS/[        R                  S	S
9  U R                  SSS/[        R                  S9  [        SS5       H3  nU R                  [        U5      SU 3SU 3/[        R                  S9  M5     g)z5Define keybinds for draw, move slots, and board view.dz	Draw cardr5  )r   spacebz
View boardr=  T)r   include_spectatorsvzView your pawnsrA  r   r  zChoose move rz   N)supersetup_keybindsdefine_keybindr   ACTIVErJ  rE   )rl   r   	__class__s     r4   rU  SorryGame.setup_keybinds  s     C{m<CVCVWG[;-|GZGZ[N%%# 	 	
 	N%%	 	 	
 !RLDD	tf%dV$%"))	    !r3   c                 ~    U R                   S:w  a  gU R                  U:w  a  gU R                  R                  S:w  a  gg )Nplayingaction-not-playingaction-not-your-turnr!  action-not-available)r  current_playerrN   r   r   s     r4   r7  SorryGame._is_draw_enabled,  s:    ;;)#'&()??%%/)r3   c                     U R                   S:w  a  [        R                  $ U R                  U:w  a  [        R                  $ U R                  R
                  S:w  a  [        R                  $ [        R                  $ )Nr[  r!  )r  r   HIDDENr_  rN   r   VISIBLEr   s     r4   r8  SorryGame._is_draw_hidden5  s^    ;;)#$$$&($$$??%%/$$$!!!r3   c                 &    U R                   S:w  a  gg )Nr[  r\  )r  r   s     r4   r?   SorryGame._is_view_board_enabled>  s    ;;)#'r3   c                 "    [         R                  $ rp   )r   rb  r   s     r4   r@  SorryGame._is_view_board_hiddenC  s       r3   r   SorryPawnStatec                    UR                   S:X  a  [        R                  " US5      $ UR                   S:X  a,  [        R                  " USUR                  =(       d    SS-   S9$ UR                   S:X  a#  [        R                  " US	UR                  S-   S
9$ UR                   S:X  a  [        R                  " US5      $ UR                   $ )z:Return a localized short description of a pawn's position.r   zsorry-zone-startr   zsorry-zone-trackr   r   )r   	home_pathzsorry-zone-home-path)r   r   zsorry-zone-home)r   r   r   r   r   )rl   r   r   s      r4   _describe_pawnSorryGame._describe_pawnF  s    99##F,>??99##*d6I6I6NQRS5S  99###F,B$//\]J]^^99##F,=>>yyr3   c                 J   UnU R                  U5      nU(       d  gUR                  n/ nU R                  R                  R	                  5        H  nU R                  UR                  5      nU(       a  UR                  OUR                  n	UR                   V
s/ s H3  n
[        R                  " USU
R                  U R                  X5      S9PM5     nn
UR                  [        R                  " USU	SR                  U5      S95        M     U R                  X5        gs  sn
f )z1Show all players' pawn positions in a status box.Nzsorry-board-pawn-briefr   r   zsorry-board-player-linez, )r   r   )r   r   rN   r   valuesr   re   rf   r   r   r   r   rl  appendjoin
status_box)rl   r   rx   r{   r   r   linesr   r   
owner_namer   
pawn_partss               r4   r>  SorryGame._action_view_boardT  s   }}V$////668B 11",,?M/<++",,J HH %D   ,,,T:	 %   LL  -%))J/	 9( 	&#s   :D c           	      2   UnU R                  U5      nU(       d  gUR                  nU R                  R                  R	                  UR
                  5      nUc  gUR                   H-  nUR                  SUR                  U R                  Xu5      S9  M/     g)z1Speak the requesting player's own pawn positions.Nzsorry-view-your-pawnro  )
r   r   rN   r   r   ri   r   r   r   rl  )rl   r   rx   r{   r   r   r   r   s           r4   rB  SorryGame._action_view_pawnsr  s    }}V$__**..vyy9:HHDLL&__((6   r3   c                 z    U R                   R                  S:X  a  U R                  U5      $ U R                  U5      $ )z+Return the move list for the current phase.choose_split)rN   r   _get_current_split_optionsr   r   s     r4   _active_move_listSorryGame._active_move_list  s6    ??%%7226::,,V44r3   c                     U R                   S:w  a  gU R                  U:w  a  gU R                  R                  S;  a  gU R	                  U5      nUc  gU R                  U5      nU[        U5      :  a  gg )Nr[  r\  r]     r   r{  r^  )r  r_  rN   r   r   r}  lenrl   r   rx   r   movess        r4   rF  SorryGame._is_move_slot_enabled  sr    ;;)#'&()??%%-LL)$$Y/<)&&v.#e*)r3   c                    U R                   S:w  a  [        R                  $ U R                  U:w  a  [        R                  $ U R                  R
                  S;  a  [        R                  $ U R                  U5      nUc  [        R                  $ U R                  U5      nU[        U5      :  a  [        R                  $ [        R                  $ )Nr[  r  )
r  r   rb  r_  rN   r   r   r}  r  rc  r  s        r4   rG  SorryGame._is_move_slot_hidden  s    ;;)#$$$&($$$??%%-LL$$$$$Y/<$$$&&v.#e*$$$!!!r3   c                 (   U R                  U5      nU R                  U5      nUc  [        R                  " US5      $ U R	                  U5      nSUs=::  a  [        U5      ::  a  O  OU R                  X5US-
     5      $ [        R                  " USUS9$ )Nzsorry-move-slot-fallbackr   rC  rD  )r   r   r   r   r}  r  r   )rl   r   rx   r   r   r  s         r4   rH  SorryGame._get_move_slot_label  s    $$V,$$Y/<##F,FGG&&v."E
"##F$(O<<(9EEr3   c                    UnU R                  U5      b  g[        U R                  5      nUc  U R                  SS9  gU R	                  SSS9  U R                  SU5      nU R                  USS	US
9  U R                  X5      nU(       d7  U R                  USSUS
9  [        U R                  5        U R                  US9  gU R                  R                  (       a  [        U5      S:X  a  U R                  XS   5      nU R                  US   5        U(       a  U R                  5         U R                  XS   5        U R!                  X5        U R#                  XS   5        U R%                  5         U R'                  U5      (       a  U R)                  U5        g[        U R                  5        U R                  US9  gSU R                  l        U R-                  5         [.        R0                  " U [2        R4                  " SS5      S9  g)z;Draw a card and transition into move selection/application.N0r   zgame_squares/draw{variant}.oggr	   )r	  r
  r   zsorry-you-draw-announcementzsorry-draw-announcement)cardzsorry-you-no-legal-moveszsorry-no-legal-movesr   r   r         r+  )r7  r#   rN   r1  play_standard_dice_roll_soundr   r   r   r"   rL   rB   r  r   r  r  r   r   r   r   r  r  r   r  r   r/  r  r  )rl   r   rx   r{   r   card_displaylegal_movesr   s           r4   r6  SorryGame._action_draw_card  s     (4"4??3	%%%4**;1 	+ 	
 ..tY?!!)%	 	" 	
 33FF%%*&!	 &  !1%%	%:<<..3{3Cq3H,,V^DH!!+a.1((*A7##F5))&a.A$$&##F++!!&) 1%%	%:%2" Dq"(=>r3   c                 0   U R                   R                  S:w  a  / $ U R                   R                  b  U R                   R                  c  / $ U R	                  U5      nUc  / $ [        UU R                   R                  U R                   R                  5      $ )Nr{  )rN   r   r"  r#  r   r   )rl   r   r   s      r4   r|  $SorryGame._get_current_split_options  s    ??%%7I??''/4??3O3O3WI,,V4I.OO((OO((
 	
r3   c                 0   U R                  XS9b  gU R                  U5      nUc  gU R                  R                  S:X  Ga3  U R	                  U5      nUS:  d  U[        U5      :  a  gXCS-
     nU R                  R                  nUc  gSU R                  l        SU R                  l        U R                  X5      nU R                  U5        U(       a  U R                  5         U R                  X5        U R                  X5        U R                  X5        U R                  5         U R!                  U5      (       a  U R#                  U5        g[%        U R                  5        U R'                  US9  gU R)                  U5      nUS:  d  U[        U5      :  a  gXS-
     nU R                  R                  nUc  gUR*                  S:X  a  SU R                  l        UR,                  U R                  l        UR.                  U R                  l        U R1                  5         [2        R4                  " U [6        R8                  " SS5      S	9  gU R                  X5      nU R                  U5        U(       a  U R                  5         U R                  X5        U R                  X5        U R                  X5        U R                  5         U R!                  U5      (       a  U R#                  U5        g[%        U R                  5        U R'                  US9  g)
zApply the selected move slot.rx   Nr{  r   r  r   r  r  r+  )rF  r   rN   r   r|  r  r   r"  r#  r   r  r  r   r   r   r   r  r  r"   r1  r   r   r   r   r  r   r/  r  r  )	rl   r   rx   r   rL   r   r   r   legals	            r4   rE  SorryGame._action_choose_move  s   %%f%BN$$Y/<??%%755f=Gax4#g,.!8$D44I +/DOO(+/DOO(,,V:H!!$'((*-##F5))&7$$&##F++!!&) 1%%	%:--f5!8tc%j(AXOO00	>>]*)7DOO&+/??DOO(+/+D+DDOO(""$FNN1b,AB((6d#$$&F)1%%f3  "''f%T__-!!I!6r3   c                    U R                  5         U R                  5       nSU l        SU l        SU l        U R                  5       nU R                  U5        U R                  SS9  [        U Vs/ s H  o3R                  PM     snUR                  U R                  R                  S9U l        U R                  R                  (       a  UR                  S-
  OUR                  nU H  nXCl        SUl        M     U R!                  S5        U R#                  SS9  [$        R&                  " U [(        R*                  " S	S
5      S9  gs  snf )zStart the game.r[  Tr   Fr  )rk   rC   r   zgame_pig/mus.oggr)  r*  r+  N)rs   rj   r  r  roundget_active_playersset_turn_playersreset_turn_orderr!   ri   rk   rL   rC   rN   r(   r)   
play_musicr%  r   r/  r  r  )rl   r   active_playersr   r(   s        r4   on_startSorryGame.on_start5  s   &&(&&(
002n-u-2%34^6YY^4"33&*ll&L&L
 ||55 ""Q&'' 	
 %F$2!#$F  % 	*+$'Dr2(>?! 5s   /Ec                 N   > [         TU ]  5         [        R                  " U 5        g)z&Drive bot turns in draw/choose phases.N)rT  on_tickr   )rl   rX  s    r4   r  SorryGame.on_tickT  s    $r3   c                   ^ U R                   R                  S:X  a  gU R                   R                  S:X  az  U R                  U5      nU(       d  gU R                  U5      nUc  g[	        U R                   X2U R                  5       5      mTc  g[        U4S j[        USS9 5       S5      nS	U 3$ U R                   R                  S
:X  a  U R                  U5      nU(       d  gU R                  U5      nUc  g[	        U R                   UUU R                  5       5      mTc  g[        U4S j[        USS9 5       S5      nUc  gS	U 3$ g)z1Return the action ID a bot should take this tick.r!  r5  r{  Nmove_slot_1c              3   d   >#    U  H%  u  pUR                   TR                   :X  d  M!  Uv   M'     g 7frp   r  )r   idxmselecteds      r4   r   &SorryGame.bot_think.<locals>.<genexpr>h  s.      "={{h&8&88 C"=    0	0r   )r   rz   r   c              3   d   >#    U  H%  u  pUR                   TR                   :X  d  M!  Uv   M'     g 7frp   r  )r   r  r   r  s      r4   r   r    s.      %>	~~););; C%>r  )	rN   r   r|  r   r   rj   next	enumerater   )rl   r   rL   r   
slot_indexr  r  s         @r4   	bot_thinkSorryGame.bot_thinkY  s\   ??%%/??%%755f=G008L#"4??L4KaKaKcdH$"+G1"=
 J  
|,,??%%611&9E008L#"&&(	H %.uA%>
 J !
|,,r3   )r  rN   r  rM   r  )F) )rQ   N)Nr+   r,   r-   r.   r/   r   rD   rK   r%   r1   r6   rL   rM   rE   r   rN   rP   r0   classmethodrU   rY   r\   r_   rc   rF   rm   rs   r   rj   r   r   r   r   r   r   r   dictobjectr   r   r   r   r   r    r   r   r   r   r   r  r  r  r  r%  r1  r   rL  rU  r7  r   r8  r?  r@  rl  r>  rB  r}  rF  rG  rH  r6  r|  rE  r  r  r  r2   __classcell__)rX  s   @r4   rH   rH   Q   s    <!&t!<GT+<!,?G\?+c+!&~!FJFNC      &S & &      
s 
# 
t 
P[ 
3 ##4 #	# 	#* 	V     
S4Z C 5 # 5 Y 5 3 5 v 	\\ $J\ 	\
 
c6k	\$MV M9 M M^" "$|:L "QU "H:v :Y :4 :<v <2BT2I <

 
 
i	
 Sv S$y/ S

v 

Y 

4CU 

Y@f @ @7Y 74 72<
!6 !d ! /3 !t !t !@c @d @,[ ,Y ,\4v #* "f " "V d
 
!F !z !#3 S S ' 'C 'D '< C D "5 54	? 5F s sTz "6 "c "j "F6 Fc Fc F4? 4?3 4?4 4?l
 
DO 
>7& >7S >7T >7@@> 
1 13: 1 1r3   rH   )/r/   dataclassesr   r   r  baser   r   registryr   game_utils.actionsr
   r   r   game_utils.bot_helperr   game_utils.optionsr   r   r   r   messages.localizationr   server.core.ui.keybindsr   botr   r  r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r%   r6   rH   r*   r3   r4   <module>r     s      (   $ ? ? . S S 1 0     &    ;    F w w  wr3   