Simplify running more than one fight at a time

This still requires too much manual work, so I probably will change
things up again, but I wanted to have a record just in case.
This commit is contained in:
Nate Bowman
2026-10-18 17:44:17 -04:00
parent 93372fed4a
commit ec3eb15731
3 changed files with 167 additions and 30 deletions

View File

@@ -1,8 +1,10 @@
import itertools
import json
import math
from copy import deepcopy
from flashcards.config import config
from flashcards.types import BonusTypes
@@ -55,6 +57,28 @@ def get_bonuses_from_names(clss, names):
return bonuses
def generate_notes(bonuses):
if len(bonuses) > 0:
notes = f'with {" and ".join(bonuses)}'
else:
notes = ''
return notes
def _powerset(elements):
for size in range(len(elements) + 1):
for combo in itertools.combinations(elements, size):
yield list(combo)
def generate_all_combinations(attack, armor, hp):
attack_combos = _powerset(attack)
armor_combos = _powerset(armor)
hp_combos = _powerset(hp)
# must be a list; an iterator will be 'used up' after first time through
return list(itertools.product(attack_combos, armor_combos, hp_combos))
def calculate_hits_to_kill(attacker,
defender,
data,
@@ -128,3 +152,35 @@ def generate_fight_results(attacker,
results['notes'] = notes
return results
def generate_fight_results_from_names(attacker,
defender,
armor_class,
bonus_range,
data,
nums,
attack_bonus_names,
armor_bonus_names,
hp_bonus_names,
verbose):
attack_bonuses = get_bonuses_from_names(BonusTypes.ATTACK,
attack_bonus_names)
armor_bonuses = get_bonuses_from_names(BonusTypes.ARMOR,
armor_bonus_names)
hp_bonuses = get_bonuses_from_names(BonusTypes.HP,
hp_bonus_names)
notes = generate_notes(hp_bonus_names)
return generate_fight_results(attacker,
defender,
armor_class,
bonus_range,
data,
nums,
notes=notes,
extra_attack_bonuses=attack_bonuses,
extra_armor_bonuses=armor_bonuses,
hp_bonuses=hp_bonuses,
verbose=verbose)