DND dice roller

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

DND dice roller

Postby Moe_Lester » Tue Feb 15, 2005 4:55 pm

what would good structure for a dice-roller be..
the dice-roller would be for DND...so could someone help me i am attempting to make one for my sessions..
Senatus Populusque Romanus (SPQR)
"The Senate and the People of Rome" - i.e. "The Aristocrats and the Commoners", the official name of the Roman Republic. "SPQR" was carried on battle standards by the Roman Legions.
User avatar
Moe_Lester
 
Posts: 20
Joined: Mon Jan 31, 2005 6:06 pm
Location: quarter dimensional space

Postby Bugdude » Tue Feb 15, 2005 5:06 pm

What would good question for a forum be?
User avatar
Bugdude
Moderator
 
Posts: 2480
Joined: Sun Aug 29, 2004 1:58 am
Location: Living in sin

Postby Corsix » Tue Feb 15, 2005 5:07 pm

I made a dice roller in VB a long time ago...
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Tue Feb 15, 2005 5:14 pm

(rand() % 6)


BAM done -.-

*edit*
ahhh dvorak is killing me, fixed typo :D
*edit2*
added edit
Last edited by schloob on Tue Feb 15, 2005 5:15 pm, edited 1 time in total.
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Corsix » Tue Feb 15, 2005 5:15 pm

But what about D3s and D8s?
actually it would be
Code: Select all
(rand() % 6)+1
(1->6, not 0->5)
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Tue Feb 15, 2005 5:17 pm

Corsix wrote:But what about D3s and D8s?
actually it would be
Code: Select all
(rand() % 6)+1
(1->6, not 0->5)

(rand() % d)

happy??
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby schloob » Tue Feb 15, 2005 5:17 pm

all the latest dice are 0-5
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Wizard » Tue Feb 15, 2005 5:42 pm

Code: Select all
((rand() / RAND_MAX) * d) + 1;

is better, I think. More even distribution.
Code: Select all
public class Dice {
    public:
        Dice(int sides) {
            i_sides = sides;
        }
        Dice() {
            i_sides = 6;
        }
        int roll() {
            return ((rand() / RAND_MAX) * i_sides) + 1;
        }
    private:
        int i_sides;
};

There, nice little package.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Darobat » Tue Feb 15, 2005 5:44 pm

Wizard wrote:public class Dice {

I think that should just be
Code: Select all
class Dice {
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby Wizard » Tue Feb 15, 2005 5:47 pm

Dag Nabbit, Java syntax slipping in again. This didn't used to happen. I don't think I'm capable of programming in two different languages like this anymore :P
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Alvaro » Tue Feb 15, 2005 8:51 pm

Wizard wrote:
Code: Select all
((rand() / RAND_MAX) * d) + 1;

Are you sure that RAND_MAX is not an integer? Your dice may be getting just ones on some compilers...
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Wizard » Tue Feb 15, 2005 11:35 pm

I knew that. I just didn't... um... want to give away everything, is all. Yeah.
Look, a decoy.
:biggun:
;)
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Invictus » Wed Feb 16, 2005 1:06 am

Code: Select all
srand(time(0));
...
int Random(int min, int max)
{
   return rand()%(max+1-min)+min;
}



[edit1] Removes static call because I wasn't sure if it would do what I expected.
[edit2] Added edit1 because alvaro posted while I was editing.
Last edited by Invictus on Wed Feb 16, 2005 1:15 am, edited 2 times in total.
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Alvaro » Wed Feb 16, 2005 1:11 am

Invictus wrote:
Code: Select all
int Random(int min, int max)
{
   static srand(time(0));
   return rand()%(max+1-min)+min;
}

Good idea, but I think the syntax should be
Code: Select all
   static int dummy=srand(time(0));

...or something like that, right?
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Invictus » Wed Feb 16, 2005 1:17 am

You have to use a dummy? I'll test it later if no one answers it by the time I get my laptop back. I just told my brother that I would let him use it to write a report while I try to fix his comp.
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Next

Return to Games and Graphics

Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests