Update --- I think I see my problem... in the example at Stack Exchange Question it shows 5C3 5C4 and 5C5... if I have researched this out, this means 5 combinations choose X. If so, what is that calculation? (head is spinning right now... so break time) (that's the part I think I need to put in my code below)
I'm trying to write a function for my Computer Opponents in playing a dice game.
For all computer opponents:
-knows the value of its own dice (can have between 1 and 5 dice in it's hand)
-knows the total amount of die left in the game (between 2 and 4 players in the game, so 4 and 20 die total)
-knows the incoming bid (i.e. previous player bids there are six-4's, or four-2's, etc)
My decision tree for the computer to either raise or bid is based upon: -checking own dice for definite Raise or Call situation (i.e. incoming bid is three-2's, and computer has 4 2's in hand, for sure Computer will do a raise since computer has three-2's OR if incoming bid is six-4's, and total Die remaining is 8, and computer has 3 die in hand.. none of which are 6's, then Call)
-if neither definite Raise or Call, calculate chance that existing bid is valid, and then Random generate a number.. if the Random Number exceeds the chance that is calculated then Raise, else call.
In order to calculate the probability that the remaining die contain the rest of the bid dice, and in looking through samples here (I knew I should have paid more attention in my statistics class) I THINK what I need to do is add up the probabilities like so:
Examples: 10 die remaining, 5 in my (computer) hand. Current bid is four-3's. In my hand is two-3's, so need to calculate the probability that two of the remaining 5 dice are 3's.
or 20 die remaining, 5 in my (computer) hand. Current bid is six-4's. In my hand are two-4's, so need to calculate the probability that four of the remaining 15 dice are 4's.
In all cases.. that leaves me with adding up the probabilities such:
P(N dice (of the remaining dice) match the incoming value) (i.e. five-3's, or 15-4's) + P(N-1 dice match the incoming value) (i.e. four-3's or 14-4's).. and keep subtracting from N until I reach the value of the number of Dice I am trying to find (i.e. 5-3 because I need probability of two-4's, or 15-11 because I need probability of four-4's)
If that logic is correct (and makes sense) what do I need to keep track of each time through a loop?
Right now I set initial conditions (example):
TotalDiceLeftToLookThrough = 11 NumberOfDiceThatBidderNeeds = 3 CurrentDieToCalculateProbability = 11 PowerForNotAppearing = 1; TotalProbability = 0;
TotalProbability = (1/6)^CurrentDieToCalculateProbability ((1/6)^11)
CurrentDieToCalculateProbability -= 1 (now equals 10)
while(CurrentDieToCalculateProbability >= NumberOfDiceThatBidderNeeds) TotalProbability += TotalDiceLeftToLookThrough * (5/6)^PowerForNotAppearing * (1/6)^CurrentDieToCalculateProbability CurrentDieToCalculateProbability -= 1 PowerForNotAppearing += 1 Loop
But I think I am missing something in my loop... anyone able to explain what I need in my Loop would be greatly appreciated!
I am trying to follow along with the question here StackExchange Question but I do not come up with the answer 276/6^5, so not quite sure what I am missing in my understanding... (I get 276/6^5 = .03549, and if I run thru the problem with substitution (5∗(1/6)^3∗(5/6)^2)+(5∗(1/6)^4∗(5/6)^1)+(5∗(1/6)^5) I get .019933 and if I do this:((1/6)^3 * (5/6)^2) + ((1/6)^4 * (5/6)^1) + ((1/6)^5) I get .00398 )
Update - After pulling hair out.. the code works for dice up to three.. but then it breaks bad... So, I'm not there yet. looking for any general solution that would work for N dice such that Probability of X of N being the same die is calculated. (grrr, much prefer Vectors to this! :) )