Completely lost

Started by
11 comments, last by Spencer Bowers 12 years, 4 months ago
Okay, let me explain:

I'm a self taught programmer. I don't do it professionally; it's more of a hobby.

So, some of my friends play a pen & paper RPG called MERP. One of the guys who plays with them lives in Canada (the rest live in the United States). This lead to some issues of various aspects being difficult to perform without being very tedious. They found a map tool that allows the remote player to connect and see maps and stuff and they use a VOIP service for communication. The main issue they had was dice rolling. They looked around and couldn't find a dice roller that fit the purposes they needed and asked if I could make them one.

So, I made them a dice roller that uses a client/server architecture and allows the remote player to connect and for them to see each others rolls and do other various tasks specific to the game they play. For all intents and purposes it works just fine.

However, they had commented on the frequency of rolls seeming too weird. They would get what felt like an unusual occurrence of open ended rolls (where if it lands 1-5 or 96-100 you reroll and subtract or add the roll, respectively, to the original roll) and they felt that it seemed to favor certain rolls (in terms of what part of the spectrum it would roll on [consistently high or low]).

Now, this shouldn't of been any fault of my own, I used an array of the .NET pseudo random number generator that were initialized at the roll using a shifted time stamp of the moment they were created (where the time stamp is shifted per instance) and it would then randomly* pick which RNG to use for each individual roll using another RNG instance.

However, they insisted the frequency wasn't right. But, one of them had, what I felt was, a really good idea. The idea was to use a 3D die that is rolled using the mouse (with the force of the 'throw' determined by the speed the mouse was moved. Combine that with 'real' physics and you'd have something very similar to an actual die.

So, I started googling a lot for 3D C# stuff and determined DirectX would be a solid way to go. I downloaded the SDK and read some tutorials and was completely lost. Went right over my head. I googled some more, still made no progress. I posted on the XNA forums asking where to start and they suggested some wrappers for C# (including XNA and SlimDX). I felt XNA was geared too much towards Windows phones and the Xbox so I went to SlimDX.

I downloaded SlimDX, read their getting started page and the 3 tutorials they had and still... completely over my head. None of it makes sense to me. I can write a TCP library for automating the entire protocol for me making a server client program easy to setup and run and I can write the library from scratch in 3-4 hours. I can't, however, for the life of me get even a simple square to show up using DX. This isn't just DX related; I'm terrible at drawing things through code. I can make a moderately pretty UI if all the controls are created for me and I can play around with it in Visual Studio but ask me to draw a custom control or to draw things on a form through code and I'll fail miserably. Just can't seem to wrap my head around it.

So, I essentially need someone to hold my hand through this entire process.

Still interested? Read on:

What I'm trying to accomplish:

1.) Based on user input, create a 3D geometric shape with the number of sides specified in the input.
2.) Drawing numbers on each side
3.) Allowing the user to interact with the shape through mouse clicks in combination with the motion of the mouse.
4.) Allowing the user to 'throw' the shape with a force equal to the speed of the mouse cursor.
5.) Using physics for the shape to 'fall' through the 'air' once thrown and land on an invisible imaginary table that is infinite in length and width.
6.) Using physics for the shape to bounce around until it comes to a state of rest.
7.) Figuring out which number is on the side facing up.
8.) Getting the data needed to mimic the exact same motion and result on each connected client's screen.

Everything else from UI to netcode I can handle just fine. But, the rest of it, makes my brain hurt just imagining what needs to be done.

I'm not asking someone to just go, write all the code and call it a day.

What I am asking is for someone to work with me, step by step, and be there and capable of answering my questions so I can learn to do it myself. They, fortunately, aren't in any hurry for the application (since the one I already wrote is doing it's job well enough) so it's not like this has a deadline.

I work in C# and I am completely unfamiliar with WPF, though I am willing to start learning it as well.

If you haven't stopped reading already and are still interested, I'll be around or you can also e-mail me (jon at imawesome dot org).
Advertisement
Now, this shouldn't of been any fault of my own, I used an array of the .NET pseudo random number generator that were initialized at the roll using a shifted time stamp of the moment they were created (where the time stamp is shifted per instance) and it would then randomly* pick which RNG to use for each individual roll using another RNG instance.
I'm not entirely sure how .NET handles this. Perhaps it has a way to deal with that case but... in general pseudorandom generator theory this is nonsense. A single generator will suffice. That's what pseudo-random generators are for. Additionally, you might want to check the internal algorithm, for this application you really want nothing less than mersenne twister.

However, they insisted the frequency wasn't right. But, one of them had, what I felt was, a really good idea...
First: is that a feeling or is it observable? Just dump like 10k rolls, draw them and compare to a known good generator. Generators can also be tested formally.

I can't, however, for the life of me get even a simple square to show up using DX. This isn't just DX related; I'm terrible at drawing things through code. I can make a moderately pretty UI if all the controls are created for me and I can play around with it in Visual Studio but ask me to draw a custom control or to draw things on a form through code and I'll fail miserably. Just can't seem to wrap my head around it.
Very little people draw stuff by hand, they typically load it from some kind of mesh files.


  1. Based on user input, create a 3D geometric shape with the number of sides specified in the input.
  2. Drawing numbers on each side
  3. Allowing the user to interact with the shape through mouse clicks in combination with the motion of the mouse.
  4. Allowing the user to 'throw' the shape with a force equal to the speed of the mouse cursor.
  5. Using physics for the shape to 'fall' through the 'air' once thrown and land on an invisible imaginary table that is infinite in length and width.
  6. Using physics for the shape to bounce around until it comes to a state of rest.
  7. Figuring out which number is on the side facing up.
  8. Getting the data needed to mimic the exact same motion and result on each connected client's screen.
  • What I am asking is for someone to work with me, step by step, and be there and capable of answering my questions so I can learn to do it myself.[/quote]

This is the most overcomplicated solution I've ever read... and completely throws usability in the bucket. At this point, it will be just easier to use real dice. I strongly suggest you against going in that direction. I actually suggest you to start again from the basics and perhaps consider changing email address.
I'm afraid I cannot offer any more help. I'm currently replying as a thread with 0 replies is a sad thread.

Previously "Krohm"

Why don’t you show the code for how you generate your random numbers?
You may easily be falling into the % trap that is so common, or otherwise skewing your results.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I'm not entirely sure how .NET handles this. Perhaps it has a way to deal with that case but... in general pseudorandom generator theory this is nonsense. A single generator will suffice. That's what pseudo-random generators are for. Additionally, you might want to check the internal algorithm, for this application you really want nothing less than mersenne twister.


My next version already has the Mersenne Twister in it due to their complaint.

First: is that a feeling or is it observable? Just dump like 10k rolls, draw them and compare to a known good generator. Generators can also be tested formally.


Well, as far as statistical data goes, there's a solid distribution (I put in a chart to track the rolls) and it takes varying degrees of rolls to average within the accepted deviation. Statistically speaking, I can't find their complaint. But, that's really not what this thread was about. I was explaining what lead to the idea that brought me here.

Very little people draw stuff by hand, they typically load it from some kind of mesh files.

No one creates 3D polyhedrons at run time via code? Do I just need to use a 3D program to create the models for the dice?

This is the most overcomplicated solution I've ever read... and completely throws usability in the bucket. At this point, it will be just easier to use real dice. I strongly suggest you against going in that direction. I actually suggest you to start again from the basics and perhaps consider changing email address.
I'm afraid I cannot offer any more help. I'm currently replying as a thread with 0 replies is a sad thread.

I think you've misunderstood my post. This isn't suppose to be a 'solution' to their complaint. It was just a neat idea that I wanted to do and I have no idea how to do it; the resources I've found over over my head and thus I'm asking for help.

Usability, I would think, would be fine. The premise behind it is the same as kinetic scrolling (using the speed of motion to correlate to a force to be applied to an object). Unless I'm misunderstanding what you mean.

As for the thread having zero replies at the time of your post... that's outside of my hands, isn't it?


Why don’t you show the code for how you generate your random numbers?
You may easily be falling into the % trap that is so common, or otherwise skewing your results.


L. Spiro


I suppose I wasn't articulate enough in my post. I don't actually believe there's a problem with the pseudo random number generator. In fact, they're comparing their experience to using actual dice (D100 to be precise) where they would intentionally try to skew the results by attempting to roll along specific edges of the die to gain high or low rolls (whichever was more beneficial). That doesn't make their complaint any less valid but statistically, the data is adequately spread and the open / negative open ended rolls occur at almost exactly the expected frequency (5% per side).

My reason for coming here was looking for help in creating the idea they came up with because, as I stated, I thought it was a really neat idea.

However, here is a truncated version of the method used to create the random numbers using the .NET pseudo random number generator.

//* create our random number generators
Random[] generators = new Random[dice];

//* establish their seeds
for (int a = 0; a < dice; a++)
generators[a] = new Random(unchecked((int)(DateTime.Now.Ticks >> a)));

...

//* on with the roll
for (int b = 0; b < dice; b++)
{
this.rolls.Add(generators[new Random().Next(0, dice)].Next(1, sides + 1));

//* see if they want to reroll open / negative open ended rolls
if (reroll)
{
//* see if the roll was open or negative open ended
if (this.rolls[this.rolls.Count - 1] >= openEnd)
{
//* roll was open ended, so reroll it
int roll = generators[new Random().Next(0, dice)].Next(1, sides + 1);
//* store it
this.modifications.Add(roll);
this.modified.Add(this.rolls.Count - 1);

//* repeat until we have no more open ended rolls
while (roll >= openEnd)
{
//* roll
roll = generators[new Random().Next(0, dice)].Next(1, sides + 1);
//* store it
this.modifications.Add(roll);
this.modified.Add(this.rolls.Count - 1);
}
}
else if (this.rolls[this.rolls.Count - 1] <= nOpenEnd)
{
//* roll was negative open ended, reroll it
int roll = generators[new Random().Next(0, dice)].Next(1, sides + 1);
//* store it as negative
this.modifications.Add(-roll);
this.modified.Add(this.rolls.Count - 1);

//* repeat until we have no more open ended rolls
while (roll >= openEnd)
{
//* roll
roll = generators[new Random().Next(0, dice)].Next(1, sides + 1);
//* store it
this.modifications.Add(-roll);
this.modified.Add(this.rolls.Count - 1);
}
}
}

//* apply modifier
this.bonuses.Add(bonus);
this.penalties.Add(penalty);
}
just a suggestion, but when you establish the random generators seed using the current time in ticks, are you doing this in the same loop or function that you are "rolling" the dice?

If you are, you should change it so that the seed is gotten when you first start the program, otherwise if the seed is gotten right before you roll the dice every time, the the random number very well could be "biased" since the time it takes to get the seed then get the random number is only based on the speed of the computer, which is going to be very similar for each roll.

by the way, to check if the rolls are actually biased, you could easily create a loop that rolls the dice a ton of times, keeping track of the number of times it lands on each side of the dice. if one or a couple sides are landed on a much more than the other sides, you'll know the rolls are biased

just a suggestion, but when you establish the random generators seed using the current time in ticks, are you doing this in the same loop or function that you are "rolling" the dice?

If you are, you should change it so that the seed is gotten when you first start the program, otherwise if the seed is gotten right before you roll the dice every time, the the random number very well could be "biased" since the time it takes to get the seed then get the random number is only based on the speed of the computer, which is going to be very similar for each roll.

by the way, to check if the rolls are actually biased, you could easily create a loop that rolls the dice a ton of times, keeping track of the number of times it lands on each side of the dice. if one or a couple sides are landed on a much more than the other sides, you'll know the rolls are biased


They are created at the time of the roll... however, the proper .Next is called, the seeds are each shifted and as I've stated, the statistical data shows no real bias, at least not as far as I can tell.

Once again, though, the entire point of this thread is not whether or not the current implementation of the roller is biased or improperly generating numbers.

The point of this thread is to find someone to help me with the project I've outlined in my initial post.

However, they insisted the frequency wasn't right. But, one of them had, what I felt was, a really good idea.


I just thought the point of the really good idea was to fix the bias of the rolls. It might be somewhat difficult to find someone to walk you through an entire project, but don't worry, it sounds like your project is not a very difficult one. If you don't want to learn direct3d (since direct3d can take a bit to get used to) you could look into opengl. there are a ton of tutorials and stuff to get started with both api's, and you'd probably only need to read like 4 (since most of the time tutorials will go in order from like initializing the api, drawing, transformations, and texturing, and thats all you'll probably need from opengl or directx)

So I would recommend looking into opengl, since that's a little quicker to learn. If you have any specific questions, I'll be happy to help ;)
As a side note, I don’t know if something went wrong in your post or if you really have a habit of not indenting properly.
Just in case it is the latter, knock it off. Never fail to indent when you open a new if/while/for/etc.
It is absolutely unacceptable in the entire world of programming to enter an if/while/for/etc. without indenting an extra level.




L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

No one creates 3D polyhedrons at run time via code? Do I just need to use a 3D program to create the models for the dice?
Some programs have code to generate them. It's really not much of a big deal. In some cases, they have the data encoded as constants. I have icosahedron hardcoded in a array and cube in a code snippet.

So I would recommend looking into opengl, since that's a little quicker to learn...
With C#? I'm not sold on that. I have used OpenGL for a while... to be completely honest, I suggest against using OpenGL in the first place. I still cannot understand how you people can say OpenGL is easier to learn. My main problems in understanding Direct3D9 were indeed caused by OpenGL over-reliance. Direct3D10 is totally awesome. Don't get me started on the documentation.

Previously "Krohm"


With C#? I'm not sold on that. I have used OpenGL for a while... to be completely honest, I suggest against using OpenGL in the first place. I still cannot understand how you people can say OpenGL is easier to learn. My main problems in understanding Direct3D9 were indeed caused by OpenGL over-reliance. Direct3D10 is totally awesome. Don't get me started on the documentation.


Alright, so my knowledge of opengl is a little dated, I had learned opengl before directx. At the time anyway, it was MUCH faster to get set up and start doing stuff. I love directx, I was only suggesting opengl since from my experience it was easier to learn and set up. I guess i missed the part about him using C# (not that it would have really changed my answer i guess).

I'll agree with the documentation, directx is well documented now (although a while ago directx had terrible documentation)

I suppose since he's in the directx forum, he's going to go for directx, but in the end, I think his project is simple enough so it really doesn't matter which api he uses (I only suggested opengl because when i used it, it was much faster to set up (less code), easier to understand (probably only because there was no solid tutorials or documentation on directx at the time), and seemed to do everything for you). Opengl is also portable ;) but don't get me wrong, i'm not trying to move people away from directx, just trying to be helpful. I've been using directx for years and love it

This topic is closed to new replies.

Advertisement