Talk:Pig the dice game/Player: Difference between revisions

Line 12:
 
I was thinking of implementing a simple always roll n times then hold. I could then do stats on randomly varying n for each player and see if there are any patterns for the winner. But as yet I have no prog at all so its just an idea... --[[User:Paddy3118|Paddy3118]] 03:09, 15 September 2012 (UTC)
 
The winning strategy needs to take into account the complete game state, namely the current player's total score, his current holding score, and the other player's score. The function to calculate the player's best strategy and winning chance given a game state is (psuedo code):
<lang>function P(total, this_round, op):
// args: my total, my rolled so far, and opponent's score; it's my turn
if total + this_round >= 100 then: return 1
 
// I yield; my winning chance is whatever opponent doesn't win his
chance_yield = 1 - P(op, 0, total + this_round)
 
// chance to win after rolling a 1
chance_roll = (1 - P(op, 0, total)) / 6
 
// plus chance to win for rolling 2--6
for roll from 2 to 6 do:
chance_roll += P(total, this_round + roll, op) / 6
 
return max(chance_roll, chance_yield) // choose better prospect</lang>
Note that this is a recursive relation, and the P function can't be evaluated just like that due to infinite recursions. There are ways around it by doing matrix iterations or some such, assuming a single function for probability makes sense -- depending on the game type, it's possible that there's no optimal strategy, in which case either the probability matrix won't converge, or there could be multiple stable solutions, etc. I don't think that happens for this game, but calculating the matrix can still be quite daunting. --[[User:Ledrug|Ledrug]] 06:01, 15 September 2012 (UTC)
Anonymous user