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


pig := proc()
	local Points, pointsThisTurn, answer, rollNum, i, win;
	randomize();
	Points := [0, 0];
	win := [false, 0];
	while not win[1] do
		for i to 2 do
			if not win[1] then
				printf("Player %a's turn.\n", i);
				answer := "";
				pointsThisTurn := 0;
				while not answer = "HOLD" do
					while not answer = "ROLL" and not answer = "HOLD" do
						printf("Would you like to ROLL or HOLD?\n");
						answer := StringTools:-UpperCase(readline());
						if not answer = "ROLL" and not answer = "HOLD" then
							printf("Invalid answer.\n\n");
						end if;
					end do;
					if answer = "ROLL" then
						rollNum := rand(1..6)();
						printf("You rolled a %a!\n", rollNum);
						if rollNum = 1 then
							pointsThisTurn := 0;
							answer := "HOLD";
						else
							pointsThisTurn := pointsThisTurn + rollNum;
							answer := "";
							printf("Your points so far this turn: %a.\n\n", pointsThisTurn);
						end if;
					end if;
				end do;
				printf("This turn is over! Player %a gained %a points this turn.\n\n", i, pointsThisTurn);
				Points[i] := Points[i] + pointsThisTurn;
				if Points[i] >= 100 then
					win := [true, i];
				end if;
				printf("Player 1 has %a points. Player 2 has %a points.\n\n", Points[1], Points[2]);
			end if;
		end do;
	end do;
	printf("Player %a won with %a points!\n", win[2], Points[win[2]]);
end proc;
 
pig();