Warhammer 40k stats tools
Project description
Warhammer Stats
This is a Python library providing components to generate PMFs for Warhammer 40000. This code was taken from the backend of https://www.warhammer-stats-engine.com/ and split out into its own package to make is easier for other developers to use.
Usage
You can use pip to fetch the latest version of the library. https://pypi.org/project/warhammer-stats/
pipenv install warhammer-stats
Example Usage
The example script:
from warhammer_stats import Attack, MultiAttack, PMFCollection, Target, Weapon
from warhammer_stats.modifiers.splitter_modifiers import \
OnAModifiableRollOfNAddAP
from warhammer_stats.utils.modifier_collection import ModifierCollection
# Define a modifier such that on a 6 to wound, add 3 AP to the
# attack.
weapon_mods = ModifierCollection(
wound_mods=[OnAModifiableRollOfNAddAP(6, 3)]
)
# Define the weapon. In this case it is a shuriken catapult with 2 shots, strength 4, AP 0 and damage 1.
# It has the modifiers defined above.
shuriken_catapult = Weapon(
bs=4,
shots=PMFCollection.static(2),
strength=4,
ap=0,
damage=PMFCollection.static(1),
modifiers=weapon_mods,
name='Shuriken Catapult',
)
# Define the weapon. In this case it is a bolter with 2 shots, strength 4, AP 0 and damage 1.
battle_canon = Weapon(
bs=4,
shots=PMFCollection.mdn(2, 6),
strength=8,
ap=2,
damage=PMFCollection.mdn(1, 3),
name='Battle Canon',
)
# Define the target. In this case it is a space marine eradicator with three wounds.
# He has no invulnerable or FNP so both are 7+ saves. He has a 4+ save.
space_marine = Target(
toughness=4,
save=3,
invuln=7,
fnp=7,
wounds=2,
name='Space Marine',
)
shuriken_results = Attack(shuriken_catapult, space_marine).run()
battle_canon_results = Attack(battle_canon, space_marine).run()
combined_results = MultiAttack([shuriken_catapult, battle_canon], space_marine).run()
# Print the mean of the kill distribution
print('shuriken_results', shuriken_results)
print('battle_canon_results', battle_canon_results)
print('combined_results', combined_results)
# If we want we can drill down into the results and see the probability distribution for each phase.
# For example, we can see the full probability distribution for the number of kills.
print('battle_canon_results.kills_dist', battle_canon_results.kills_dist)
# We can also see the cumulative probability distribution for the number of kills.
print('battle_canon_results.kills_dist.cumulative', battle_canon_results.kills_dist.cumulative())
Output:
> python example.py
shuriken_results AttackResults(
Mortal Wounds - avg: 0.0000, std: 0.0000
Self Wounds - avg: 0.0000, std: 0.0000
Total Damage - avg: 0.2083, std: 0.4320
Kills - avg: 0.0109, std: 0.1036
)
battle_canon_results AttackResults(
Mortal Wounds - avg: 0.0000, std: 0.0000
Self Wounds - avg: 0.0000, std: 0.0000
Total Damage - avg: 3.2406, std: 2.3625
Kills - avg: 1.4002, std: 1.1346
)
combined_results AttackResults(
Mortal Wounds - avg: 0.0000, std: 0.0000
Self Wounds - avg: 0.0000, std: 0.0000
Total Damage - avg: 3.4489, std: 2.4017
Kills - avg: 1.4111, std: 1.1394
)
battle_canon_results.kills_dist [0.2307, 0.3573, 0.2522, 0.1132, 0.0362, 0.0086, 0.0016, 0.0002, 0.0, 0.0]
battle_canon_results.kills_dist.cumulative [1.0, 0.7693, 0.412, 0.1598, 0.0466, 0.0104, 0.0018, 0.0002, 0.0, 0.0]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file warhammer_stats-0.1.1.tar.gz.
File metadata
- Download URL: warhammer_stats-0.1.1.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
183bbdac744554a80b361d2225ba3e58544eda511db91648b4860efa01719cfe
|
|
| MD5 |
714c85fbb0793b1123901624625b38bd
|
|
| BLAKE2b-256 |
f1e58ff981ea8dc7fee9ba7044544d6f55554c395e631dd1a5dec7628c990430
|
File details
Details for the file warhammer_stats-0.1.1-py3-none-any.whl.
File metadata
- Download URL: warhammer_stats-0.1.1-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2955b364a7780de406d4933f407bcc1b52012e4832e846387ba0eea14d0e8e04
|
|
| MD5 |
e9f9c83076f0b3e7d8fc72c016e53ce5
|
|
| BLAKE2b-256 |
0116d00b99426cd06ebceded00ae8f26295d871b227808da146e38e65f3c58cb
|