-- Nome file: poker.adb; -- Autore: Samuel Ribi; -- Data creazione: 22.3.2001; -- Data ultima modifica: 30.3.2001; -- Versione: 2.0; -- Scopo: Distribuisce 5 carte a 4 giocatori; -- Scritto con: Text Editor su Unix, pcGrasp su Windows ME, AdaGide su Windows NT. with Ada.Text_Io, Ada.Integer_Text_Io, Ada.Numerics.Discrete_Random; use Ada.Text_Io, Ada.Integer_Text_Io; procedure Poker1 is subtype Carta_T is Integer range 1 .. 52; package Random_Carta is new Ada.Numerics.Discrete_Random (Carta_T); use Random_Carta; Ncarte : constant Integer := 20; G : Generator; Carta : Integer; Vcarta : array(1..Ncarte) of Integer := (others => 0); poker_file : FILE_TYPE; function Ctrl_Carta(Carta , Index : Integer) return Boolean is begin for I in 1..Index loop if Vcarta(I) = Carta then return False; end if; end loop; Vcarta(Index) := Carta; return True; end Ctrl_Carta; procedure Put is Seme : Integer; begin Create(poker_file, out_file, "poker.txt"); set_output(poker_file); for I in 1..Ncarte loop Seme := (Vcarta(I) + 12) / 13; Carta := Vcarta(I) mod 13; case Carta is --when 1 => Put("A "); --when 11 => Put("J "); --when 12 => Put("Q "); when 0 => Put(13, width => 0); Put(" "); when others => Put(Carta, width => 0); Put(" "); end case; case Seme is when 1 => Put("Fiori"); when 2 => Put("Picche"); when 3 => Put("Cuori"); when 4 => Put("Quadri"); when others => null; end case; if i mod 5 = 0 then New_Line; else Put(" "); end if; end loop; end Put; begin for I in 1..Ncarte loop loop Reset (G); Carta := Random(G); exit when Ctrl_Carta(Carta,I); end loop; end loop; Put; end Poker1;