I Wrote My First Program in a Fat Minute and it Felt Amazing

Hello all. For those who are unaware, I am an extreme programming fanatic. I love the prospect of computer programming, and plan to get into a programming/computer science related field. Today (since it is President's Day in the United States) I decided it would be fun to sit down and write a program.

It wasn't fun. It sucked. I hated every minute of it. Everything felt so foreign since the last time I did any programming was last September for a competition that I performed horribly at. I have been so busy with school lately that I haven't been able to convince myself that I have the time to get something done. I have started numerous projects and end up just abandoning them.

Let me explain what I ended up doing. Recently, I have found a new found love for dice games, or more, board games that involve rolling dice to get to a goal (like Monopoly). I just like the statistics about it, and that (usually) you can play the game by only buying property or performing actions that affect the peak of the bell curve. So I decided that for fun I would create a dice roll calculator. Not necessarily a "find all the numbers you can roll with x dice" but rather "find all the numbers you can roll with x dice, find out how many of the dice combinations are duplicates, and then use that to find the percentage chance for rolling that particular number." To further explain, I have provided more information in the spoiler.
If you have ever played a game where you are rolling more than one die, you may have noticed that, more often than not, you will end up rolling in the middle of the two extreme rolls. This is because of all the possible combinations. If we look at the following:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
You will notice that there are 9 possible combinations, but there are not 9 numbers you can roll. You can only roll 6 different numbers, with one in the middle being the most common because of the way the dice rolls will add up.

This concept is what drove me to make this program. Basically, the user will provide it with two numbers: the number of dice being rolled and the number of sides each dice will have. The program will then take those numbers and figure out the statistics of rolling those dice.
Now let me, once again, express how I felt about this. "It wasn't fun. It sucked. I hated every minute of it." This may be discouraging for anybody approaching programming. Please don't let it be. Let me explain why it was so difficult.

The task that I chose may sound simple, but it wasn't for one reason: choosing the amount of dice. Every time you add a die, the amount of combinations goes up exponentially. On top of that, there are more loops that need to happen. The problem isn't really with the former, but with the latter. For some reason, it was so difficult for me to determine how to make different loops for each dice block. Let me explain how I approached it.

I treated all combinations as a two dimensional array, with the number of dice blocks being the number of columns and the number of sides on each die raised to the power of the number of dice blocks as the number of rows (by the way, if you didn't know this is how you calculate the total number of combinations). So basically, each row was a different combination and each column contained a different number for the combination. To fill this array (or vector) I filled it by column, not by row. I filled the first column using a loop, and then changed that loop by putting it in a recursive function. Oh man, this took me an eternity (or rather 30 minutes, which felt like a long time for this project) to figure out. Originally I had very complicated things that didn't matter. I had template functions with lambda argument unpackers at the rock bottom of this projects existence. The rest of it was fairly straight forward.

Now I will explain how I managed to figure this out. First of all, I was stumped, even after figuring out I needed a recursive function, for about 15 minutes. I then decided that I needed to just write out an example of how I would fill the first column, and then the second column, and the third column if I was using 3 10-sided dice. This helped immensely.

The true reason this project was so hard for me was because I didn't plan ahead. The most important part of programming is understanding A) what you are doing, and B) how you are going to do it. By deciding "hey I want to make a dice roll statistics application" and jumping in, I was not telling myself what kind of stuff I would be getting into. I really regret the first hour of template functions and lambda unpackers. Always, always, always write some form of psuedocode or some kind of flow map or something that gets your ideas down so you aren't lost.

TL;DR did a decently easy assignment but took forever because I am rusty and didn't do any planning.

Anyways, for those that want to see what I did, go ahead and look here: https://github.com/blu-dev/DiceRollStatistics
Also, I did want to try out the new Visual Studio 2019 preview, so idk if that has anything to do with anybody's ability to load the project in visual studio.

Cheers!

EDIT: I forgot to mention that the complete satisfaction I got from completing this project is worth any pain experienced during the process. Do not give up! If you have to take a break, do it, but never let your projects die!
  • Like
Reactions: 3 people

Comments

G
OK, I just want to say that I've been looking for something like this for literally ages, and I am so glad that somebody just happens to hand it to me. Thank you so much!
 
  • Like
Reactions: 1 person

Blog entry information

Author
Guest
Views
60
Comments
6
Last update

More entries in Personal Blogs

General chit-chat
Help Users
  • Skelletonike @ Skelletonike:
    It's great <3
  • AncientBoi @ AncientBoi:
    LoL. No. good bye
  • Skelletonike @ Skelletonike:
    Fried tripas and fries <3
  • K3N1 @ K3N1:
    My power just randomly went out and it's not even raining out lol
  • H @ hecker_isaac:
    morning peeps
  • coolax @ coolax:
    hey guys anyone can help me for LOZ : TOTK ? im trying to install theses 60fps file but I don't understand where i'm suppose to paste them. ? anyone kno ?
  • K3N1 @ K3N1:
    Your mom's spaghetti
  • Psionic Roshambo @ Psionic Roshambo:
    Her armpits sweaty already
  • K3N1 @ K3N1:
    On the surface
  • Psionic Roshambo @ Psionic Roshambo:
    Flies crawling and pizza stained already
  • K3N1 @ K3N1:
    My noodle has vomit on it already
  • Psionic Roshambo @ Psionic Roshambo:
    Monica's dress stained already
  • SylverReZ @ SylverReZ:
    @Psionic Roshambo, Bill Clinton no!
    +1
  • SylverReZ @ SylverReZ:
    Lmao
    +1
  • Sonic Angel Knight @ Sonic Angel Knight:
    Mama Mia spaghetti :P
    +1
  • DJPlace @ DJPlace:
    don't forget the meatballs
    +1
  • Sonic Angel Knight @ Sonic Angel Knight:
    Mama mia wouldn't forget meatballs in her spaghetti. :P
  • Sonic Angel Knight @ Sonic Angel Knight:
    Speaking of meatballs, what's the deal with meatball sandwich? How can people eat those? It's ROUND. Trying to bite those in a sandwich is a challenge. It's easier to eat a burger stacked with toppings. :ninja:
  • idcwhat3v3r @ idcwhat3v3r:
    here's my cup of care
  • idcwhat3v3r @ idcwhat3v3r:
    oh look, IT'S FUCKING EMPTY.
  • K3N1 @ K3N1:
    Seems familiar
  • Psionic Roshambo @ Psionic Roshambo:
    Spaghetti noodles are straight until you get them hot and wet too lol
    Psionic Roshambo @ Psionic Roshambo: Spaghetti noodles are straight until you get them hot and wet too lol