Ada_S2/TD_R_LACROIX_ENG_06-01-2020.adb

308 lines
No EOL
14 KiB
Ada

-- //shall we play a game?
with Fiche_Plongee, Capteurs, Gada.Text_IO;
use Fiche_Plongee, Capteurs, Gada.Text_IO;
-- // 01000011 01100101 00100000 01110100 01100101 01111000 01110100 01100101 00100000 01100101 01110011 01110100 00100000 01100101 01101110 00100000 01100010 01101001 01101110 01100001 01101001 01110010 01100101
-- // .- -. -.. / - .... .. ... / --- -. . / .. ... / .. -. / -- --- .-. ... . / -.-. --- -.. .
procedure td is
-- TD 2
function Effectif_Palanquee(Table: T_Palanq) return Integer is
I : Integer := 1; -- to go through the table
Counter : Integer := 0; -- the final value
begin
for I in 1 .. Max_Plongeurs loop
if Table.Plongeurs(I).Present then
Counter := Counter + 1;
end if;
end loop;
return Counter;
end Effectif_Palanquee;
-- //Wake up Neo
function Effectif_Fiche(Table: T_Fiche_Secu) return Integer is
I : Integer := 0; -- to go through the table
J : Integer := 0; -- to go through the table
Counter : Integer := 0; -- the final value
begin
for I in 1 .. Table.NB_Palanquees loop -- welook at all the palanquees
for J in 1 .. Max_Plongeurs loop -- then we look at all the plongeurs in the palanquee
if Table.Tab_Palanquees(I).Plongeurs(J).Present then -- if they are present
Counter := Counter+1; -- we increment the counter
end if;
end loop;
end loop;
return Counter;
end Effectif_Fiche;
-- //the matrix has you
function Est_Plongee_Technique(Palanq : T_Palanq) return Boolean is
I : Integer := 1; -- to go through the table
Teacher : Integer := 0; -- to store the number of teachers
Student : Integer := 0; -- to store the number of students
Other : Integer := 0; -- to store the number of plongeurs that are neither student nor teachers
begin
for I in 0 .. Max_Plongeurs loop -- we go through the palanquee
if Palanq.Plongeurs(I).Present then -- we check if the plongeur is present
if Palanq.Plongeurs(I).Role = Ens then -- if he is present and is a teacher we increment teacher
Teacher := Teacher + 1;
elsif Palanq.Plongeurs(I).Role = Eleve then -- if he is present and is a student we increment student
Student := Student + 1;
else -- if he is present and is neither a teacher nor a student we increment other
Other := Other + 1;
end if;
end if;
end loop;
return (Teacher = 1 and Other = 0 and (Student > 0 and Student < 5)); -- we return the value taken by the condition
end Est_Plongee_Technique;
-- //follow the white rabbit
function Numero_Premiere_Technique(Fiche : T_Fiche_Secu) return Integer is
I : Integer := 1; -- to go through the table
Tech : Boolean := Est_Plongee_Technique(Fiche.Tab_Palanquees(I)); -- we initialize this as the very first entry of the table
begin
while (not Tech) loop -- while our plongee is not technique we keep on looking at the next entry
I := I + 1; -- I miss the i++ so bad
Tech := Est_Plongee_Technique(Fiche.Tab_Palanquees(I)); -- we take the value of whether the Ith plongee is technique
end loop;
return I;
end Numero_Premiere_Technique;
-- //the two that are one will become the one that is all
function Durees_Fiche_OK(Fiche: T_Fiche_Secu) return Boolean is
I : Integer := 1; -- to go through the table
Good : Boolean := True; -- if it stays good all along then it's good else it's not
begin
for I in 1 .. Fiche.NB_Palanquees loop
if Fiche.Tab_Palanquees(I).Duree_Reelle_Fond >= Fiche.Temps_Plongee_Max_Autorise then -- if the length of the plongee was greater than the authorized time we set good to false
Good := False; -- therefore as soon as there is one palanquee that got past the limit it is and will remain false
end if;
end loop;
return Good;
end Durees_Fiche_OK;
-- //Do you know about Twitch Prime?
function Profondeur_Max(Table: T_palanq) return Integer is
I : Integer := 0; -- to go through the table
Max : Integer := 0; -- to be returned
begin
for I in 0 .. Max_Plongeurs loop
if Table.Plongeurs(I).Profondeur_Max_Autorisee < Max then -- it's smaller than because if smone can't go further it becomes the new maximum allowed
Max := Table.Plongeurs(I).Profondeur_Max_Autorisee;
end if;
end loop;
return I;
end Profondeur_Max;
-- //Ash nazg durbatulûk, ash nazg gimbatul, ash nazg thrakatulûk, agh burzum-ishi krimpatul
function Profondeur_Fiche_OK(Fiche: T_Fiche_Secu) return Boolean is
I : Integer := 1; -- to go through the table
Good : Boolean := True; -- to be returned
begin
for I in 1 .. Fiche.NB_Palanquees loop
if Fiche.Tab_Palanquees(I).Profondeur_Reelle >= Profondeur_Max(Fiche.Tab_Palanquees(I)) then -- if the length of the plongee was greater than the authorized time we set good to false
Good := False; -- therefore as soon as there is one palanquee that got past the limit it is and will remain false
end if;
end loop;
return Good;
end Profondeur_Fiche_OK;
-- //The answer to the question of the universe life and everything is ... 42
-- TD 3
-- Q1: exmample of events:
--the race starts and the guys jumps
-- (Signal_Feu:32400.0)
-- (Plot,2,32400.8)
-- (Plot,3,32400.9)
-- (Plot,1,32401.2)
-- (Sud,3,32420.8)
-- (Sud,2,32421.8)
-- (Sud,2,32421.85) -- note there was an error here because of the capteur's bug
-- (Sud,2,32421.90)
-- (Sud,1,32423.8)
-- (Nord,3,32440.8)
-- (Nord,2,32441.8)
-- (Nord,1,32443.8)
-- (Sud,3,32460.8)
-- (Sud,2,32461.8)
-- (Sud,1,32463.8)
-- (Nord,3,32480.8)
-- (Bouton_Fin,32480.9)
-- (Nord,2,32481.8)
-- (Nord,1,32483.8)
-- //Roads? where we go we don't need roads
procedure Course is
Temp: Float := 0.0; -- there to store a value
Rank: Integer := 0;
Sorted: Boolean := False; -- there to store the state of sorting of the array at the end
J : Integer := 0;-- there to increment
I : Integer := 0;-- there to increment
NB_Swimmer: Integer := 8; -- could be more;
Running : Boolean:= True;
Event : T_Evenement;
TDepart : Float := 0.0; -- the time of the start of the race
type T_TableTime is array (1..NB_Swimmer, 1..4) of Float; --time of the nth swimmer at 1: Start, 2:50 m, 3 finish, 4, the last time it reached a Nord base
type T_TableNum is array (1..NB_Swimmer) of Integer; -- number of times the nth swimmer did a 50m
type T_TableArr is array (1..NB_Swimmer) of Float; -- time at which the awimmer arrives
TableTime: T_TableTime := (others => (others => 0.0));
TableNum : T_TableNum := (others => 0);
Arrival : T_TableArr := (others => 0.0);
begin
while Running loop
Event := Attend_Signal;
if Event.Emetteur = Signal_Feu then
TDepart := Event.Date; -- We stock the first value to have the time of the swimmers
elsif Event.Emetteur = Capteur_Plot then
if Event.Date - TDepart < 0.1 then -- it is a false start: https://en.wikipedia.org/wiki/False_start
Running := False; -- we stop the race
Put_Line("False start at line" & Integer'Image(Event.Num));
else
TableTime(Event.Num, 1) := Event.Date; -- starting value
TableTime(Event.Num, 4) := Event.Date; -- Last value
end if;
elsif (Event.Emetteur = Capteur_Nord and (Event.Date - TableTime(Event.Num, 4) > 5.0)) then -- it's hard to do 50m in less than 5 seconds
if TableNum(Event.Num) = 0 then
TableTime(Event.Num, 2) := Event.Date; -- we store the value at the first 50 m
TableNum(Event.Num) := TableNum(Event.Num) + 1; -- we increment the numer of runs
elsif TableNum(Event.Num) = 15 then -- it means he's finishing his last run
TableTime(Event.Num, 3) := Event.Date; -- we store the arrival's date
end if;
elsif Event.Emetteur = Bouton_Fin then -- the director of the race stopped it (probably saw someone arrive)
Running := False;
end if;
End loop;
-- we store the times of arrival
for I in 1 .. NB_Swimmer loop
Arrival(I) := TableTime(I, 3);
end loop;
-- We order the table:
while not Sorted loop
for I in 1 .. NB_Swimmer-1 loop -- for every value if it is greater than the next one we swop them
if Arrival(I) > Arrival(I + 1) then
Temp := Arrival(I); -- there to store a value
Arrival(I) := Arrival(I + 1);
Arrival(I + 1) := Temp;
Temp := 0.0; --reset
end if;
end loop;
-- //I Lost (https://en.wikipedia.org/wiki/The_Game_(mind_game))
--here we check for if it's sorted (if not we give it another go)
Sorted := True; --it starts true
for I in 1 .. NB_Swimmer-1 loop
if Arrival(I) > Arrival(I + 1) then -- if a value is greater than the next one (as it's not supposed to be)
Sorted := False; -- we set the sorted value to false
end if;
end loop;
end loop;
-- //really intersting: https://www.youtube.com/watch?v=ub82Xb1C8os
--we then print out the lines
for I in 1 .. NB_Swimmer loop
J := 0;
while (Arrival(I) /= TableTime(J, 3)) loop
J := J + 1;
end loop;
Put_Line("Swimmer " & Integer'Image(J) & " arrived in place " & Integer'Image(I) & " with a time of " & Float'Image(Arrival(I)-TDepart));
end loop;
end Course;
-- //It is the nature of human kind to push itself towards the horyzon, we test our limits,
-- //we face our fears, we rise to the challenge, and become something greater than ourselves,
-- //a civilization.
begin
Put_Line("42");
-- As we do not have usable numerical data I did not do numerical testes :/
end td;
-- //subscribe to pewdiepie, or don't this craze is over anyway
--
--
--
--
--
--
--
-- *((((((((. ,(((((((((, .(((((((/ ./(########(/, *((((((((((* ,#####*
-- *########. *#########( .#######( .(################(. .############. (#%%%*
-- *########. *##########/ .#######( *########/**(#######(. /############( .%%%#*
-- *########. *###########, .(######( (#######, /#######* ,######((######, *%%%*
-- *########. *############. .(######( .(#######(, (######,,######( #%%*
-- *########. *############/ .(######( /###########(* /######( (######* *%%*
-- *########. *#######/*####,.(######( *################* .#######* *#######. (#*
-- *########. *#######* (###(,(######( ./###############( (#######. .(######/ .#*
-- *########. *#######* .(###(#######( .*(##########(. ,#######/....(#(#####* /*
-- *########. *#######* *###########( . .(########* #####################( *
-- *########. *#######* (##########( ,#######(. *########,*######################*
-- *########. *#######* ##########( .(########(*/(########(,(#######* .*########,
-- *########. *#######* ,#########( .(##################* /#######(. .########(
-- ,((((((((. ,(((((((* *((((((((/ .*((##(#####(*. .((((((((* /((((((((*
--
--
-- ,#, (# (# ,#**%, #( *#.*#. #/.#, ##./, *#.
-- ,#, (( (#.,%*,#, #( *%.*#. #/.#* ./#/ *#..
-- .*. */* ,//, **** ,//. .*/, .//* ,***,
--
-- suposed to be "To Lose" or something of that vibe
--
--
--
--
--