Steve Jackson Games - Site Navigation
Home General Info Follow Us Search Illuminator Store Forums What's New Other Games Ogre GURPS Munchkin Our Games: Home

Go Back   Steve Jackson Games Forums > Roleplaying > GURPS

Reply
 
Thread Tools Display Modes
Old 03-14-2017, 10:02 AM   #1
GreatWyrmGold
 
Join Date: Oct 2011
Default 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?
GreatWyrmGold is offline   Reply With Quote
Old 03-14-2017, 10:23 AM   #2
Varyon
 
Join Date: Jun 2013
Default 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.
Varyon is offline   Reply With Quote
Old 03-14-2017, 10:26 AM   #3
seasong
 
seasong's Avatar
 
Join Date: Aug 2004
Location: Seattle, WA
Default 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
seasong is offline   Reply With Quote
Old 03-14-2017, 10:31 AM   #4
Andreas
 
Join Date: Mar 2014
Default 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)
Andreas is offline   Reply With Quote
Old 03-14-2017, 10:37 AM   #5
ericthered
Hero of Democracy
 
ericthered's Avatar
 
Join Date: Mar 2012
Location: far from the ocean
Default 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!
ericthered is offline   Reply With Quote
Old 03-14-2017, 10:54 AM   #6
GreatWyrmGold
 
Join Date: Oct 2011
Default Re: Python Problems

Quote:
Originally Posted by Varyon View Post
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.
...Yup, that'd do it. 3% sounds much more reasonable!

Quote:
Originally Posted by seasong View Post
For me, the point at which you posted the code as a tiny text image ;-)
It's not supposed to be tiny...I thought it was almost the size of my entire monitor...

Quote:
Originally Posted by ericthered View Post
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.
There are a fair few bugs I sorted out of this code that way. Not sure how it would have helped here, though.

Thanks for the help!
GreatWyrmGold is offline   Reply With Quote
Old 03-14-2017, 11:03 AM   #7
seasong
 
seasong's Avatar
 
Join Date: Aug 2004
Location: Seattle, WA
Default Re: Python Problems

Quote:
Originally Posted by GreatWyrmGold View Post
It's not supposed to be tiny...I thought it was almost the size of my entire monitor...
Just posting it as plain text would have:

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.
3. Avoided exposing me to the regrettable advertisements on the image hosting site you decided to use.

Posting code as an image provided the following benefits:
__________________
Thomas Weigel
Gamer, Coder, Geek
seasong is offline   Reply With Quote
Old 03-14-2017, 11:09 AM   #8
Ulzgoroth
 
Join Date: Jul 2008
Default Re: Python Problems

Quote:
Originally Posted by GreatWyrmGold View Post
There are a fair few bugs I sorted out of this code that way. Not sure how it would have helped here, though.
You could straight-up print the results of every line of calculation as you do it. Then you'd notice that MWFail was suspiciously close to 1, hopefully.
Quote:
Originally Posted by seasong View Post
Posting code as an image provided the following benefits:
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.
Ulzgoroth is offline   Reply With Quote
Old 03-14-2017, 11:37 AM   #9
Varyon
 
Join Date: Jun 2013
Default Re: Python Problems

Quote:
Originally Posted by GreatWyrmGold View Post
It's not supposed to be tiny...I thought it was almost the size of my entire monitor...
The image started out tiny for me, but simply clicking on it got it to full screen. Of course, now that site only loads ads and not the picture for me.
Varyon is offline   Reply With Quote
Reply

Tags
damage, python

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Fnords are Off
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:27 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2024, vBulletin Solutions, Inc.