How to resolve the algorithm Pig the dice game step by step in the Run BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pig the dice game step by step in the Run BASIC programming language

Table of Contents

Problem Statement

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:

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pig the dice game step by step in the Run BASIC programming language

Source code in the run programming language

numPlayers	= 2
maxScore 	= 100
dim	safeScore(numPlayers)

[loop]
for player = 1 to numPlayers
  score     = 0

  while safeScore(player) < maxScore
   input "Player ";player;" Rolling? (Y) ";rolling$
    if upper$(rolling$) = "Y" then
        rolled = int(rnd(0) * 5) + 1
        print "Player ";player;" rolled ";rolled
        if rolled = 1 then
            print "Bust! you lose player ";player;" but still keep your previous score of ";safeScore(plater)
            exit while
        end if
        score = score + rolled
    else
        safeScore(player) = safeScore(player) + score
    end if
  wend
next player
goto [loop]
[winner] 
print "Player ";plater;" wins with a score of ";safeScore(player)

  

You may also check:How to resolve the algorithm Binary search step by step in the Sidef programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the FALSE programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the Phix programming language
You may also check:How to resolve the algorithm Machine code step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Kolakoski sequence step by step in the Ruby programming language