
    soj7                     r    d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  G d d	e          ZdS )
    N)Game)User)	GameBoard)GameOutcome)GameTurn)RussianRouletteChamberStatusc                        e Zd Zdddddej        fdededededed	ef fd
ZddZddd de	fdZ
de	fdZdefdZd Z	 dde	dd defdZdedede	fdZdedefdZdedede	fdZdefdZ xZS )RussianRoulette   Nrowscolumnscylinderbullet_xbullet_y	game_turnc                     t                                                       | _        | _        ||n fdt	           j                  D              _        | _        | _        t          |t                    st          |          n| _
         j        dk    s j        dk    r                                  d S d S )Nc                 L    g | ] }d  t          j                  D             !S )c                 &    g | ]}t           j        S  )RRChamberStatus	NOT_FIRED).0_s     6/app/src/model/game/russianroulette/RussianRoulette.py
<listcomp>z7RussianRoulette.__init__.<locals>.<listcomp>.<listcomp>   s    HHHq*HHH    )ranger   )r   r   selfs     r   r   z,RussianRoulette.__init__.<locals>.<listcomp>   s?       MNHHE$,4G4GHHH  r   r   )super__init__r   r   r   r   r   r   
isinstancer   r   set_bullet_position)r   r   r   r   r   r   r   	__class__s   `      r   r!   zRussianRoulette.__init__   s     		 # H   RWX\XaRbRb   	 &%'1)X'F'FUHYI 	
 =B$-2"5"5$$&&&&& #6"5r   returnc                     	 t          j        d| j        dz
            }t          j        d| j        dz
            }|| j        dz  k    s|| j        dz  k    r|| _        || _        dS g)z*
        Sets the bullet position
        Tr         N)randomrandintr   r   r   r   r   xys      r   r#   z#RussianRoulette.set_bullet_position,   sr    
	q$)a-00Aq$,"233A DIN""a4<1+<&<&< ! !	r   other_boardc                    |du p|                                 }|                                 }||                                nd}|s|                                 r||k     rdS dS |                                 rdS |||k    rdS d}t          | j                  D ]E\  }}t          |          D ]0\  }}	|	t
          j        k    r|                     ||          s|dz  }1F|dk    S )z
        Returns if the game is finished. The game is finished when all but one chamber is fired, except for the center
        :param other_board: The other board, in case of global game
        :return: GameTurn
        Nr   TFr'   )is_finishedget_fired_correct_countbullet_is_fired	enumerater   r   r   is_chamber_center)
r   r.   other_is_finishedself_fired_correct_countother_fired_correct_countnot_fired_count	row_indexrowchamber_indexchambers
             r   r0   zRussianRoulette.is_finished;   s<    (4/L;3J3J3L3L#'#?#?#A#A 5@5LK//111RS 	" ! 	##%% *BE^*^*^t5!! 	4 "'?B['['[4'66 	) 	)NIs*3C.. ) )&wo777@V@V}A A7 $q(O	) !##r   c                 F    |                                  t          j        k    S )zF
        Returns if the bullet is fired
        :return: bool
        )get_bullet_chamber_statusr   FIREDr   s    r   r2   zRussianRoulette.bullet_is_fired`   s     --//?3HHHr   c                 <    | j         | j                 | j                 S )zT
        Returns the bullet chamber status
        :return: RRChamberStatus
        )r   r   r   r@   s    r   r>   z)RussianRoulette.get_bullet_chamber_statush   s     }T]+DM::r   c                 f    | j         t          j        u rt          j        nt          j        | _         dS )z
        Sets the turn
        N)r   r   OPPONENT
CHALLENGERr@   s    r   set_turnzRussianRoulette.set_turnp   s,     $(>X5F#F#FHHL] 	r   user_is_challengerc                    |                      |          st          j        S |t|                                 }|                                }||k    r|rt          j        nt          j        S ||k     r|rt          j        nt          j        S t          j        S |                                 r-| j        t          j
        k    rt          j        S t          j        S t          j        S )z
        Returns the outcome of the game
        :param user_is_challenger: If the outcome is being evaluated by the challenger
        :param other_board: The other board, in case of global game
        :return: GameTurn
        )r.   )r0   r   NONEr1   CHALLENGER_WONOPPONENT_WONDRAWr2   r   r   rD   )r   rF   r.   self_pointsother_pointss        r   get_outcomezRussianRoulette.get_outcomey   s     K88 	$##"6688K&>>@@L\))2DbK..+Jb |++0BbK,,Hb ##!! 	2~!444"//"11r   usergamec                 T    | j         t          j        u r||j        k    S ||j        k    S )z{
        Returns if the user is the turn
        :param user: User
        :param game: Game
        :return: bool
        r   r   rD   
challengeropponent)r   rO   rP   s      r   is_user_turnzRussianRoulette.is_user_turn   s.     >X0004?**4=((r   c                 H    | j         t          j        k    r|j        S |j        S )z[
        Returns the user turn
        :param game: The game
        :return: User
        rR   )r   rP   s     r   get_user_turnzRussianRoulette.get_user_turn   s$     >X000?"}r   r,   r-   c                 :    || j         dz  k    o|| j        dz  k    S )z
        Returns if the chamber is the center
        :param x: Location x
        :param y: Location y
        :return: If is the center of the chamber
        r(   )r   r   r+   s      r   r4   z!RussianRoulette.is_chamber_center   s&     DIN"=qDLA,='==r   c                     d}t          | j                  D ]/\  }}t          |          D ]\  }}|t          j        k    r|dz  }0|                                 r|dz  }|S )zu
        Returns the number of chambers that have been fired and don't contain a bullet
        :return: int
        r   r'   )r3   r   r   r?   r2   )r   fired_correct_countr9   r:   r;   r<   s         r   r1   z'RussianRoulette.get_fired_correct_count   s      '66 	- 	-NIs*3C.. - -&wo333'1,'-
 !! 	%1$""r   )r%   N)N)__name__
__module____qualname__r   rD   intlistr!   r#   boolr0   r2   r   r>   rE   r   rN   r   r   rU   rW   r4   r1   __classcell__)r$   s   @r   r
   r
      s        &1' '' ' 	'
 ' ' ' ' ' ' ' '<   #$ #$'8 #$D #$ #$ #$ #$JI I I I I;? ; ; ; ;
 
 
 JN"  " "&" 5F" 	"  "  "  " H) )T )d ) ) ) )
$ 
4 
 
 
 
>3 >3 >4 > > > ># # # # # # # # #r   r
   )r)   src.model.Gamer   src.model.Userr   src.model.game.GameBoardr   src.model.game.GameOutcomer   src.model.game.GameTurnr   ;src.model.game.russianroulette.RussianRouletteChamberStatusr   r   r
   r   r   r   <module>rh      s                 . . . . . . 2 2 2 2 2 2 , , , , , ,     
C# C# C# C# C#i C# C# C# C# C#r   