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 random, strformat, strutils
 
randomize()
 
stdout.write "Player 1 - Enter your name : "
let name1 = block:
              let n = stdin.readLine().strip()
              if n.len == 0: "PLAYER 1" else: n.toUpper
stdout.write "Player 2 - Enter your name : "
let name2 = block:
              let n = stdin.readLine().strip()
              if n.len == 0: "PLAYER 2" else: n.toUpper
 
let names = [name1, name2]
var totals: array[2, Natural]
var player = 0
 
while true:
  echo &"\n{names[player]}"
  echo &"  Your total score is currently {totals[player]}"
  var score = 0
 
  while true:
    stdout.write "  Roll or Hold r/h : "
    let rh = stdin.readLine().toLowerAscii()
    case rh
 
    of "h":
      inc totals[player], score
      echo &"  Your total score is now {totals[player]}"
      if totals[player] >= 100:
        echo &"  So, {names[player]}, YOU'VE WON!"
        quit QuitSuccess
      player = 1 - player
      break
 
    of "r":
      let dice = rand(1..6)
      echo &"    You have thrown a {dice}"
      if dice == 1:
        echo "    Sorry, your score for this round is now 0"
        echo &"  Your total score remains at {totals[player]}"
        player = 1 - player
        break
      inc score, dice
      echo &"    Your score for the round is now {score}"
 
    else:
      echo "    Must be 'r' or 'h', try again"