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


import "/ioutil" for Input
import "/str" for Str
import "random" for Random
 
var name1 = Input.text("Player 1 - Enter your name : ").trim()
name1 = (name1 == "") ? "PLAYER1" : Str.upper(name1)
var name2 = Input.text("Player 2 - Enter your name : ").trim()
name2 = (name2 == "") ? "PLAYER2" : Str.upper(name2)
var names = [name1, name2]
var r = Random.new()
var totals = [0, 0]
var player = 0
while (true) {
    System.print("\n%(names[player])")
    System.print("  Your total score is currently %(totals[player])")
    var score = 0
    while (true) {
        var rh = Str.lower(Input.option("  Roll or Hold r/h : ", "rhRH"))
        if (rh == "h") {
            totals[player] = totals[player] + score
            System.print("  Your total score is now %(totals[player])")
            if (totals[player] >= 100) {
                System.print("  So, %(names[player]), YOU'VE WON!")
                return
            }
            player = (player == 0) ? 1 : 0
            break
        }
        var dice = r.int(1, 7)
        System.print("    You have thrown a %(dice)")
        if (dice == 1) {
            System.print("    Sorry, your score for this round is now 0")
            System.print("  Your total score remains at %(totals[player])")
            player = (player == 0) ? 1 : 0
            break
        }
        score = score + dice
        System.print("    Your score for the round is now %(score)")
    }
}