It's been a while! I was away for quite a bit learning Unreal Engine 5 and applying this knowledge to that. I also got my old math professor from college to explain the mathematics to me a bit more, so I have a more solid understanding of the terms, like factorial and combination and such. Thanks for helping me despite my lack of understanding, haha.
Now I do have a few fresh questions for you guys! If I show some gaps in my understanding, please let me know.
K = (number of dice in the claim) - (number of dice in the player's hand that match the pip or is wild (one))
N = (number of dice that the other player has)
Probability = 0
compare: K=0
-- set probability to 1
else
compare: K<=N
Repeat K times
-- add factorial(N)/(factorial(loopindex+1)*factorial(N-loopindex-1))*((1/3)^(loopindex+1))*((2/3)^(N-loopindex-1)) to probability
function factorial(num)
-- return (num=0 | num=1)?1:factorial(num-1)
Here's the same thing in formula form in case I made typos.
Anyways, hopefully some of that helps.
I am actually grasping this without much trouble now! What I notice with the code that my professor helped me with and this is that yours uses "1/3" and "2/3" in the exact calculation. This is because the original premise uses wilds, right? Since a 1 or the wagered pip could both count, there is a 2/6 chance to roll what you are trying to roll, which gets simplified to 1/3. Same thing for the 2/3, which is the 4/6 chance you won't roll what you want simplified.
So here's my first question. If I want to have the rules change to either be "Ones are Wild" or not, then I need to use a boolean to first check if "Ones are Wild" or not. If ones are NOT wild, then I would still need to use the 1/6 and 5/6 from the math that my professor taught me. Like this...
If "Ones are Wild", then I'd need to use the 1/3 and 2/3... but... does that still hold up if the player wagers One pips? There's only one way to roll a One, so I would need to do a second check to see if the player wagered faces equal to or above 2, right? If so, they use the "Wild Exact" formula, but if they wagered Ones, then they'd need to still use the "Not Wild Exact" formula... I think.
Secondly, I've been trying to figure out how to implement a "Dead On" rule. With this, a participant may, rather than calling the other player a liar for overestimating the number of dice on the table, may call "Dead on", essentially "There number of dice wagered exactly matches what is on the table.".
At present, I am rolling a float between 0 and 1 and comparing it to the "At Least" calculation. If we roll under the calculated result, then the AI believes the player is telling the truth. I actually set up a quick loop that simulates it 10,000 times with a single click, and the AI wins a lot when it plays perfectly like this, almost 80 percent of the time.
However, when I tried to implement "Dead On" rules, the AI was either calling Dead On hundreds of times or calling it no more than 10 or so times in 10,000 rounds, and they all were wrong...
I wish I had saved my code, but I quit out of frustration and forgot to save. I believe my idea was to subtract one of the results (Exact chance and At Least chance) from the other to give myself ranges that the AI could randomly roll the dice for. So if, for example, Exact was 0.1 and At Least was 0.3, then if the AI random roll was less than 0.1, the AI called Dead On. If the AI roll was between 0.1 and 0.3, it would consider you to tell the truth, and if it rolled above 0.3, then you were lying.
I haven't gotten to having the AI choose a new wager yet, but I want to solve this small conundrum first.