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)
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)
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)
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)
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))
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)
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)
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)
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)
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)
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)
In [7]:
Example_Calc(1)
In [8]:
Example_Calc(2)
In [9]:
Example_Calc(3)
In [10]:
Example_Calc(4)
In [11]:
Example_Calc(5)
In [12]:
Example_Calc(6)
In [ ]: