wh40kdr
wh40kdr
DevLog WH40k Dice Roller
4 posts
Don't wanna be here? Send us removal request.
wh40kdr · 1 year ago
Text
[Pinned] Github
https://github.com/SamFuller02/WH40kDR
0 notes
wh40kdr · 1 year ago
Text
Devlog 2 - Hit Rolls (and how they work in Warhammer) (15:55 DST 16/06/2024)
For today I've added an hit roll function, and tested it's functionality.
In 40k attacks work as follows. You pick a weapon profile and that weapon profile has a number of attacks, A, and a ballistics/weapon skill, [B/W]S. To make an attack you roll Ad6, and every result which is greater than or equal to S is a successful hit. Moreover every result of a 6 (or lower depending on a unit's abilities) is considered a critical hit and may have additional effects (such as lethal hits, or sustained hits).
Implementing an effective attack roll function is actually very easy with a pre-existing dice roll function (see Devlog 1 or Github). The first step is to create an empty list in which the dice rolls are stored. Lists are some of the most useful objects in python because they are indexed, and you can both change the values of an index, and iterate over each index respectively. Using the in-built .append() function of python and a for loop, I could use my roll() function a number of times equal to the number of attacks, and append each roll onto the list.
I can then use an if/elif loop to iterate over the lists and count the successful hits (and crits) by comparing them to the skill. The important thing is to count crits before hits as in python, once one path of a loop is successfully executed, it will return to the start of the loop for the next iteration, instead of following the subsequent path. In more plain language if it's analysing the results for hits before it analyses for crits, since every crit is itself a hit, the computer goes "that's a hit, now lets look at the next result" without ever going "that's a crit". By first analysing for crits the computer will first identify if a result is a crit, and if it isn't it will then test to see if the result is a hit.
Finally, a feature I've included as a surprise tool that will help later is the ability to lower the critical hit threshold, since certain units have the ability to crit on lower results.
The next step is going to be creating a wound roll function (which is more complicated because wound roll targets very in Warhammer), and then a combined attack roll function that takes the hit roll results and uses them to make the wound roll. Probably going to *roll* these into one Devlog so expect a few days at least before the next input. Signing-off for now with another link to my Github.
https://github.com/SamFuller02/WH40kDR
1 note · View note
wh40kdr · 1 year ago
Text
Devlog 1 - Basic Dice Function (and relevant statistics) (14:17 DST 14/06/2024)
To kickstart my journey let's talk about my dice-rolling function and some very basic and important statistics about fair dice and dice rolls. The core function of any dice-rolling app for any game is the ability to roll fair dice. A six-sided dice (d6 in TTRPG lingo) should give each possible result (i.e. any number from 1-6) 1/6th of the time it is rolled. In principle if you roll the dice six times you should get six different results: 1, 2, 3, 4, 5, and 6. Then if you roll the dice a seventh time you should get a repeat result. Now in practice this won't happen for a small quantity of dice rolls, because the result of a fair dice is random, and so instead the fairness is measure over many, many dice rolls, until eventually it can be said that the dice is fair. Let's consider the actual dice function and how it works. Creating a dice roller is actually rather simple. I made mine by defining a callable function called roll(), with a number of sides that could be inputted (and has a default value of 6 since the purpose of this roller will be for Warhammer). The function then uses a random number generator to generate a number, n, where 0 <= n < 1 (a number between zero and one which could be zero but can't be one). The random number is multiplied by the number of sides which gives a floating point number.
Now for some python syntax. Python contains an in-built function called int(), which converts floating point numbers into integer numbers. It does this through truncation i.e. 0.2 -> 0, 1.4 -> 1, 2.9 -> 2. So our integer result takes a value between 0 and the number of sides minus 1 (for a six-sided dice right now we get 0, 1, 2, 3, 4, or 5). To get valid results for any sided dice we then just add 1 to the random result.
Tumblr media
Figure 1. The above shows a histogram of the results of 50 dice rolls before the +1 shift. (Disclaimer: The numbers on the x-axis for all graphs are a mess. Ignore them, each column represents an integer value.)
Tumblr media
Figure 2. The above shows another histogram of the results of 50 dice rolls this time with the +1 shift. The results are now valid for a d6.
So we have a dice roll function and now we come back to the earlier part of this Devlog, is it fair? Testing this is relatively easy. For a fair dice, if we plot a histogram of a large number of dice rolls (say 5 million), then the resulting graph should show a uniform distribution.
Tumblr media
Figure 3. The distribution of results from 5 million dice rolls.
Since this distribution is uniform (there will be fluctuations in each column but they're statistically insignificant when each column contains 800,000+) the dice is fair. But before I sign off this Devlog, lets show one more cool thing about dice. Rolling two dice of the same type (say 2d6) and summing the results gives a normal distribution.
Tumblr media
Figure 4. The distribution of 50 million 2d6 rolls.
For anyone wondering why this is cool, this is a little nerdy homage of mine and part of the reason I originally created a dice roller. One of my favourite Dungeons and Dragons youtubers is Matt Colville, who runs a very interesting youtube series called running the game, which teaches people how to Dungeon master. He's also started a board game company spinning off from the channels success who are creating their own TTRPG (which I'm very excited to play). They did a very interesting video about dice a few months ago in which Matt claimed that the result of 2d6 was normally distributed, and me being a nerd I decided I would experimentally test that claim myself rather than taking it on a face value. The result is the original dice roll function and most of the subject of this Devlog. So thank you Matt and the entire team at MCDM.
As a final sign-off from me, I will be uploading the master python file to my GitHub: https://github.com/SamFuller02/WH40kDR. At the moment I'm still figuring out GitHub so for now it may appear a little sloppy but it might improve with time.
Link to the video that inspired me: https://www.youtube.com/watch?v=lvs2OYsJmaY
1 note · View note
wh40kdr · 1 year ago
Text
Beginnings (13/06/2024)
Okay story-time. Last summer, sometime in late July, I (Sam) started playing Warhammer 40k, as part of a large group of people who all started playing at my pub. My faction of choice was Orks, because frankly, they are simple to play, fun to run, have awesome minis, and (if you're as dreadful at painting as I am) easy to paint for beginners, because small mistakes fit the aesthetic.
Now many people who play 40k derive a lot of fun out of the process of rolling dice (myself included), but when you run lots of models with a variety of weapons, rolling all the dice, and counting the results can be very tedious and very time consuming, especially for high volume attacks that aren't very effective or consequential.
Luckily for me, in my spare time (Note: read as what I actually do) I moonlight as an undergraduate Physics student in the UK, and as part of my course I learn coding, probably with the intention of eventually having a career that relies on my coding skills. So I thought, rather than using one of the many fully-functional, and probably much better made Dice Rolling apps available on the Google Play Store, I would instead test my coding skills this summer (and probably into the foreseeable year to be honest), along the way possibly teaching some basic coding and statistics, and showing how the development of anything is a series of f*ck ups that eventually lead to the right result as I move from Python 3, to whatever software seems most suitable for basic app development.
I also might occasionally post some pictures of Warhammer things I've painted (badly) but who knows. For know this is Sam signing-off.
7 notes · View notes