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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pig the dice game step by step in the Yabasic 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 Yabasic programming language

Source code in the yabasic programming language

numjugadores = 2
maxpuntos = 100
dim	almacenpuntos(3)
almacenpuntos(1) = 1
almacenpuntos(2) = 1

clear screen
print "The game of PIG"
print "===============", chr$(13), chr$(10)
print "Si jugador saca un 1, no anota nada y se convierte en el turno del oponente."
print "Si jugador saca 2-6, se agrega al total del turno y su turno continúa."
print "Si jugador elige 'mantener', su total de puntos se añade a su puntuación,";
print " y se convierte en el turno del siguiente jugador.", chr$(10)
print "El primer jugador en anotar 100 o más puntos gana.", chr$(13), chr$(10)

repeat
  for jugador = 1 to 2 //numjugadores
    puntos = 0

    while almacenpuntos(jugador) <= maxpuntos
      print "\nJugador ", jugador, ": (", almacenpuntos(jugador), ",", puntos, ")";
      input "  Tirada? (Sn) " nuevotiro$
      if upper$(nuevotiro$) = "S" then
        tirada = int(ran(5)) + 1
        print "  Tirada:", tirada
        if tirada = 1 then
          print chr$(10), "¡Pierdes tu turno! jugador ", jugador;
          print " pero mantienes tu puntuación anterior de ", almacenpuntos(jugador)
          break
        fi
        puntos = puntos + tirada
      else
        almacenpuntos(jugador) = almacenpuntos(jugador) + puntos
        print "  Te quedas con: ", almacenpuntos(jugador)
        if almacenpuntos(jugador) >= maxpuntos then
          print chr$(10), "Gana el Jugador ", jugador, " con ", almacenpuntos(jugador), " puntos."
          end
        fi
        break
      fi
    wend
  next jugador
until false


  

You may also check:How to resolve the algorithm Associative array/Creation step by step in the EMal programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Lingo programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the ColdFusion programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the Wren programming language