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,107 +0,0 @@
with Ada.Text_IO; with Ada.Numerics.Float_Random;
procedure Rock_Paper_Scissors is
package Rand renames Ada.Numerics.Float_Random;
Gen: Rand.Generator;
type Choice is (Rock, Paper, Scissors);
Cnt: array (Choice) of Natural := (1, 1, 1);
-- for the initialization: pretend that each of Rock, Paper,
-- and Scissors, has been played once by the human
-- else the first computer choice would be deterministic
function Computer_Choice return Choice is
Random_Number: Natural :=
Integer(Rand.Random(Gen)
* (Float(Cnt(Rock)) + Float(Cnt(Paper)) + Float(Cnt(Scissors))));
begin
if Random_Number < Cnt(Rock) then
-- guess the human will choose Rock
return Paper;
elsif Random_Number - Cnt(Rock) < Cnt(Paper) then
-- guess the human will choose Paper
return Scissors;
else -- guess the human will choose Scissors
return Rock;
end if;
end Computer_Choice;
Finish_The_Game: exception;
function Human_Choice return Choice is
Done: Boolean := False;
T: constant String
:= "enter ""r"" for Rock, ""p"" for Paper, or ""s"" for Scissors""!";
U: constant String
:= "or enter ""q"" to Quit the game";
Result: Choice;
begin
Ada.Text_IO.Put_Line(T);
Ada.Text_IO.Put_Line(U);
while not Done loop
Done := True;
declare
S: String := Ada.Text_IO.Get_Line;
begin
if S="r" or S="R" then
Result := Rock;
elsif S="p" or S = "P" then
Result := Paper;
elsif S="s" or S="S" then
Result := Scissors;
elsif S="q" or S="Q" then
raise Finish_The_Game;
else
Done := False;
end if;
end;
end loop;
return Result;
end Human_Choice;
type Result is (Human_Wins, Draw, Computer_Wins);
function "<" (X, Y: Choice) return Boolean is
-- X < Y if X looses against Y
begin
case X is
when Rock => return (Y = Paper);
when Paper => return (Y = Scissors);
when Scissors => return (Y = Rock);
end case;
end "<";
Score: array(Result) of Natural := (0, 0, 0);
C,H: Choice;
Res: Result;
begin
-- play the game
loop
C := Computer_Choice; -- the computer makes its choice first
H := Human_Choice; -- now ask the player for his/her choice
Cnt(H) := Cnt(H) + 1; -- update the counts for the AI
if C < H then
Res := Human_Wins;
elsif H < C then
Res := Computer_Wins;
else
Res := Draw;
end if;
Ada.Text_IO.Put_Line("COMPUTER'S CHOICE: " & Choice'Image(C)
& " RESULT: " & Result'Image(Res));
Ada.Text_IO.New_Line;
Score(Res) := Score(Res) + 1;
end loop;
exception
when Finish_The_Game =>
Ada.Text_IO.New_Line;
for R in Score'Range loop
Ada.Text_IO.Put_Line(Result'Image(R) & Natural'Image(Score(R)));
end loop;
end Rock_Paper_Scissors;

View file

@ -1,92 +0,0 @@
RPS()
Func RPS()
Local $ai_Played_games[4]
$ai_Played_games[0] = 3
For $I = 1 To 3
$ai_Played_games[$I] = 1
Next
$RPS = GUICreate("Rock Paper Scissors", 338, 108, 292, 248)
$Rock = GUICtrlCreateButton("Rock", 8, 8, 113, 25, 131072)
$Paper = GUICtrlCreateButton("Paper", 8, 40, 113, 25, 131072)
$Scissors = GUICtrlCreateButton("Scissors", 8, 72, 113, 25, 131072)
$Label1 = GUICtrlCreateLabel("W:", 136, 8, 18, 17)
$Wins = GUICtrlCreateLabel("0", 160, 8, 36, 17)
$Label3 = GUICtrlCreateLabel("L:", 208, 8, 13, 17)
$Looses = GUICtrlCreateLabel("0", 224, 8, 36, 17)
$Label5 = GUICtrlCreateLabel("D:", 272, 8, 15, 17)
$Deuce = GUICtrlCreateLabel("0", 296, 8, 36, 17)
$Displaybutton = GUICtrlCreateButton("", 136, 48, 193, 49, 131072)
GUICtrlSetState($ai_Played_games, 128)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Rock
$Ret = _RPS_Eval(1, $ai_Played_games)
GUICtrlSetData($Displaybutton, $Ret)
If $Ret = "Deuce" Then
GUICtrlSetData($Deuce, Guictrlread($Deuce)+1)
Elseif $Ret = "You Loose" Then
GUICtrlSetData($Looses, Guictrlread($Looses)+1)
Elseif $Ret = "You Win" Then
GUICtrlSetData($Wins, Guictrlread($Wins)+1)
EndIf
Case $Paper
$Ret = _RPS_Eval(2, $ai_Played_games)
GUICtrlSetData($Displaybutton, $Ret)
If $Ret = "Deuce" Then
GUICtrlSetData($Deuce, Guictrlread($Deuce)+1)
Elseif $Ret = "You Loose" Then
GUICtrlSetData($Looses, Guictrlread($Looses)+1)
Elseif $Ret = "You Win" Then
GUICtrlSetData($Wins, Guictrlread($Wins)+1)
EndIf
Case $Scissors
$Ret = _RPS_Eval(3, $ai_Played_games)
GUICtrlSetData($Displaybutton, $Ret)
If $Ret = "Deuce" Then
GUICtrlSetData($Deuce, Guictrlread($Deuce)+1)
Elseif $Ret = "You Loose" Then
GUICtrlSetData($Looses, Guictrlread($Looses)+1)
Elseif $Ret = "You Win" Then
GUICtrlSetData($Wins, Guictrlread($Wins)+1)
EndIf
EndSwitch
WEnd
EndFunc ;==>RPS
Func _RPS_Eval($i_Player_Choose, $ai_Played_games)
Local $i_choice = 1
$i_rnd = Random(1, 1000, 1)
$i_choose_1 = ($ai_Played_games[1] / $ai_Played_games[0] * 1000)
$i_choose_2 = ($ai_Played_games[2] / $ai_Played_games[0] * 1000)
$i_choose_3 = ($ai_Played_games[3] / $ai_Played_games[0] * 1000)
If $i_rnd < $i_choose_1 Then
$i_choice = 2
ElseIf $i_rnd < $i_choose_1 + $i_choose_2 And $i_rnd > $i_choose_1 Then
$i_choice = 3
ElseIf $i_rnd < $i_choose_1 + $i_choose_2 + $i_choose_3 And $i_rnd > $i_choose_1 + $i_choose_2 Then
$i_choice = 1
EndIf
$ai_Played_games[0] += 1
If $i_Player_Choose = 1 Then
$ai_Played_games[1] += 1
If $i_choice = 1 Then Return "Deuce"
If $i_choice = 2 Then Return "You Loose"
If $i_choice = 3 Then Return "You Win"
ElseIf $i_Player_Choose = 2 Then
$ai_Played_games[2] += 1
If $i_choice = 2 Then Return "Deuce"
If $i_choice = 3 Then Return "You Loose"
If $i_choice = 1 Then Return "You Win"
ElseIf $i_Player_Choose = 3 Then
$ai_Played_games[3] += 1
If $i_choice = 3 Then Return "Deuce"
If $i_choice = 1 Then Return "You Loose"
If $i_choice = 2 Then Return "You Win"
EndIf
EndFunc ;==>_RPS_Eval

View file

@ -1,50 +0,0 @@
function weighted_rand(sequence table)
integer sum,r
sum = 0
for i = 1 to length(table) do
sum += table[i]
end for
r = rand(sum)
for i = 1 to length(table)-1 do
r -= table[i]
if r <= 0 then
return i
end if
end for
return length(table)
end function
constant names = { "Rock", "Paper", "Scissors" }
constant winner = { "We tied.", "Meself winned.", "You win." }
integer user_action, my_action, key, win
sequence user_rec, score
user_rec = {1,1,1}
score = {0,0}
while 1 do
my_action = remainder(weighted_rand(user_rec)+1,3)+1
puts(1,"Your choice [1-3]:\n")
puts(1," 1. Rock\n 2. Paper\n 3. Scissors\n> ")
key = -1
while (key < '1' or key > '3') and key != 'q' do
key = get_key()
end while
puts(1,key)
puts(1,'\n')
if key = 'q' then
exit
end if
user_action = key-'0'
win = remainder(my_action-user_action+3,3)
printf(1,"You chose %s; I chose %s. %s\n",
{ names[user_action],
names[my_action],
winner[win+1] })
if win then
score[win] += 1
end if
printf(1,"\nScore %d:%d\n",score)
user_rec[user_action] += 1
end while