Pig the dice game/Player: Difference between revisions
m (sp.) |
(first cut at building a strategy) |
||
Line 13: | Line 13: | ||
# '''Holding''': The player's score for that round is added to their total and becomes safe from the effects of throwing a one. The player's turn finishes with play passing to the next player. |
# '''Holding''': The player's score for that round is added to their total and becomes safe from the effects of throwing a one. The player's turn finishes with play passing to the next player. |
||
=={{header|J}}== |
|||
This is a partial implementation of the current task. |
|||
This is a routine to estimate the value of rolling, given the current total of rolls which the player is building (left argument) and the current total of rolls which are a permanent part of the player's score (right argument). |
|||
If the expected value is positive, it's probably in the best interest of the player to take the roll. That said, a more sophisticated strategy might play cautiously when a player is sufficiently ahead of the other player(s). |
|||
<lang J>pigval=:4 :0 |
|||
(+/%#)(-x),}.(1+i.6)<.100-y+x |
|||
)</lang> |
|||
Examples: |
|||
<lang> 10 pigval 90 |
|||
_1.66667</lang> |
|||
If we have 10 points from our current rolls and have 90 permanent points, rolling again is a bad idea. |
|||
<lang> 0 5 10 15 20 pigval"0/60 65 70 75 80 85 90 95 100 |
|||
3.33333 3.33333 3.33333 3.33333 3.33333 3.33333 3.33333 3.16667 0 |
|||
2.5 2.5 2.5 2.5 2.5 2.5 2.33333 _0.833333 _5 |
|||
1.66667 1.66667 1.66667 1.66667 1.66667 1.5 _1.66667 _5.83333 _10 |
|||
0.833333 0.833333 0.833333 0.833333 0.666667 _2.5 _6.66667 _10.8333 _15 |
|||
0 0 0 _0.166667 _3.33333 _7.5 _11.6667 _15.8333 _20</lang> |
|||
If we have 70 permanent points (or less) we should probably re-roll when our uncommitted rolls total to less than 20. |
|||
;Reference |
;Reference |
Revision as of 19:12, 14 September 2012
The task is to create a dice simulator and scorer of Pig the dice game and add to it the ability to play the game to at least one strategy.
- State here the play strategies involved.
- Simulate playing the game a number of times with two players of given strategies and report here summary statistics such as, but not restricted to, the influence of going first or which strategy seems stronger.
- Game Rules
The game of Pig is a multiplayer game played with a single six-sided die. The object of the game is to reach 100 points or more. Play is taken in turns. On each person's turn that person has the option of either
- Rolling the dice: where a roll of two to six is added to their score for that turn and the player's turn continues as the player is given the same choice again; or a roll of 1 loses the player's total points for that turn and their turn finishes with play passing to the next player.
- Holding: The player's score for that round is added to their total and becomes safe from the effects of throwing a one. The player's turn finishes with play passing to the next player.
J
This is a partial implementation of the current task.
This is a routine to estimate the value of rolling, given the current total of rolls which the player is building (left argument) and the current total of rolls which are a permanent part of the player's score (right argument).
If the expected value is positive, it's probably in the best interest of the player to take the roll. That said, a more sophisticated strategy might play cautiously when a player is sufficiently ahead of the other player(s).
<lang J>pigval=:4 :0
(+/%#)(-x),}.(1+i.6)<.100-y+x
)</lang>
Examples:
<lang> 10 pigval 90 _1.66667</lang>
If we have 10 points from our current rolls and have 90 permanent points, rolling again is a bad idea.
<lang> 0 5 10 15 20 pigval"0/60 65 70 75 80 85 90 95 100
3.33333 3.33333 3.33333 3.33333 3.33333 3.33333 3.33333 3.16667 0 2.5 2.5 2.5 2.5 2.5 2.5 2.33333 _0.833333 _5 1.66667 1.66667 1.66667 1.66667 1.66667 1.5 _1.66667 _5.83333 _10
0.833333 0.833333 0.833333 0.833333 0.666667 _2.5 _6.66667 _10.8333 _15
0 0 0 _0.166667 _3.33333 _7.5 _11.6667 _15.8333 _20</lang>
If we have 70 permanent points (or less) we should probably re-roll when our uncommitted rolls total to less than 20.
- Reference