Skip to content

Instantly share code, notes, and snippets.

@jingibus
Created December 10, 2019 19:03
Show Gist options
  • Save jingibus/e70c93210089dae08f29b50d773e690c to your computer and use it in GitHub Desktop.
Save jingibus/e70c93210089dae08f29b50d773e690c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import csv, sys
vocal = False
high_prob = 0.33
low_prob = high_prob / 2
high_prob_miss = 1 - high_prob
low_prob_miss = 1 - low_prob
global counter
counter = 0
class Hardpoint:
def __init__(self, p, damage):
global counter
self.p = p
self.damage = damage
self.id = counter
counter += 1
def __repr__(self):
return "(" + ", ".join([str(x) for x in [self.id, self.p, self.damage]]) + ")"
def prob_of_reaching_damage(hardpoints, min_damage):
if min_damage <= 0:
if vocal:
print 'hardpoints always reach', min_damage, ':', hardpoints
return 1.0
if not hardpoints:
if vocal:
print 'no hardpoints always fail to reach', min_damage
return 0.0
hardpoint, rest_hardpoints = hardpoints[0], hardpoints[1:]
prob_if_hits = prob_of_reaching_damage(rest_hardpoints, min_damage - hardpoint.damage)
prob_if_misses = prob_of_reaching_damage(rest_hardpoints, min_damage)
prob = prob_if_hits * hardpoint.p + prob_if_misses * (1 - hardpoint.p)
if vocal:
print 'For hardpoints', hardpoints, 'if first one hits, we are', prob_if_hits, 'likely to reach', min_damage, 'otherwise', prob_if_misses
print 'So prob is', prob
return prob
class Configuration:
def __init__(self, name, hardpoints):
self.name =name
self.hardpoints = hardpoints
def make(damage, count):
return [Hardpoint(high_prob, damage) for x in range(count)]
def make_uacs(damage, count):
return make(damage, count) + [Hardpoint(low_prob, damage) for x in range(count)]
def report_to_csv(damage_list, configurations, output):
csvout = csv.writer(output)
columns = ['Hardpoints'] + ['Prob of ' + str(damage) + ' dam to head' for damage in damage_list]
csvout.writerow(columns)
for configuration in configurations:
row = ([configuration.name] + [str(prob_of_reaching_damage(configuration.hardpoints, min_damage))
for min_damage in damage_list])
csvout.writerow(row)
def reddit_report(damage_list, configurations):
for min_damage in damage_list:
print '\nProbability to reach', min_damage, ':'
for conf in configurations:
print '*', conf.name, ':', prob_of_reaching_damage(conf.hardpoints, min_damage)
configurations = [
Configuration('1 UAC2++ & 4 ER MLas++', make_uacs(35, 1) + make(45, 4)),
Configuration('2 UAC2++ & 4 ER MLas++', make_uacs(35, 2) + make(45, 4)),
Configuration('3 UAC2++ & 4 ER MLas++', make_uacs(35, 3) + make(45, 4)),
Configuration('3 UAC2++ & 4 ER MLas++ && 2 ER SLas++', make_uacs(35, 3) + make(45, 4) + make(40, 2)),
Configuration('3 UAC2++ & 2 LLas++dam', make_uacs(35, 3) + make(50, 2)),
Configuration('2 UAC5 & 4 ER MLas++', make_uacs(45, 2) + make(45, 4)),
Configuration('4 LLas++dam', make(50, 4)),
Configuration('2 ER PPC++', make(70, 2)),
Configuration('2 Gauss', make(75, 2)),
]
damage_list = [61, 77, 102]
report_to_csv(damage_list, configurations, sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment