title: Turn Base battle game python
body: <p>I created a turn based battle game in python and it just won't work, I have tried multiple ways, and yet it is still the same.
  The situation is this: both players (player1 = me, player 2 = pc) will choose 3 units to attack each other, if one of us killed all of the units, the player wins.</p>
  <p>My main issue is when I kill the first PC unit, at the PC's turn, the PC still manages to kill me using his first unit and vice versa. I need something like when the unit reach hp &lt; 0, the unit is unable to hit anymore.</p>
  <p>Notes:
  battlefield is a list that holds both players' 3 units. I have two to hold both player's units</p>
  <pre class="lang-py prettyprint-override"><code>AI_battlefield = [first_ai,second_ai,third_ai]
  player_battlefield=[first_unit,second_unit,third_unit]
          
  if len(ai_battlefield) = 3 and len(player_..)== 3:
     ( player or AI attack as usual but when it comes to 2 unit as below:
  
  if len(AI_battlefield) = 3 and len(player_battlefield) == 2 :   
     if playe1.hp &lt; 0
         player2.attack if user input is 1 
         player3.attack if user input is 2 
     elif player2.hp &lt;0
         .....
     elif player3.hp &lt;0 
         attack....
  if len(asa_jdasdS) == 2 and len(pdlsad) ==3 
      if player1hp &lt; 0 
      elif player2hp &lt; 0 
      elif player3hp &lt;0   
  </code></pre>
  <p>I have tried multiple ways and yet it doesn't work. This is my example of my another solution but yet it still won't work:</p>
  <pre class="lang-py prettyprint-override"><code>while start_game:
      RANDOM_VALUE = random.randint(-5, 10)
      time.sleep(1)
      game.total_turn()
      if game.round % 2 != 0:
          if len(AI_battlefield) == 0:
              print(&quot;Game Over &quot;)
              print(&quot;You Win&quot;)
              print('Thanks for playing')
              start_game = False
  
          elif len(player_battlefield) == 0:
              print(&quot;Game Over &quot;)
              print(&quot;You Lose&quot;)
              print('Thanks for playing')
              start_game = False
          print(&quot;--- Available Units --- &quot;)
          field_unit(first_unit, second_unit, third_unit)
          field_unit(first_AI, second_AI, third_AI)
          print(&quot;\n&quot;)
          print(f&quot; === Round {game.round} === &quot;)
          print(&quot;Player move:&quot;)
          player_unit = (int(input(&quot;Select unit [Q=Quit] : &quot;)))
          choice = int(input(f&quot;Select opponent to attack [Q=Quit]:&quot;))
          if first_AI.hp &gt; 0:
              if choice == 1:
                  if len(player_battlefield) == 3:
                      if player_unit == 1:
                          func_dict.get(&quot;cond_c&quot;, attack)(first_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0, AI_grave)
  
                      elif player_unit == 2:  # player 1 hit the 2nd pc
                          func_dict.get(&quot;cond_c&quot;, attack)(second_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                          AI_grave)
  
                      elif player_unit == 3:
                          func_dict.get(&quot;cond_c&quot;, attack)(third_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0, AI_grave)
  
                  elif len(player_battlefield) == 2:
                      if first_unit.hp &lt; 0:
                          if player_unit == 1:
                              func_dict.get(&quot;cond_c&quot;, attack)(second_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                          elif player_unit == 2:
                              func_dict.get(&quot;cond_c&quot;, attack)(third_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                      elif second_unit.hp &lt; 0:
                          if player_unit == 1:
                              func_dict.get(&quot;cond_c&quot;, attack)(first_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                          elif player_unit == 2:
                              func_dict.get(&quot;cond_c&quot;, attack)(third_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
  
                  elif len(player_battlefield) == 1:
                      if first_unit.hp &lt; 0 and second_unit.hp &lt; 0:
                          func_dict.get(&quot;cond_c&quot;, attack)(third_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0, AI_grave)
                      elif second_unit.hp &lt; 0 and third_unit.hp &lt; 0:
                          func_dict.get(&quot;cond_c&quot;, attack)(first_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0, AI_grave)
                      elif first_unit.hp &lt; 0 and third_unit.hp &lt; 0:
                          func_dict.get(&quot;cond_c&quot;, attack)(second_unit, first_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                          AI_grave)
  
          elif second_AI.hp &gt; 0:
              if choice == 2:
                  if len(player_battlefield) == 3:
                      if player_unit == 1:
                          func_dict.get(&quot;cond_c&quot;, attack)(first_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                          AI_grave)
  
                      elif player_unit == 2:  # player 1 hit the 2nd pc
                          func_dict.get(&quot;cond_c&quot;, attack)(second_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                          AI_grave)
  
                      elif player_unit == 3:
                          func_dict.get(&quot;cond_c&quot;, attack)(third_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                          AI_grave)
                  elif len(player_battlefield) == 2:
                      if first_unit.hp &lt; 0:
                          if player_unit == 1:
                              func_dict.get(&quot;cond_c&quot;, attack)(second_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                          elif player_unit == 2:
                              func_dict.get(&quot;cond_c&quot;, attack)(third_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                      elif second_unit.hp &lt; 0:
                          if player_unit == 1:
                              func_dict.get(&quot;cond_c&quot;, attack)(first_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
                          elif player_unit == 2:
                              func_dict.get(&quot;cond_c&quot;, attack)(third_unit, second_AI, RANDOM_VALUE, AI_battlefield, 0,
                                                              AI_grave)
  </code></pre>