In [3]:
from ti3combat import Battle, PrepareForces, EasyOutcomes
from sabotage_run import p_outer, p_survives, p_survivors

n fighters are assigned. How likely will m get through the outer defenses? Use p_outer, e.g. for 2 fighters:


In [2]:
n = 2
survive_outer = np.array([p_outer(n,m) for m in range(n+1)])
print survive_outer
print sum(survive_outer)


[ 0.64  0.32  0.04]
1.0

Of those m fighters, how many will be left after inner defenses?


In [3]:
m = 2
survive_inner = np.array([p_survives(m,k) for k in range(m+1)])
print survive_inner
print sum(survive_inner)


[ 0.81  0.09  0.1 ]
1.0

In [4]:
m = 1
survive_inner = np.array([p_survives(m,k) for k in range(m+1)])
print survive_inner
print sum(survive_inner)


[ 0.9  0.1]
1.0

Now, what does that mean for the whole sabotage run?


In [5]:
n = 2
survive = np.array([p_survivors(n,k) for k in range(n+1)])
print survive
print sum(survive)


[ 0.9604  0.0356  0.004 ]
1.0

In [6]:
l = 6
print ' \ k     0          1          2         3          4         5         6' 
print 'n \ '
for n in range(l+1):
    #survive = np.zeros(l+1)
    survive = np.array([p_survivors(n,k) for k in range(n+1)]) * 100
    print n,
    for p in survive:
        print '  {:7.3f}'.format(p),
    print #'{}   {:.3f}   {:.3f}   {:.3f}   {:.3f}   {:.3f}   {:.3f}   {:.3f}'.format(n,*tuple(survive))


 \ k     0          1          2         3          4         5         6
n \ 
0   100.000
1    98.000     2.000
2    96.040     3.560     0.400
3    94.119     4.769     1.032     0.080
4    92.237     5.697     1.779     0.270     0.016
5    90.392     6.403     2.563     0.572     0.067     0.003
6    88.584     6.930     3.331     0.970     0.168     0.016     0.001

Let's assume 1 carrier with 6 fighters is attacked by a warsun with 4 fighters and 2 cruisers. First calculate probabilities for this battle for various numbers of defending fighters. (Fighters may have been destroyed during Sabotage Runs.)


In [7]:
Ships_Att = {'CA':2,'FT':4,'WS':1}
outcomes = []
BattleDict = None
for k in range(7):
    Forces = PrepareForces(Ships_Att,{'CV':1,'FT':k})
    #Forces['Defender']['DmgOrder'] = ['CV1']+['FT{}'.format(m) for m in range(k,0,-1)]
    out = Battle(Forces,BattleDict=BattleDict)
    BattleDict = out[2]
    outcomes += [(out[0],out[3],EasyOutcomes(out[0]))]

In [14]:
print 'N_FT  %Attacker   %Tie        %Defender   Value'
for k in range(7):
    value = outcomes[k][1][1] - outcomes[k][1][0]
    print ' {}    {:8.4f}    {:.3e}   {:.3e}   {:.3f}'.format(k,outcomes[k][2][0]*100,outcomes[k][2][1]*100,
                                                            outcomes[k][2][2]*100,value)


N_FT  %Attacker   %Tie        %Defender   Value
 0    100.0000    3.118e-23   2.514e-25   3.000
 1    100.0000    1.355e-12   7.613e-14   3.479
 2    100.0000    1.703e-08   1.851e-09   3.937
 3    100.0000    5.118e-06   7.953e-07   4.365
 4     99.9997    2.615e-04   7.005e-05   4.752
 5     99.9936    4.535e-03   1.908e-03   5.095
 6     99.9406    3.619e-02   2.325e-02   5.382

In [16]:
Ships_Att = {'CA':2,'FT':4}
#Ships_Att = {'CA':2}
outcomes_noWS = []
BattleDict = None
for k in range(7):
    Forces = PrepareForces(Ships_Att,{'CV':1,'FT':k})
    #Forces['Defender']['DmgOrder'] = ['CV1']+['FT{}'.format(m) for m in range(k,0,-1)]
    out = Battle(Forces,BattleDict=BattleDict)
    BattleDict = out[2]
    outcomes_noWS += [(out[0],out[3],EasyOutcomes(out[0]))]

In [19]:
print 'N_FT  %Attacker   %Tie        %Defender   Value'
for k in range(7):
    value = outcomes_noWS[k][1][0] - outcomes_noWS[k][1][1]
    print ' {}    {:8.4f}    {:.3e}   {:.3e}   {:.3f}'.format(k,outcomes_noWS[k][2][0],outcomes_noWS[k][2][1],
                                                   outcomes_noWS[k][2][2],value)


N_FT  %Attacker   %Tie        %Defender   Value
 0      1.0000    9.510e-08   1.427e-07   -2.883
 1      0.9999    3.186e-05   8.877e-05   -3.214
 2      0.9970    5.608e-04   2.449e-03   -3.453
 3      0.9767    3.036e-03   2.030e-02   -3.483
 4      0.9081    8.107e-03   8.379e-02   -3.094
 5      0.7688    1.334e-02   2.179e-01   -2.142
 6      0.5749    1.535e-02   4.097e-01   -0.745

In [56]:
n = 6
print 'Sabotage  %Winning  %Survive    Value'
for k in range(7):
    combined = [0,0,0,0,0]
    # If the Sabotage Run is unsuccessful
    combined[0] += (outcomes[n-k][2][2] + outcomes[n-k][2][1]) * p_survivors(k,0) * 100
    combined[1] += outcomes[n-k][2][2] * p_survivors(k,0) * 100
    combined[2] += (outcomes[n-k][1][0] - outcomes[n-k][1][1] - 0.5*k) * p_survivors(k,0)
    combined[3] += (outcomes[n-k][1][0]) * p_survivors(k,0)
    combined[4] += (outcomes[n-k][1][1] + 0.5*k) * p_survivors(k,0)
    # If it is successful
    for l in range(1,k+1):
        combined[0] += (outcomes_noWS[n-k+l][2][2] + outcomes_noWS[n-k+l][2][1]) * p_survivors(k,l) * 100
        combined[1] += outcomes_noWS[n-k+l][2][2] * p_survivors(k,l) * 100  
        combined[2] += (outcomes_noWS[n-k+l][1][0] - outcomes_noWS[n-k+l][1][1] - 0.5*(k) + 12.) * p_survivors(k,l)
        combined[3] += (outcomes_noWS[n-k+l][1][0] - 12.) * p_survivors(k,l)
        combined[4] += (outcomes_noWS[n-k+l][1][1] + 0.5*(k-l)) * p_survivors(k,l)
    print '    {}        {:.3f}     {:.3f}   {:.3f}'.format(k,*combined)


Sabotage  %Winning  %Survive    Value
    0        0.059     0.023   -5.382
    1        0.856     0.821   -5.258
    2        0.993     0.940   -5.146
    3        0.711     0.657   -5.038
    4        0.366     0.330   -4.909
    5        0.148     0.132   -4.754
    6        0.053     0.046   -4.578

In [57]:
n = 6
#print 'Sabotage  %Winning  %Survive    Value'
for k in range(7):
    combined = [0,0,0,0]
    # If the Sabotage Run is unsuccessful
    combined[0] += outcomes[n-k][2][2] * p_survivors(k,0)
    combined[1] += outcomes[n-k][2][1] * p_survivors(k,0)
    combined[2] += outcomes[n-k][2][0] * p_survivors(k,0)
    combined[3] += (outcomes[n-k][1][0] - outcomes[n-k][1][1] - 0.5*k) * p_survivors(k,0)
    #combined[3] += (outcomes[n-k][1][0] - outcomes[n-k][1][1]) * p_survivors(k,0)
    # If it is successful
    for l in range(1,k+1):
        combined[0] += outcomes_noWS[n-k+l][2][2] * p_survivors(k,l)
        combined[1] += outcomes_noWS[n-k+l][2][1] * p_survivors(k,l)
        combined[2] += outcomes_noWS[n-k+l][2][0] * p_survivors(k,l)       
        combined[3] += (outcomes_noWS[n-k+l][1][0] - outcomes_noWS[n-k+l][1][1] - 0.5*(k-l) + 12.) * p_survivors(k,l)
        #combined[3] += (outcomes_noWS[n-k+l][1][0] - outcomes_noWS[n-k+l][1][1]) * p_survivors(k,l)
    print '    {}        {:.3e}     {:.3e}   {:.4f}    {:.3f}'.format(k,*combined)


    0        2.325e-04     3.619e-04   0.9994    -5.382
    1        8.214e-03     3.514e-04   0.9914    -5.258
    2        9.395e-03     5.388e-04   0.9901    -5.146
    3        6.572e-03     5.366e-04   0.9929    -5.038
    4        3.302e-03     3.557e-04   0.9963    -4.909
    5        1.315e-03     1.695e-04   0.9985    -4.754
    6        4.627e-04     6.619e-05   0.9995    -4.578

In [30]:
n = 6
#print 'Sabotage  %Winning  %Survive    Value'
for k in range(7):
    combined = [0,0,0,0]
    # If the Sabotage Run is unsuccessful
    combined[0] += outcomes[n-k][2][2] * p_survivors(k,0)
    combined[1] += outcomes[n-k][2][1] * p_survivors(k,0)
    combined[2] += outcomes[n-k][2][0] * p_survivors(k,0)
    combined[3] += (outcomes[n-k][1][0] - outcomes[n-k][1][1] - 0.5*k) * p_survivors(k,0)
    # If it is successful
    for l in range(1,k+1):
        combined[0] += outcomes_noWS[n-k][2][2] * p_survivors(k,l)
        combined[1] += outcomes_noWS[n-k][2][1] * p_survivors(k,l)
        combined[2] += outcomes_noWS[n-k][2][0] * p_survivors(k,l)       
        combined[3] += (outcomes_noWS[n-k][1][0] - outcomes_noWS[n-k][1][1] 
                        - 0.5*(k-l*outcomes_noWS[n-k][2][2]) + 12.) * p_survivors(k,l)
    print '    {}        {:.3e}     {:.3e}   {:.4f}    {:.3f}'.format(k,*combined)


    0        2.325e-04     3.619e-04   0.9994    -5.382
    1        4.376e-03     3.113e-04   0.9953    -5.294
    2        3.319e-03     3.235e-04   0.9964    -5.210
    3        1.194e-03     1.786e-04   0.9986    -5.107
    4        1.901e-04     4.354e-05   0.9998    -4.968
    5        8.529e-06     3.061e-06   1.0000    -4.801
    6        1.628e-08     1.086e-08   1.0000    -4.617

In [5]:
def Example_Calc(n_CA):
    Ships_Att = {'CA':2,'FT':4,'WS':1}
    outcomes = []
    BattleDict = None
    for k in range(7):
        Forces = PrepareForces(Ships_Att,{'CV':1,'FT':k,'CA':n_CA})
        #Forces['Defender']['DmgOrder'] = ['CV1']+['FT{}'.format(m) for m in range(k,0,-1)]
        out = Battle(Forces,BattleDict=BattleDict)
        BattleDict = out[2]
        outcomes += [(out[0],out[3],EasyOutcomes(out[0]))]
        
    Ships_Att = {'CA':2,'FT':4}
    #Ships_Att = {'CA':2}
    outcomes_noWS = []
    BattleDict = None
    for k in range(7):
        Forces = PrepareForces(Ships_Att,{'CV':1,'FT':k,'CA':n_CA})
        #Forces['Defender']['DmgOrder'] = ['CV1']+['FT{}'.format(m) for m in range(k,0,-1)]
        out = Battle(Forces,BattleDict=BattleDict)
        BattleDict = out[2]
        outcomes_noWS += [(out[0],out[3],EasyOutcomes(out[0]))]
        
    n = 6
    #print 'Sabotage  %Winning  %Survive    Value'
    for k in range(7):
        combined = [0,0,0,0]
        # If the Sabotage Run is unsuccessful
        combined[0] += outcomes[n-k][2][2] * p_survivors(k,0)
        combined[1] += outcomes[n-k][2][1] * p_survivors(k,0)
        combined[2] += outcomes[n-k][2][0] * p_survivors(k,0)
        combined[3] += (outcomes[n-k][1][0] - outcomes[n-k][1][1] - 0.5*k) * p_survivors(k,0)
        #combined[3] += (outcomes[n-k][1][0] - outcomes[n-k][1][1]) * p_survivors(k,0)
        # If it is successful
        for l in range(1,k+1):
            combined[0] += outcomes_noWS[n-k+l][2][2] * p_survivors(k,l)
            combined[1] += outcomes_noWS[n-k+l][2][1] * p_survivors(k,l)
            combined[2] += outcomes_noWS[n-k+l][2][0] * p_survivors(k,l)       
            combined[3] += (outcomes_noWS[n-k+l][1][0] - outcomes_noWS[n-k+l][1][1] - 0.5*(k-l) + 12.) * p_survivors(k,l)
            #combined[3] += (outcomes_noWS[n-k+l][1][0] - outcomes_noWS[n-k+l][1][1]) * p_survivors(k,l)
        print '    {}        {:.3e}     {:.3e}   {:.4f}    {:.3f}'.format(k,*combined)

In [6]:
Example_Calc(0)


    0        2.325e-04     3.619e-04   0.9994    -5.382
    1        8.214e-03     3.514e-04   0.9914    -5.258
    2        9.395e-03     5.388e-04   0.9901    -5.146
    3        6.572e-03     5.366e-04   0.9929    -5.038
    4        3.302e-03     3.557e-04   0.9963    -4.909
    5        1.315e-03     1.695e-04   0.9985    -4.754
    6        4.627e-04     6.619e-05   0.9995    -4.578

In [7]:
Example_Calc(1)


    0        3.647e-03     4.192e-03   0.9922    -6.734
    1        1.544e-02     1.230e-03   0.9833    -6.753
    2        2.283e-02     7.421e-04   0.9764    -6.695
    3        2.267e-02     9.677e-04   0.9764    -6.648
    4        1.673e-02     1.050e-03   0.9822    -6.610
    5        9.485e-03     8.069e-04   0.9897    -6.549
    6        4.339e-03     4.512e-04   0.9952    -6.451

In [8]:
Example_Calc(2)


    0        2.695e-02     1.974e-02   0.9533    -7.329
    1        2.575e-02     7.857e-03   0.9664    -7.878
    2        3.434e-02     2.434e-03   0.9632    -8.048
    3        4.088e-02     1.110e-03   0.9580    -8.080
    4        3.947e-02     1.290e-03   0.9592    -8.102
    5        3.038e-02     1.499e-03   0.9681    -8.133
    6        1.855e-02     1.271e-03   0.9802    -8.146

In [9]:
Example_Calc(3)


    0        1.088e-01     4.763e-02   0.8435    -6.451
    1        6.305e-02     2.773e-02   0.9092    -8.079
    2        5.070e-02     1.220e-02   0.9371    -8.939
    3        5.482e-02     3.992e-03   0.9412    -9.300
    4        6.017e-02     1.490e-03   0.9383    -9.436
    5        5.761e-02     1.508e-03   0.9409    -9.526
    6        4.552e-02     1.843e-03   0.9526    -9.629

In [10]:
Example_Calc(4)


    0        2.762e-01     7.007e-02   0.6537    -3.809
    1        1.669e-01     5.589e-02   0.7772    -6.726
    2        1.022e-01     3.530e-02   0.8625    -8.768
    3        7.726e-02     1.666e-02   0.9061    -9.964
    4        7.577e-02     5.634e-03   0.9186    -10.533
    5        7.952e-02     1.861e-03   0.9186    -10.776
    6        7.578e-02     1.666e-03   0.9226    -10.939

In [11]:
Example_Calc(5)


    0        4.991e-01     7.043e-02   0.4305    -0.002
    1        3.497e-01     7.255e-02   0.5778    -3.783
    2        2.242e-01     6.174e-02   0.7140    -7.044
    3        1.414e-01     4.119e-02   0.8174    -9.487
    4        1.036e-01     2.043e-02   0.8759    -11.001
    5        9.645e-02     7.246e-03   0.8963    -11.758
    6        9.849e-02     2.282e-03   0.8992    -12.110

In [12]:
Example_Calc(6)


    0        7.091e-01     5.236e-02   0.2385    3.895
    1        5.684e-01     6.640e-02   0.3652    -0.011
    2        4.148e-01     7.238e-02   0.5128    -3.954
    3        2.756e-01     6.478e-02   0.6596    -7.522
    4        1.776e-01     4.545e-02   0.7770    -10.286
    5        1.293e-01     2.396e-02   0.8467    -12.046
    6        1.170e-01     9.108e-03   0.8739    -12.974

In [ ]: