03-14-2017, 10:02 AM | #1 |
Join Date: Oct 2011
|
Python Problems
For reasons which are too convoluted and irrelevant to explain, I decided to make a Python program that calculates the odds of a given attack knocking out someone. I've managed to create a program that works, but which gives me...wonky results. For instance, it suggests that a 1d+0 attack would have just over a 30% chance of knocking out a normal person (10 HP, 10 HT). I assume there's some kind of failed transition from my understanding of the rules and my implementation of the code, but I don't see any remaining errors which could cause that. So I figured I'd find some more people to look over it from another angle and hopefully see what I didn't.
My understanding of the rules:
Spoiler:
A rough outline of how I tried to implement this:
Spoiler:
The code I used, with comments added both from the code editor and the image editor: http://i63.tinypic.com/10fb095.png Does anyone see where I went wrong? |
03-14-2017, 10:23 AM | #2 |
Join Date: Jun 2013
|
Re: Python Problems
A Major Wound means taking more than half your HP in a single blow - a roll of 5 on 1d isn't enough for an HP 10 target, you need a roll of 6.
Seeing as the probability of rolling a 5 or 6 is just over 30%, I'd say your current implementation must have Major Wounds automatically knocking characters out. In addition to changing your Major Wound threshold, you'll need to look at the code for calculating the chance of falling unconscious from a Major Wound to see why it's always returning 100%. I'm afraid I don't really know any code, however, so won't be of much help there. EDIT: Maybe I can help, actually. Looking over the code, you have MWFail=1-Prob(3,6,15). From the previous comments, Prob(3,6,15) is "Probability of rolling 15+ on 3d6." From the rest of the code, it looks like MWFail is meant to return the chance of falling unconscious - but right now you have it as the chance of rolling a 14 or lower, which is the chance of the target not falling unconscious. Change that to MWFail=Prob(3,6,15) and see what you get. Last edited by Varyon; 03-14-2017 at 10:30 AM. |
03-14-2017, 10:26 AM | #3 |
Join Date: Aug 2004
Location: Seattle, WA
|
Re: Python Problems
For me, the point at which you posted the code as a tiny text image ;-)
However, depending on the version of python you are using (2 or 3), the problem could be your division operation at line 12: odds = targetAmount / rollAmount In python2, that will yield an integer, which will almost always be zero in this case. You would fix it by adding an explicit float operation, i.e.: odds = targetAmount * 1.0 / rollAmount That's as far as I got before trying to read the screen image killed me.
__________________
Thomas Weigel Gamer, Coder, Geek |
03-14-2017, 10:31 AM | #4 |
Join Date: Mar 2014
|
Re: Python Problems
Varyon is correct in that the calculated chance of falling unconscious from a major wound is close to 100% in that code. The problem lies in this line
MWFail = 1 - Prob(3,6,15) Since the Prob function calculates the chance of rolling higher than the target number, what it should say is MWFail = Prob(3,6,15) |
03-14-2017, 10:37 AM | #5 |
Hero of Democracy
Join Date: Mar 2012
Location: far from the ocean
|
Re: Python Problems
As a general debugging note, printing out intermediate numbers in this sort of thing sorts out all sorts of problems. I've done a lot of this sort of thing (in javascript, python is hurting my head right now), and testing each step is a lot easier than looking at code to see what you did wrong.
__________________
Be helpful, not pedantic Worlds Beyond Earth -- my blog Check out the PbP forum! If you don't see a game you'd like, ask me about making one! |
03-14-2017, 10:54 AM | #6 | |||
Join Date: Oct 2011
|
Re: Python Problems
Quote:
Quote:
Quote:
Thanks for the help! |
|||
03-14-2017, 11:03 AM | #7 | |
Join Date: Aug 2004
Location: Seattle, WA
|
Re: Python Problems
Quote:
1. Used my font choices (for my poor eyes). 2. Allowed me to work with your code (copy/paste relevant portions to be changed in this forum; run it through a debugger; step through and examine values; etc.). Code:
The CODE tag allows you to retain formatting. Posting code as an image provided the following benefits:
__________________
Thomas Weigel Gamer, Coder, Geek |
|
03-14-2017, 11:09 AM | #8 | |
Join Date: Jul 2008
|
Re: Python Problems
Quote:
It allows the edited-in additional text notes. OTOH, those could have been turned into comments so they'd be in the text.
__________________
I don't know any 3e, so there is no chance that I am talking about 3e rules by accident. |
|
03-14-2017, 11:37 AM | #9 |
Join Date: Jun 2013
|
Re: Python Problems
|
Tags |
damage, python |
Thread Tools | |
Display Modes | |
|
|