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   1   (one).   The player's turn finishes with play passing to the next player.


Task

Create a program to score for, and simulate dice throws for, a two-person game.



Related task

   Pig the dice game/Player


include c:\cxpl\codes;          \intrinsic 'code' declarations
integer Player, Die, Points, Score(2);
[Score(0):= 0;  Score(1):= 0;   \starting scores for each player
Player:= 1;                     \second player
repeat  Player:= if Player = 1 then 0 else 1;           \next player
        Points:= 0;                                     \points for current turn
        loop    [Text(0, "Player ");  IntOut(0, Player+1);
                Text(0, " is up. Roll or hold (r/h)? ");
                OpenI(0);       \discard any chars in keyboard buffer (like CR)
                if ChIn(0) = ^h then quit               \default is 'r' to roll
                else    [Die:= Ran(6)+1;                \roll the die
                        Text(0, "You get ");  IntOut(0, Die);  CrLf(0);
                        if Die = 1 then [Points:= 0;  quit];
                        Points:= Points + Die;          \add up points for turn
                        Text(0, "Total points are ");  IntOut(0, Points);
                        Text(0, " for a tentative score of ");
                        IntOut(0, Score(Player)+Points);  CrLf(0);
                        ];
                ];
        Score(Player):= Score(Player) + Points;         \show scores
        Text(0, "Player 1 has ");  IntOut(0, Score(0));
        Text(0, " and player 2 has ");  IntOut(0, Score(1));  CrLf(0);
until   Score(Player) >= 100;
Text(0, "Player ");  IntOut(0, Player+1);  Text(0, " WINS!!!");
]