.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Air Assault Task Force- Save $8.00
Bronze- Save $10.00

   







Go Back   .com.unity Forums > Illwinter Game Design > Dominions 2: The Ascension Wars

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old January 1st, 2004, 08:39 AM
Saber Cherry's Avatar

Saber Cherry Saber Cherry is offline
Major General
 
Join Date: Oct 2003
Location: Crystal Tokyo
Posts: 2,453
Thanks: 0
Thanked 0 Times in 0 Posts
Saber Cherry is on a distinguished road
Default Re: Dominions Dice Roll Chart

In contrast, my inexact code is quite short=)

For a single open or closed die:
code:
	//rolls a closed die, "sides" sides, numbered (low) to (low+sides-1)
private int rollDie(){return rand(sides)+low;}

//rolls an open die
private int rollDieOpen(){
face=total=rollDie();
while(face>=high){total+=(face=rollDie());}
return total;
}

//returns a random number, 0 to max-1
private int rand(int max){return (randy.nextInt()&mask)%max;}

Unfortunately, I do not know how slow the pseudorandomizer is, so I don't know how much avoiding it would help. I was considering pregenerating a lookup table that I could reference with a single random number, instead of multiple random numbers like 2d6*-2d6* simulation requires... but the table would be huge to be accurate. A table covering 99.999% of rolls would need 100,000 bytes, which would hurt Cache performance. Alternately, storing the probability table you provided and looking up the value would require minimum n(log(n)) steps to look up a roll from a probability.

A single formula, in this form:

code:
int convertTo2d6roll(double probability){
return something;
}

...assuming the code was fairly short...

...would speed up things a lot.

Of course, the ultimate distribution would still be entirely dependant on Java's pseudorandomizer

However, from examining what you wrote below, which I do not very much understand (but I think I should if I remembered my stats class)... it looks like it has a lot of expensive double-precision floating point division.

Regardless of speed, I would love to see code that implements it, if you have time! And I'll try to figure out what you wrote below, tomorrow=)

-Cherry

P.S. To post code on these forums: Use ["code"] blah blah ["/code"] format. Without the quotes
__________________
Cherry
Reply With Quote
 

Bookmarks

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
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:19 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.