I'm trying to recreate a single player version of a dice game called Dudo. The most relevant information is that six players have six hidden dice, and the point of the game is to guess how many of a certain kind of die are on the table in total (e.g. If there are ten 4s, or twelve 5s etc).
To make some AI, I'm using binomial distributions where the computer guesses the probability of there being a certain number of a certain kind of die, based on how many of that kind of die it already has in its hand. I saved this equation in the variable chance:
chance = ((1/3) ** (i - player_dice_type[turn][active_type])) * ((2/3) ** (total_count - i - player_count[turn] + player_dice_type[turn][active_type]))
i
is the number of that kind of die (e.g. six 5s, or seven 5s, or eight 5s etc.). I have a list of how many of each kind of die a player has (player_dice_type
) and I can select a specific die for a specific player by subsetting turn
and active_type
. The 1/3 has to do with the rules of the game (normally it'd be 1/6 for dice), but that doesn't have to do with my issue anyway.
When I call chance, it ONLY gives me the value for if player_dice_type[turn][active_type] = 0
, and i = 6
, so the probability that 6 of that die are on the table when the computer has 0 of it.
I can call i
and player_dice_type[turn][active_type]
and see that they do NOT equal 6 or 0. The thing is though, if I copy and paste the equation, it works perfectly fine. It only defaults to 6 and 0 when I call chance.
I've also tried making a chancefun(i)
function that returns the original equation, and then said chance = chancefun(i)
. I can change i in the environment to whatever I want and chancefun(i)
will react accordingly, but once again, the variable chance
does not.
I've included scoping as a tag just because I think it might somehow be related but I can't think of how. I've also tried change the variable name from chance
to a bunch of other things and still no luck.
If you defined chance
as a variable, its value was fixed when you created it. It will not "update" if you later change the value of i
or anything else. You cannot "call" chance as you've defined it; it's just a static value, not a function.
If you do something like chance = chancefun(i)
, that sets the value of chance, once, and that's it. Is does not "link" the variable chance
to chancefunc
somehow.
If you want to get different values of chance for different parameters, make it a function and call it with the arguments you want. Something like:
def chance(i, turn, active_type):
return ((1/3) ** (i - player_dice_type[turn][active_type])) * ((2/3) ** (total_count - i - player_count[turn] + player_dice_type[turn][active_type]))
I'm assuming here that player_dice_type
and total_count
are globally defined variables. You will need to decide what values you want chance
to look up globally and which ones you want to pass on each call.