Talent rolls in DSA

9

Some friends and I have played some DSA (a mainly german tabletop RPG much like D&D). I was wondering what the chance on passing rolls are, so you will have to write some code to calculate it.

Your character is defined by stats (from 8 to 14) and (TV) Talent values (0 to 21). For now we will use climbing as an example.

Talent tests

A talent (climbing) looks like this: (Courage-Dexterity-Strength) TV: 7. To test a character on a talent you roll on these stats with a 20-sided dice and try to get below or equal to the stat, if you do that well. If not, you can use your TV points to reduce the roll with a ratio of 1:1.

Example

A hunter with courage 12, dexterity 13 and strength 14 is trying to climb a tree, his TV is 7.

He rolls a 3, the value is below 12 so he passed that roll.

Then he rolls a 17, 17 is 4 more than 13, so 4 TV get used up with 3 left.

For the last roll you get a 14, spot on passed.

All rolls are passed and the hunter managed to climb the tree, 3 TV are left.

Input

4 values in any format you choose, taken from the standard input of your language. It has to be in this order though.

E.g. 12 13 14 7 or 12,13,14,7 or as an array {12,13,14,7} or mixed [12, 14, 8], 3

Output

The chance of how often the rolls pass.

E.g. (for values above)0.803

12,14,8,3 = 0.322

11,11,12,11 = 0.840

For the bonus: Again formating is not the issue here, output it however you like but in following order:

failed/with 0/with 1/with 2/with 3/with 4/with 5/with 6/with 7 

and so on until no TV is left.

12,13,14,7 = 0.197/0.075/0.089/0.084/0.078/0.073/0.068/0.063/0.273

12,14,8,3 = 0.678/0.056/0.051/0.047/0.168

Challenge and rules and bonus

  • You shall find out given the input the chance to pass the rolls to a +- 0.5% accuracy.

  • -20% if your program also outputs the chances to pass with n TV (see output).

  • This is , so shortest code in bytes wins!

Eumel

Posted 2016-01-03T14:38:47.487

Reputation: 2 487

1Does "4 values in any format you choose" include taking them in a different order? – Martin Ender – 2016-01-04T00:03:02.617

1Or something like [12, 14, 8], 3? – Martin Ender – 2016-01-04T00:04:19.500

I thought i had the order included, its in now. Mixed inputs are allowed as well. – Eumel – 2016-01-04T08:30:13.970

Answers

2

Pyth - 21 20 19 bytes

Saved 1 bytes thanks to @ThomasKwa

.Omgvzsg#0-VdQ^SyT3

Test Suite.

Maltysen

Posted 2016-01-03T14:38:47.487

Reputation: 25 023

Pyth is so good... This is APL's type of question, and I only have 27 in APL. – lirtosiast – 2016-01-03T23:18:50.940

the order of the input was suppoesed to be stat,stat,stat,TV i did only specify that now though. However if you can modify that easily that would be nice. Could you put in an explanation? – Eumel – 2016-01-04T08:38:34.910

@Eumel sure, changing the order shouldn't be as problem, I'm on a phone right now, I'll do it when I get home. – Maltysen – 2016-01-04T19:13:01.140

1

Dyalog APL, 28 bytes

{(+/÷⍴)⍵≥∊+/¨0⌈(⊂⍺)-⍨¨⍳3⍴20}

This approach is the same as @Maltysen's. We can't be sure of 0.5% accuracy if we just draw a few thousand random dice rolls, so we instead take the average over all possible rolls. This takes the three stats as the left argument, and the talent value on the right.

Try it here!

lirtosiast

Posted 2016-01-03T14:38:47.487

Reputation: 20 331