prkill - script to calculate %-to-kill

Discussion among members of the development team.

Moderator: Forum Moderators

ott
Inactive Developer
Posts: 838
Joined: September 28th, 2004, 10:20 am

prkill - script to calculate %-to-kill

Post by ott »

Here is a a perl script to calculate exact probabilities that units A and B kill each other during a skirmish. A is the attacker, while B defends.

prkill calculates the joint probability function of the number of hitpoints each unit has remaining after each swing. After the last swing, the probabilities that A kills B, B kills A, and both survive are then printed. The joint probability function is also printed (the hitpoints of A are along the X axis, of B along the Y axis), unless neither unit is likely to survive. The output should be identical to the earlier versions (pre-1.9), which used the binomial distribution of number of hits, but couldn't handle "drain". The new method is currently slower for units with many hitpoints, but is more general and hopefully easier to understand.

The method in prkill version 1.5 is used by the game currently (since 0.9.1+cvs). This is available in-game from the "Damage Calculations" option in the Attack menu. The new method in version 1.9 is scheduled to be implemented in-game but only after 1.0 is released.

Please note that the in-game display will not show these statistics if one of the units has drain, or if one of the units has slow on its attack and the skirmish involves berserk, since these cases are not properly dealt with yet. The script has the same limitation on "berserk+slow", but it does now support drain.

For each of the two units involved in the skirmish, you need to specify commandline options for %-to-hit, number of swings, damage per swing (you will need to modify the base damage by the time of day and any resistances/vulnerabilities against the given damage type), and the hitpoints each unit has before the skirmish. You can also specify if "berserk" is active for this skirmish, and if B has firststrike active during this skirmish (ie. B has firststrike on this attack type but A doesn't). In addition, you can specify if either A or B has drain on its attack (or both do).

Run prkill --help to see the list of command line options.

As an example, to calculate the probabilities for a a slightly injured Ulfserker attacking a Thief, both standing in grassland during the day:

Code: Select all

prkill -p 0.4 -P 0.7 -n 4 -N 3 -d 5 -D 4 -h 36 -H 24 -x

A: 36hp, 5-4, B: 24hp, 4-3 berserk
Pr[A kills B] =     81.3392%
Pr[B kills A] =     18.6608%
Pr[both survive] =   0.0000%
And here is a Wraith attacking an Ulfserker, both on mountains at dawn:

Code: Select all

prkill -p 0.5 -P 0.5 -n 4 -N 4 -d 5 -D 2 -h 25 -H 40 -x

A: 25hp, 5-4 (2 drain), B: 40hp, 2-4 berserk
Pr[A kills B] =     99.9449%
Pr[B kills A] =      0.0550%
Pr[both survive] =   0.0000%
Finally, the same situation but the Wraith against an injured Goblin Spearman:

Code: Select all

prkill -p 0.4 -P 0.5 -n 4 -N 3 -d 7 -D 4 -h 25 -H 14 -r -y

A: 25hp, 7-4 (3 drain), B: 14hp, 4-3 firststrike
Pr[A kills B] =     52.4800%
Pr[B kills A] =      0.0000%
Pr[both survive] =  47.5200%
History:
1.1 initial release
1.2 fixes a problem in reduce() which gave incorrect results for Troll vs. Revenant at night, but most results should still be very similar
1.3-1.4 unreleased
1.5 simplified calculations, made option names more rational, added --help, added firststrike support
1.6-1.8 unreleased
1.9 changed to new method, now supports drain

Planned is pod documentation (ie. a man page), and support for "berserk+slow", which is not currently handled. Possible enhancements include calculating the damage-per-swing based on time of day, alignment, leadership, resistances and specials like backstab or charge: but don't hold your breath, this is likely to be a separate script.
Attachments
prkill19.zip
perl script to calculate %-to-kill
(2.13 KiB) Downloaded 2957 times
Last edited by ott on July 10th, 2005, 4:28 pm, edited 3 times in total.
This quote is not attributable to Antoine de Saint-Exupéry.
freecraft
Posts: 94
Joined: April 28th, 2005, 12:49 am
Location: Serbia
Contact:

Re: prkill - script to calculate %-to-kill

Post by freecraft »

ott wrote: An energetic C++ coder should be able to add this easily to the in-game "Show defence calculations" dialogue box.
Well, nice script!

However, I am against this what I have quoted ... Well, I think players should think by themselfes, not using scripts that will prognose them shall they win or lose an unit ... Ofcourse, I like your script (although i haven't tested it yet - I know what it does) because it is good for learning ... but, in game ... I preffer brain thinking :)
User avatar
Elvish_Pillager
Posts: 8137
Joined: May 28th, 2004, 10:21 am
Location: Everywhere you think, nowhere you can possibly imagine.
Contact:

Re: prkill - script to calculate %-to-kill

Post by Elvish_Pillager »

freecraft wrote:Well, I think players should think by themselfes, not using scripts that will prognose them shall they win or lose an unit ...
I am against any concealing of information from the player, especially when the player could get that information by a more frustrating process, so I support the inclusion of this in the attack dialog.
It's all fun and games until someone loses a lawsuit. Oh, and by the way, sending me private messages won't work. :/ If you must contact me, there's an e-mail address listed on the website in my profile.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Re: prkill - script to calculate %-to-kill

Post by turin »

Elvish Pillager wrote:
freecraft wrote:Well, I think players should think by themselfes, not using scripts that will prognose them shall they win or lose an unit ...
I am against any concealing of information from the player, especially when the player could get that information by a more frustrating process, so I support the inclusion of this in the attack dialog.
Agreed.

This is why I also support showing gold values for non fog/shroud games. AFAIK, this has yet to be done.
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
User avatar
Jetrel
Posts: 7242
Joined: February 23rd, 2004, 3:36 am
Location: Midwest US

Re: prkill - script to calculate %-to-kill

Post by Jetrel »

Elvish Pillager wrote:
freecraft wrote:Well, I think players should think by themselfes, not using scripts that will prognose them shall they win or lose an unit ...
I am against any concealing of information from the player, especially when the player could get that information by a more frustrating process, so I support the inclusion of this in the attack dialog.
Agreed.
ott
Inactive Developer
Posts: 838
Joined: September 28th, 2004, 10:20 am

Post by ott »

This feature has now been in CVS for a week, in synch with this script.
This quote is not attributable to Antoine de Saint-Exupéry.
User avatar
Elvish_Pillager
Posts: 8137
Joined: May 28th, 2004, 10:21 am
Location: Everywhere you think, nowhere you can possibly imagine.
Contact:

Post by Elvish_Pillager »

Well, I've played with it, and I'm actually pretty disappointed. I could get a pretty good estimate just by thinking, and since it's in Damage Calculations, it's rather inconvenient to reach.

If it was on the main attack screen, it would be much more useful to me.

I'll try to cook up a sample image of where it could go, soon.

EDIT: also another problem I forgot. It *shouldn't* say "Both should survive" when an Elvish Archer shoots (6-4) at a 22HP, 70%, Thief. (0.81% ctk)
It's all fun and games until someone loses a lawsuit. Oh, and by the way, sending me private messages won't work. :/ If you must contact me, there's an e-mail address listed on the website in my profile.
ryn
Posts: 196
Joined: August 23rd, 2004, 4:01 am
Location: Israel

Post by ryn »

Nor should it give berserkers 100% to kill in some situations. I think what EP wants to say is that your program should round towards 50 - that is, away from 100 and 0.
2B |! 2B = 3F
js138
Posts: 145
Joined: February 23rd, 2005, 7:45 pm
Location: Cambridge
Contact:

Post by js138 »

Well an alternative is to distinguish between 0% and 0.0005% and by calling one 0% and the other 0+% o

similarly 100% could be '100%' and 99.9995% could be '99+%'

Then you can round to nearest for values inbetween.

You could come up with english phrases which would describe those 0+ and 99+ states better, but then you have to translate them.
ott
Inactive Developer
Posts: 838
Joined: September 28th, 2004, 10:20 am

Post by ott »

I'm glad to hear EP found the feature disappointing. I would be very worried if the routine gave different results to the intuitive calculations of an experienced player!

The Damage Calculations dialog is perhaps not ideal, but it seemed the most logical place to put it at the time. A mockup of another place it could go would be welcome, though it might have to wait until post-1.0.

Saying "both should survive" seems reasonable if the probability that this doesn't happen is very small -- perhaps the cutoff is too high, though.

Thanks to js138 for the 0+/99+ idea, something like that would make sense.
This quote is not attributable to Antoine de Saint-Exupéry.
User avatar
Elvish_Pillager
Posts: 8137
Joined: May 28th, 2004, 10:21 am
Location: Everywhere you think, nowhere you can possibly imagine.
Contact:

Post by Elvish_Pillager »

ott wrote:Saying "both should survive" seems reasonable if the probability that this doesn't happen is very small -- perhaps the cutoff is too high, though.
Even if you want to preserve this for extremely low chances, I think that it should say "Both will survive" when it's a guarantee.

P.S.:
Attachments
chance to kill.png
chance to kill.png (77.73 KiB) Viewed 11308 times
It's all fun and games until someone loses a lawsuit. Oh, and by the way, sending me private messages won't work. :/ If you must contact me, there's an e-mail address listed on the website in my profile.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

You put the "35% chance to kill" text in the space where the attack special goes! How is that going to work?
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
User avatar
Elvish_Pillager
Posts: 8137
Joined: May 28th, 2004, 10:21 am
Location: Everywhere you think, nowhere you can possibly imagine.
Contact:

Post by Elvish_Pillager »

turin wrote:You put the "35% chance to kill" text in the space where the attack special goes! How is that going to work?
Attachments
Woot! Attack of the magic sword!
Woot! Attack of the magic sword!
chance to kill.png (78.7 KiB) Viewed 11448 times
It's all fun and games until someone loses a lawsuit. Oh, and by the way, sending me private messages won't work. :/ If you must contact me, there's an e-mail address listed on the website in my profile.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

Well, that is a good setup.
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
claus
Posts: 186
Joined: April 4th, 2005, 5:51 am

Post by claus »

You might get problems with some attacks (for example "lightbeam" and "water spray" both need more space than "sword")
Post Reply