Talk:Pig the dice game/Player

From Rosetta Code

Very draft task

Unlike most of the tasks I start, I have started this one without having a Python solution to hand and so I am unsure of how large a task this is, and may have left important things out of the task description that may lead to non-compatible future edits .

Thanks Tim T. for the many corrections to the hopeless grammar I initially had in Pig the dice game; I hope my English has improved. --Paddy3118 05:57, 14 September 2012 (UTC)

Strategy

I've put together an estimator for use in deciding whether to reroll or not. Here's pseudo-code for people that cannot read J:

consider each roll, for non-1 rolls, each roll's base value is the minimum of itself and 100-(sum of dice currently rolled). For a roll of 1, the value is -(uncommitted rolls). Average these to get the estimated value of the current possibilities. [Or, of course, if you just want to know if the result is positive, you do not need to divide by 6.] --Rdm 19:17, 14 September 2012 (UTC)
That said, using philosophy behind "you don't have to be faster than the bear", a strategy which takes into account your opponent's score could be superior -- sometimes playing more conservatively because we know that our opponent doesn't have a good chance of winning. That said, I have not completely convinced myself that this would ever be a good idea -- intuitively, it seems like it could be, but I have not had the time to think it through, yet. --Rdm 19:22, 14 September 2012 (UTC)

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... --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. --Ledrug 06:01, 15 September 2012 (UTC)