title: Python: Conditional probabilities of winning a tiebreaker game
body: <p>This question was asked again (<a href="https://stackoverflow.com/questions/27698815/excel-conditional-probabilities-of-winning-a-tiebreaker-game">Excel: Conditional probabilities of winning a tiebreaker game</a>), but the OP wanted an Excel-based answer and the one s/he got was not really accurate.</p>
  
  <p>I am trying to calculate the conditional probability of winning a tiebreaker match as described in <a href="http://strategicgames.com.au/PhD.pdf" rel="nofollow noreferrer">http://strategicgames.com.au/PhD.pdf</a>,  page 21-22.</p>
  
  <p>It requires coding two recursive formulas:
  <a href="https://i.stack.imgur.com/YT5kI.png" rel="nofollow noreferrer">Formulas</a>
  (I cannot attach picture due to low rep)</p>
  
  <p>This is what i've done so far:</p>
  
  <pre><code>def prob_tiebraker_game_A(Pa, Pb, a, b):
      if a == 7 and b &gt;= 0 and b &lt;=5:
          return 1
      elif b == 7 and a &gt;= 0 and a &lt;=5:
          return 0
      elif a == 6 and b == 6:
          return (Pa*(1-Pb))/(Pa*(1-Pb) + (1-Pa)*Pb)
      elif (a+b) % 2 ==0:
          return Pa*prob_tiebraker_game_B(Pa, Pb, a+1, b) + (1-Pa)*prob_tiebraker_game_B(Pa, Pb, a,b+1)
      elif (a+b) % 2 !=0:
          return Pa*prob_tiebraker_game_A(Pa, Pb, a+1, b) + (1-Pa)*prob_tiebraker_game_A(Pa, Pb, a,b+1)
  
  
  
   def prob_tiebraker_game_B(Pa, Pb, a, b):
      if b == 7 and a &gt;= 0 and a &lt;=5:
          return 1
      elif a == 7 and b &gt;= 0 and b &lt;=5:
          return 0
      elif a == 6 and b == 6:
          return (Pb*(1-Pa))/(Pb*(1-Pa) + (1-Pb)*Pa)
      elif (a+b) % 2 ==0:
          return Pb*prob_tiebraker_game_A(Pa, Pb, a+1, b) + (1-Pb) * prob_tiebraker_game_A(Pa, Pb, a,b+1)
      elif (a+b) % 2 !=0:
          return Pb*prob_tiebraker_game_B(Pa, Pb, a+1, b) + (1-Pb) *  prob_tiebraker_game_B(Pa, Pb, a,b+1)
  </code></pre>
  
  <p>For values of Pa = 0.62, Pb = 0.6, i should be getting these results:
  <a href="https://i.stack.imgur.com/s1gz2.png" rel="nofollow noreferrer">Results</a></p>
  
  <p>But i am getting the wrong numbers for any values of (a,b) except (0,0) and (6,6), (7,.) and (.,7) since these scores depend on the first 3 conditions in the functions which are trivial to evaluate.</p>
  
  <p>I tried modifying the other conditions but with no success. Any help appreciated would be appreciated</p>