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


constant numPlayers = 2,
         maxScore = 100
sequence scores = repeat(0,numPlayers)
printf(1,"\nPig The Dice Game\n\n")
integer points = 0, -- points accumulated in current turn, 0=swap turn
        player = 1  -- start with first player
while true do
    integer roll = rand(6)
    printf(1,"Player %d, your score is %d, you rolled %d. ",{player,scores[player],roll})
    if roll=1 then
        printf(1," Too bad. :(\n")
        points = 0 -- swap turn
    else            
        points += roll
        if scores[player]+points>=maxScore then exit end if
        printf(1,"Round score %d. Roll or Hold?",{points})
        integer reply = upper(wait_key())
        printf(1,"%c\n",{reply})
        if reply == 'H' then
            scores[player] += points
            points = 0 -- swap turn
        end if
    end if
    if points=0 then
        player = mod(player,numPlayers) + 1
    end if
end while
printf(1,"\nPlayer %d wins with a score of %d!\n",{player,scores[player]+points})