Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,23 +0,0 @@
package Pig is
type Dice_Score is range 1 .. 6;
type Player is tagged private;
function Recent(P: Player) return Natural;
function All_Recent(P: Player) return Natural;
function Score(P: Player) return Natural;
type Actor is abstract tagged null record;
function Roll_More(A: Actor; Self, Opponent: Player'Class)
return Boolean is abstract;
procedure Play(First, Second: Actor'Class; First_Wins: out Boolean);
private
type Player is tagged record
Score: Natural := 0;
All_Recent: Natural := 0;
Recent_Roll: Dice_Score := 1;
end record;
end Pig;

View file

@ -1,51 +0,0 @@
with Ada.Numerics.Discrete_Random;
package body Pig is
function Score(P: Player) return Natural is (P.Score);
function All_Recent(P: Player) return Natural is (P.All_Recent);
function Recent(P: Player) return Natural is (Natural(P.Recent_Roll));
function Has_Won(P: Player) return Boolean is (P.Score >= 100);
package RND is new Ada.Numerics.Discrete_Random(Dice_Score);
Gen: RND.Generator;
procedure Roll(P: in out Player) is
begin
P.Recent_Roll := RND.Random(Gen);
if P.Recent = 1 then
P.All_Recent := 0;
else
P.All_Recent := P.All_Recent + P.Recent;
end if;
end Roll;
procedure Add_To_Score(P: in out Player) is
begin
P.Score := P.Score + P.All_Recent;
P.All_Recent := 0;
end Add_To_Score;
procedure Play(First, Second: Actor'Class;
First_Wins: out Boolean) is
P1, P2: Player;
begin
loop
Roll(P1);
while First.Roll_More(P1, P2) and then P1.Recent > 1 loop
Roll(P1);
end loop;
Add_To_Score(P1);
exit when P1.Score >= 100;
Roll(P2);
while Second.Roll_More(P2, P1) and then P2.Recent > 1 loop
Roll(P2);
end loop;
Add_To_Score(P2);
exit when P2.Score >= 100;
end loop;
First_Wins := P1.Score >= 100;
end Play;
begin
RND.Reset(Gen);
end Pig;

View file

@ -1,32 +0,0 @@
with Pig, Ada.Text_IO;
procedure Play_Pig is
use Pig;
type Hand is new Actor with record
Name: String(1 .. 5);
end record;
function Roll_More(A: Hand; Self, Opponent: Player'Class) return Boolean;
function Roll_More(A: Hand; Self, Opponent: Player'Class) return Boolean is
Ch: Character := ' ';
use Ada.Text_IO;
begin
Put(A.Name & " you:" & Natural'Image(Self.Score) &
" (opponent:" & Natural'Image(Opponent.Score) &
") this round:" & Natural'Image(Self.All_Recent) &
" this roll:" & Natural'Image(Self.Recent) &
"; add to score(+)?");
Get(Ch);
return Ch /= '+';
end Roll_More;
A1: Hand := (Name => "Alice");
A2: Hand := (Name => "Bob ");
Alice: Boolean;
begin
Play(A1, A2, Alice);
Ada.Text_IO.Put_Line("Winner = " & (if Alice then "Alice!" else "Bob!"));
end Play_Pig;