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]
Metadata
Release files for warhammer-stats 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| warhammer_stats-0.1.1.tar.gz | 21.3 kB | Without provenance | Details for warhammer_stats-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| warhammer_stats-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for warhammer_stats-0.1.1-py3-none-any.whl |
Total release size: 51.0 kB
Release files / warhammer_stats-0.1.1.tar.gz
| Download URL | warhammer_stats-0.1.1.tar.gz |
|---|---|
| Size | 21.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
183bbdac744554a80b361d2225ba3e58544eda511db91648b4860efa01719cfe
|
|
BLAKE2b-256 checksum How to use checksums |
f1e58ff981ea8dc7fee9ba7044544d6f55554c395e631dd1a5dec7628c990430
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.14
|
Release files / warhammer_stats-0.1.1-py3-none-any.whl
| Download URL | warhammer_stats-0.1.1-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2955b364a7780de406d4933f407bcc1b52012e4832e846387ba0eea14d0e8e04
|
|
BLAKE2b-256 checksum How to use checksums |
0116d00b99426cd06ebceded00ae8f26295d871b227808da146e38e65f3c58cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.14
|
Security for warhammer-stats 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.