Add function to simulate simple fighting
This is not yet complete. I think I'm going to go a different way with using bonus (research) information, but I wanted a copy of this in the history just in case.
This commit is contained in:
146
data/bonuses.json
Normal file
146
data/bonuses.json
Normal file
@@ -0,0 +1,146 @@
|
||||
{
|
||||
"points": {
|
||||
"armor": {
|
||||
"Parthian Tactics": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Gambesons": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Padded Archer Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Leather Archer Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Ring Archer Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Scale Barding Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Chain Barding Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Plate Barding Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Scale Mail Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Chain Mail Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Plate Mail Armor": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Masonry": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3},
|
||||
{"Amount": 3, "Class": 11}
|
||||
},
|
||||
"Architecture": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 1, "Class": 3},
|
||||
{"Amount": 3, "Class": 11}
|
||||
},
|
||||
"Careening": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Dry Dock": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Loom": {
|
||||
{"Amount": 1, "Class": 4},
|
||||
{"Amount": 2, "Class": 3}
|
||||
}
|
||||
},
|
||||
"attack": {
|
||||
"Parthian Tactics": {
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Arson": {
|
||||
{"Amount": 2, "Class": 16}
|
||||
},
|
||||
"Forging": {
|
||||
{"Amount": 1, "Class": 4}
|
||||
},
|
||||
"Iron Casting": {
|
||||
{"Amount": 1, "Class": 4}
|
||||
},
|
||||
"Blast Furnace": {
|
||||
{"Amount": 2, "Class": 4}
|
||||
},
|
||||
"Fletching": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Bodkin Arrow": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Bracer": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Chemistry": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Heated Shot (Castle, Krepost, or Harbor)": {
|
||||
{"Amount": 4, "Class": 16}
|
||||
},
|
||||
"Sappers": {
|
||||
{"Amount": 15, "Class": 11},
|
||||
{"Amount": 15, "Class": 13},
|
||||
{"Amount": 3, "Class": 17}
|
||||
},
|
||||
"Arrowslits (Watch Tower)": {
|
||||
{"Amount": 1, "Class": 3}
|
||||
},
|
||||
"Arrowslits (Guard Tower)": {
|
||||
{"Amount": 2, "Class": 3}
|
||||
},
|
||||
"Arrowslits (Keep or Donjon)": {
|
||||
{"Amount": 3, "Class": 3}
|
||||
}
|
||||
},
|
||||
"hp": {
|
||||
"Bloodlines": 20,
|
||||
"Hoardings": 1000,
|
||||
"Sanctity": 15,
|
||||
"Loom": 15
|
||||
}
|
||||
},
|
||||
"percents": {
|
||||
"attack": {
|
||||
"Siege Engineers (siege)": {
|
||||
{"Amount": 20, "Class": 11},
|
||||
{"Amount": 20, "Class": 13},
|
||||
{"Amount": 20, "Class": 21},
|
||||
{"Amount": 20, "Class": 22},
|
||||
{"Amount": 20, "Class": 26}
|
||||
},
|
||||
"Siege Engineers (demo)": {
|
||||
{"Amount": 40, "Class": 11},
|
||||
{"Amount": 40, "Class": 13},
|
||||
{"Amount": 40, "Class": 21},
|
||||
{"Amount": 40, "Class": 22},
|
||||
{"Amount": 40, "Class": 26}
|
||||
},
|
||||
"Heated Shot (Tower)": {
|
||||
{"Amount": 125, "Class": 16}
|
||||
}
|
||||
},
|
||||
"hp": {
|
||||
"Masonry": 10,
|
||||
"Architecture": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
26
example-fighting.py
Normal file
26
example-fighting.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from flashcards.maps import (create_maps,
|
||||
read_data_to_dict,
|
||||
read_name_data_to_dict,
|
||||
read_string_data_to_dict)
|
||||
from flashcards.fighting import calculate_hits_to_kill
|
||||
|
||||
|
||||
|
||||
# specify the namelist to be used to create the deck
|
||||
# give the relative path of the file from config.namelists_dir
|
||||
namelist = 'units-basic.txt'
|
||||
|
||||
# key into json file specifying which data you want
|
||||
name_json_keys = 'units_buildings'
|
||||
data_json_keys = ('data', 'Unit')
|
||||
string_json_keys = ()
|
||||
|
||||
#name_data = read_name_data_to_dict(string_json_keys)
|
||||
_, nums = create_maps(namelist, name_json_keys)
|
||||
data = read_data_to_dict(data_json_keys)
|
||||
|
||||
hits = calculate_hits_to_kill('Hulk',
|
||||
'Fire Ship',
|
||||
data,
|
||||
nums)
|
||||
print(hits)
|
||||
49
flashcards/fighting.py
Normal file
49
flashcards/fighting.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import math
|
||||
|
||||
|
||||
|
||||
def _calculate_bonus(orig, bonuses, attack=False):
|
||||
for b in bonuses:
|
||||
b_amount, b_clss = b.values()
|
||||
used = False
|
||||
for iorig in range(len(orig)):
|
||||
_, clss = orig[iorig].values()
|
||||
if clss == b_clss:
|
||||
orig[iorig]['Amount'] += b_amount
|
||||
used = True
|
||||
if attack and not used:
|
||||
# bonus can add an attack but should not add an armor type
|
||||
orig.append(b)
|
||||
|
||||
|
||||
def calculate_hits_to_kill(attacker,
|
||||
defender,
|
||||
data,
|
||||
nums,
|
||||
attack_bonuses=[],
|
||||
armor_bonuses=[],
|
||||
hp_bonus=0):
|
||||
# Get base values
|
||||
attacks = data[nums[attacker]]['Attacks']
|
||||
armors = data[nums[defender]]['Armours']
|
||||
hp = data[nums[defender]]['HP']
|
||||
|
||||
# Apply any bonuses from technologies or civilizations
|
||||
_calculate_bonus(attacks, attack_bonuses, attack=True)
|
||||
_calculate_bonus(armors, armor_bonuses)
|
||||
hp += hp_bonus
|
||||
|
||||
# TODO incorporate percent bonuses as well in separate function
|
||||
# TODO use json data for hp_bonus instead of just a number
|
||||
|
||||
damage = 0
|
||||
for a in attacks:
|
||||
amount, clss = a.values()
|
||||
for d in armors:
|
||||
d_amount, d_clss = d.values()
|
||||
if clss == d_clss:
|
||||
damage += max(0, amount - d_amount)
|
||||
damage = max(1, damage)
|
||||
|
||||
hits = math.ceil(hp/damage)
|
||||
return hits
|
||||
Reference in New Issue
Block a user