-- This program is the last attempt of artificial intelligency with Ada.
-- Elhoim is Copyright (C) 2023 Manuel ; 
--
--   <one line to give the program's name and a brief idea of what it does.>
--   Copyright (C) 19yy  <name of author>
--
--   This program is free software; you can redistribute it and/or modify
--   it under the terms of the GNU General Public License as published by
--   the Free Software Foundation; either version 2 of the License, or
--   (at your option) any later version.
--
--   This program is distributed in the hope that it will be useful,
--   but WITHOUT ANY WARRANTY; without even the implied warranty of
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--   GNU General Public License for more details.
--
--   You should have received a copy of the GNU General Public License
--   along with this program; if not, write to the Free Software
--   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
--
-- Date := "2023-05-01 20:03:01"
-- Version := "1.0.0a"
package body Lib is

   function To_String (Version : in Version_Record) return String is
      
      Major_Word : constant String :=
	Major_Range'Image(Version.Major)(2..Major_Range'Image(Version.Major)'Length);
      Minor_Word : constant String :=
	Minor_Range'Image(Version.Minor)(2..Minor_Range'Image(Version.Minor)'Length);
      Revision_Word : constant String :=
	Revision_Range'Image(Version.Revision)(2..Revision_Range'Image(Version.Revision)'Length);      
   begin
      
      return Major_Word & '.' & Minor_Word & '.' & Revision_Word & Character'Value(Release_Enum'Image(Version.Release));
   end To_String;
   
   
   
   procedure Permute (Left, Right : in out Ranked_Class) is
      Buffer : Ranked_Class;
   begin
      Buffer := Left;
      Left := Right;
      Right := Buffer;
   end Permute;
   
   procedure Sort_Init (Top_Classes : access Rank_Array) is
      Sum_Left    : Float := 0.0;
      Sum_Right    : Float := 0.0;      
   begin
      for Iter_A in 1..Top_Classes'Length - 1 loop
	 for Iter_B in 1..(Top_Classes'Length - Iter_A) loop
	    Sum_Left := Top_Classes(Iter_B).Hcost + Top_Classes(Iter_B).Ucost;
	    Sum_Right := Top_Classes(Iter_B + 1).Hcost + Top_Classes(Iter_B + 1).Ucost;
	    if Sum_Left < Sum_right then
	       Permute(Top_Classes(Iter_B).all, Top_Classes(Iter_B + 1).all);
	    end if;
	 end loop;
      end loop;
   end Sort_Init;
   
   
   procedure Class_Ranking_Init(Top_Classes : access Rank_Array) is
      
      New_Object : access Ranked_Class;
      
   begin
      for Name in Tag_Name'Pos(Tag_Name'First) + 1 .. Tag_Name'Pos(Tag_Name'Last) loop
	 New_Object := new Ranked_Class;
	 Abstract_Object(New_Object.all) := Default_Ranking(Tag_Name'Val(Name));
	 Top_Classes(Name) := New_Object;
      end loop;      
   end Class_Ranking_Init;
   
end Lib ;