Created
December 10, 2019 21:30
-
-
Save jingibus/230991421c1bd396ce0256b801bedf68 to your computer and use it in GitHub Desktop.
Headcapping v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import csv, sys, math | |
vocal = False | |
high_prob = 0.33 | |
low_prob = high_prob / 2 | |
high_prob_miss = 1 - high_prob | |
low_prob_miss = 1 - low_prob | |
base_to_hit = 0.95 | |
global counter | |
counter = 0 | |
class Hardpoint: | |
def __init__(self, p, damage, structure=0): | |
global counter | |
self.p = p * base_to_hit | |
self.damage = damage | |
self.id = counter | |
self.structure = structure | |
counter += 1 | |
def damage_for_cover(self, cover_multiplier): | |
return math.floor(self.damage * cover_multiplier) + self.structure | |
def __repr__(self): | |
return "(" + ", ".join([str(x) for x in [self.id, self.p, self.damage]]) + ")" | |
def prob_of_reaching_damage(hardpoints, min_damage, cover_multiplier=1): | |
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_for_cover(cover_multiplier), cover_multiplier=cover_multiplier) | |
prob_if_misses = prob_of_reaching_damage(rest_hardpoints, min_damage, cover_multiplier = cover_multiplier) | |
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 make_gauss(count): | |
return [Hardpoint(high_prob, 70, structure=5) for x in range(count)] | |
def report_to_csv(damage_list, cover_list, configurations, output): | |
csvout = csv.writer(output) | |
columns = ['Hardpoints'] | |
for damage in damage_list: | |
columns += [str(damage) + 'dam, cover ' + str(cover) for cover in cover_list] | |
csvout.writerow(columns) | |
for configuration in configurations: | |
row = [configuration.name] | |
for min_damage in damage_list: | |
row += [('%.3f'%prob_of_reaching_damage(configuration.hardpoints, min_damage, cover_multiplier=cover)) | |
for cover in cover_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_gauss(2)), | |
Configuration('2 AC20', make(100, 2)), | |
Configuration('2 AC20++', make(120, 2)), | |
Configuration('2 UAC20', make_uacs(100, 2)), | |
Configuration('2 UAC20++', make_uacs(120, 2)), | |
Configuration('3 UAC2++ & PPC++dam', make_uacs(35, 3) + make(60, 1)), | |
Configuration('1 Gauss & 2LLas', make_gauss(1) + make(40, 2)), | |
Configuration('1 Gauss & 2LLas++dam', make_gauss(1) + make(50, 2)), | |
Configuration('1 UAC2++ & 2 ER PPC++', make_uacs(35, 1) + make(70, 2)), | |
] | |
damage_list = [61, 38, 27] | |
cover_list = [1, 0.8, 0.6] | |
report_to_csv(damage_list, cover_list, configurations, sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment