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:
@@ -1,9 +1,11 @@
|
|||||||
|
import itertools
|
||||||
|
|
||||||
|
from flashcards.constants import UnitLines, ranges
|
||||||
from flashcards.maps import (create_maps,
|
from flashcards.maps import (create_maps,
|
||||||
read_data_to_dict,
|
read_data_to_dict,
|
||||||
read_name_data_to_dict)
|
read_name_data_to_dict)
|
||||||
from flashcards.fighting import (generate_fight_results,
|
from flashcards.fighting import (generate_all_combinations,
|
||||||
get_bonuses_from_names)
|
generate_fight_results_from_names)
|
||||||
from flashcards.types import ArmorClasses, BonusTypes
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,39 +19,43 @@ namelist = 'units-buildings-trimmed.txt'
|
|||||||
name_json_keys = 'units_buildings'
|
name_json_keys = 'units_buildings'
|
||||||
data_json_keys = ('data', 'Unit')
|
data_json_keys = ('data', 'Unit')
|
||||||
|
|
||||||
_, nums = create_maps(namelist, name_json_keys)
|
|
||||||
data = read_data_to_dict(data_json_keys)
|
|
||||||
|
|
||||||
# --- Fight details start here
|
# --- Fight details start here
|
||||||
|
|
||||||
attacker = 'Spearman'
|
attacker_line = 'Spearman'
|
||||||
defender = 'Scout Cavalry'
|
defender_line = 'Knight'
|
||||||
bonus_range = range(-3, 5)
|
#defender_line = 'Scout Cavalry'
|
||||||
armor_class = ArmorClasses.MELEE
|
range_type = 'standard'
|
||||||
notes = 'with Bloodlines'
|
|
||||||
suffix = ''
|
|
||||||
|
|
||||||
hp_bonus_names = ['Bloodlines']
|
# extra bonuses beyond the usual blacksmith upgrades and bloodlines
|
||||||
|
hp_bonus_names = []
|
||||||
attack_bonus_names = []
|
attack_bonus_names = []
|
||||||
armor_bonus_names = []
|
armor_bonus_names = []
|
||||||
|
|
||||||
# --- You shouldn't need to change below this line
|
# --- Shouldn't need to change below this line
|
||||||
|
|
||||||
hp_bonuses = get_bonuses_from_names(BonusTypes.HP, hp_bonus_names)
|
_, nums = create_maps(namelist, name_json_keys)
|
||||||
attack_bonuses = get_bonuses_from_names(BonusTypes.ATTACK, attack_bonus_names)
|
data = read_data_to_dict(data_json_keys)
|
||||||
armor_bonuses = get_bonuses_from_names(BonusTypes.ARMOR, armor_bonus_names)
|
|
||||||
|
|
||||||
results = generate_fight_results(attacker,
|
attack_type = UnitLines.get_attack(attacker_line)
|
||||||
|
bonus_range = ranges[attack_type][range_type]
|
||||||
|
|
||||||
|
built_in_hp_bonus_names = UnitLines.get_hp_bonus_names(defender_line)
|
||||||
|
all_hp_bonus_names = hp_bonus_names + built_in_hp_bonus_names
|
||||||
|
bonus_names_combinations = generate_all_combinations(attack_bonus_names,
|
||||||
|
armor_bonus_names,
|
||||||
|
all_hp_bonus_names)
|
||||||
|
|
||||||
|
for attacker, defender in itertools.product(UnitLines.get_names(attacker_line),
|
||||||
|
UnitLines.get_names(defender_line)):
|
||||||
|
for combo in bonus_names_combinations:
|
||||||
|
results = generate_fight_results_from_names(attacker,
|
||||||
defender,
|
defender,
|
||||||
armor_class,
|
attack_type,
|
||||||
bonus_range,
|
bonus_range,
|
||||||
data,
|
data,
|
||||||
nums,
|
nums,
|
||||||
notes=notes,
|
combo[0],
|
||||||
extra_attack_bonuses=attack_bonuses,
|
combo[1],
|
||||||
extra_armor_bonuses=armor_bonuses,
|
combo[2],
|
||||||
hp_bonuses=hp_bonuses,
|
True)
|
||||||
verbose=True)
|
|
||||||
|
|
||||||
# --- TODO write file
|
|
||||||
print(results)
|
print(results)
|
||||||
|
|||||||
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 json
|
||||||
import math
|
import math
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from flashcards.config import config
|
from flashcards.config import config
|
||||||
|
from flashcards.types import BonusTypes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -55,6 +57,28 @@ def get_bonuses_from_names(clss, names):
|
|||||||
return bonuses
|
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,
|
def calculate_hits_to_kill(attacker,
|
||||||
defender,
|
defender,
|
||||||
data,
|
data,
|
||||||
@@ -128,3 +152,35 @@ def generate_fight_results(attacker,
|
|||||||
|
|
||||||
results['notes'] = notes
|
results['notes'] = notes
|
||||||
return results
|
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