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:
75
flashcards/constants.py
Normal file
75
flashcards/constants.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from flashcards.types import ArmorClasses
|
||||
|
||||
|
||||
|
||||
ranges = {ArmorClasses.MELEE: {
|
||||
'standard': range(-3, 5),
|
||||
'parthian tactics (armor)': range(-3, 5),
|
||||
'villager': range(-3, 5),
|
||||
},
|
||||
ArmorClasses.PIERCE: {
|
||||
'standard': range(-4, 5),
|
||||
'parthian tactics (armor)': range(-6, 5),
|
||||
'parthian tactics (attack)': range(-4, 7),
|
||||
'gambesons': range(-5, 5),
|
||||
'villager': range(-2, 5),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class UnitLines():
|
||||
|
||||
lines = {'Scout Cavalry': {
|
||||
'names': [
|
||||
'Scout Cavalry',
|
||||
'Light Cavalry',
|
||||
'Hussar'
|
||||
],
|
||||
'attack_type': ArmorClasses.MELEE,
|
||||
'hp_bonus_names': ['Bloodlines'],
|
||||
},
|
||||
'Spearman': {
|
||||
'names': [
|
||||
'Spearman',
|
||||
'Pikeman',
|
||||
'Halberdier'
|
||||
],
|
||||
'attack_type': ArmorClasses.MELEE,
|
||||
},
|
||||
'Knight': {
|
||||
'names': [
|
||||
'Knight',
|
||||
'Cavalier',
|
||||
'Paladin'
|
||||
],
|
||||
'attack_type': ArmorClasses.MELEE,
|
||||
'hp_bonus_names': ['Bloodlines'],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_names(cls, name: str) -> list(str):
|
||||
line = cls.lines[name]
|
||||
try:
|
||||
names = line['names']
|
||||
except KeyError:
|
||||
names = [name]
|
||||
print(names)
|
||||
return names
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_attack(cls, name: str) -> ArmorClasses:
|
||||
return cls.lines[name]['attack_type']
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_hp_bonus_names(cls, name: str) -> list(str):
|
||||
line = cls.lines[name]
|
||||
try:
|
||||
bonuses = line['hp_bonus_names']
|
||||
except KeyError:
|
||||
bonuses = []
|
||||
return bonuses
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user