[MUD-Dev] Chances of success (Bobby's algorithm)
Bobby Martin
bobbymartin at hotmail.com
Mon Aug 20 04:22:45 CEST 2001
This is a multi-part message in MIME format.
------=_NextPart_000_2015_25cb_4325
Content-Type: text/plain; format=flowed
I had said I was going to publish the algorithm we use in Cosm to
calculate skill successes, so here it is. I've attached a
standalone java class that does some simple testing and reporting on
the behavior of the system.
First, you "roll" a random number in the interval [0,1]. This is
essentially a d1000/1000, if you prefer to think of it that way.
Call this number 'roll'.
Then, you calculate the chance of success. The chance of success is
the ratio of your skill level to the sum of (your skill level + the
difficulty).
Here is that calculation:
chanceOfSuccess = skillLevel/(skillLevel + difficulty);
A simple comparison of the roll to the chance of success determines
whether the character succeeded at all in his endeavor (roll >
chance of success indicates failure).
If he succeeded, we now find out how well. This is the hardish
part, you can just kind of take my word for it if you like, or you
can work it out for yourself. My goal here was first to make it so
that 70% of successes were level 1, 70% of the remaining successes
were level 2, 70% of the remaining after that were level 3, etc.
So, if you compare the chanceOfSuccess to roll*(.7)^level like so:
chanceOfSuccess < roll*(.7)^level to achieve the above goal you need
to find the largest level for which the above equation is true. I
use some logarithms and come up with:
degreeOfSuccess = log(roll) - log(chanceOfSuccess)/
log(.7);
Unfortunately, once a character has achieved success, this will
distribute the success levels the same regardless of the comparison
of skillLevel to difficulty. To remedy that, I scale by the
multiplicative inverse of (1 - chanceOfSuccess). This means if you
have twice the likelihood of succeeding, you will also generally get
twice the degreeOfSuccess.
degreeOfSuccess *= (1.0/(1.0-chanceOfSuccess));
I have tested this and am pretty pleased with the results. Note
that difficulty is on the same scale as skillLevel, so skill
vs. skill tests happen the way you would want. To assign a
difficulty to a task, just pick the skill level that you want to
have a 50% chance of success; that's your difficulty. Characters
with low skills still have a small but significant chance of getting
a 30-40 degreeOfSuccess, but most of the time will fail. Characters
with high skills will mostly get 70s & above on degreeOfSuccess, but
still have a small but significant chance of failure.
Anyway, javac the attached file and play with it if you like.
Regards,
Bobby Martin
Cosm Development Team
secure email: bobbymartin at hushmail.com
------=_NextPart_000_2015_25cb_4325
Content-Type: application/octet-stream; name="testsuccess.java"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="testsuccess.java"
aW1wb3J0IGphdmEudXRpbC4qOw0KDQovLyBUaGlzIGlzIHB1YmxpYyBkb21h
aW47IHVzZSBpdCBhcyB5b3UgbGlrZS4gIEkgdGFrZSBubyByZXNwb25zaWJp
bGl0eQ0KLy8gb2YgZml0bmVzcyBmb3IgYW55IHB1cnBvc2UsIG9mIGNvdXJz
ZS4gIElmIHlvdSB1c2UgaXQsIEkgd291bGQNCi8vIGFwcHJlY2lhdGUgYW4g
YWNrbm93bGVkZ2VtZW50Lg0KLy8gQm9iYnkgTWFydGluDQoNCnB1YmxpYyBj
bGFzcyB0ZXN0c3VjY2Vzcw0Kew0KICAgIHB1YmxpYyBzdGF0aWMgZmluYWwg
UmFuZG9tIHJhbmRvbSA9IG5ldyBSYW5kb20oKTsNCiAgICBwcm90ZWN0ZWQg
c3RhdGljIGZpbmFsIGZsb2F0IFNVQ0NFU1NfSU5DUkVNRU5UID0gLjdmOw0K
DQogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykN
CiAgICB7DQogICAgICAgIGludCBza2lsbExldmVsID0gSW50ZWdlci5wYXJz
ZUludChhcmdzWzBdKTsNCiAgICAgICAgZm9yKCBpbnQgaSA9IDA7IGkgPCBh
cmdzLmxlbmd0aDsgKytpICkNCiAgICAgICAgew0KICAgICAgICAgICAgdGVz
dFN1Y2Nlc3NBbGdvKHNraWxsTGV2ZWwsIEludGVnZXIucGFyc2VJbnQoYXJn
c1tpXSkpOw0KICAgICAgICB9DQogICAgfQ0KDQogICAgcHVibGljIHN0YXRp
YyB2b2lkIHRlc3RTdWNjZXNzQWxnbyhpbnQgc2tpbGxMZXZlbCwgaW50IG9w
cG9zaW5nVmFsdWUpDQogICAgew0KCWNoZWNrU3VjY2Vzcyhza2lsbExldmVs
LCBvcHBvc2luZ1ZhbHVlLC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
ICAgIC8vc2NhbGUgYnkgdGhlIGludmVyc2Ugb2YgdGhlIGNoYW5jZSBvZiBm
YWlsdXJlLi4uICBpZiB5b3VyDQoJICAgIC8vc2tpbGwgaXMgMTB4IHRoZWly
cywgeW91IGhhdmUgMTB4IHRoZSBkZWdyZWUgb2Ygc3VjY2Vzcy4NCgkgICAg
ZGVncmVlT2ZTdWNjZXNzID0gZGVncmVlT2ZTdWNjZXNzICogKDEuMC8oMS4w
LWNoYW5jZU9mU3VjY2VzcykpOw0KDQoJICAgIGlmKCBkZWdyZWVPZlN1Y2Nl
c3MgPD0gMC4wICkNCgkgICAgew0KCQlTeXN0ZW0uZXJyLnByaW50bG4oIkRl
Z3JlZSBvZiBzdWNjZXNzIDw9IDAgZm9yIHN1Y2Nlc3NmdWwgc2tpbGwgdXNl
Iik7DQoJICAgIH0NCgkgICAgZWxzZSBpZiggZGVncmVlT2ZTdWNjZXNzIDwg
MS4wICkNCgkgICAgew0KCQlyZXR2YWwgPSAxOw0KCSAgICB9DQoJICAgIGVs
c2UgaWYoIGRlZ3JlZU9mU3VjY2VzcyA+IDEyNy4wICkNCgkgICAgew0KCQly
ZXR2YWwgPSAxMjc7DQoJICAgIH0NCgkgICAgZWxzZQ0KCSAgICB7DQoJCXJl
dHZhbCA9IChieXRlKWRlZ3JlZU9mU3VjY2VzczsNCgkgICAgfQ0KCX0NCg0K
CXJldHVybiByZXR2YWw7DQogICAgfQ0KfQ0K
------=_NextPart_000_2015_25cb_4325--
_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev
More information about the mud-dev-archive
mailing list