How to resolve the algorithm Pig the dice game/Player step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pig the dice game/Player step by step in the Ada programming language
Table of Contents
Problem Statement
Create a dice simulator and scorer of Pig the dice game and add to it the ability to play the game to at least one strategy.
As a stretch goal:
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
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pig the dice game/Player step by step in the Ada programming language
Source code in the ada programming language
with Pig; with Ada.Text_IO; with Ada.Command_Line;
procedure automatic_Pig is
use Pig;
type Robot is new Actor with record
Bound: Natural := 20;
Final_Run: Natural := 0;
end record;
function Roll_More(A: Robot; Self, Opponent: Player'Class) return Boolean;
function Roll_More(A: Robot; Self, Opponent: Player'Class) return Boolean is
((Self.All_Recent < A.Bound) or
else (Opponent.Score-100 > A.Final_Run));
function Arg(Position: Positive; Default: Natural) return Natural is
package ACL renames Ada.Command_Line;
begin
return Natural'Value(ACL.Argument(Position));
exception
when Constraint_Error => return Default;
end Arg;
T: Robot := (Bound => Arg(2, 35), Final_Run => Arg(3, 0));
F: Robot := (Bound => Arg(4, 20), Final_Run => Arg(5, 30));
T_Wins: Boolean;
Win_Count: array(Boolean) of Natural := (True=> 0, False => 0);
begin
for I in 1 .. Arg(1, 1000) loop
Play(T, F, T_Wins);
Win_Count(T_Wins) := Win_Count(T_Wins) + 1;
end loop;
Ada.Text_IO.Put_Line(Natural'Image(Win_Count(True)) &
Natural'Image(Win_Count(False)));
end Automatic_Pig;
You may also check:How to resolve the algorithm Boolean values step by step in the Clean programming language
You may also check:How to resolve the algorithm Archimedean spiral step by step in the J programming language
You may also check:How to resolve the algorithm Magic squares of odd order step by step in the Perl programming language
You may also check:How to resolve the algorithm String case step by step in the F# programming language
You may also check:How to resolve the algorithm Sum and product puzzle step by step in the ooRexx programming language