text
stringlengths
0
234
end if;
Nodes.Insert ((Array_Height, Column), Last);
end loop Create_Horizontal_Tiles;
Function Definition: procedure Main is
Function Body: use Ada.Text_IO;
use Utils;
package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);
use Integer_Vectors;
subtype Hegihtmap_Values is Natural range 0 .. 10;
subtype Hegiht is Hegihtmap_Values range 0 .. 9;
type Cave_Heightmap_Array is array (Natural range <>, Natural range <>) of Hegihtmap_Values;
File : File_Type;
Values : Vector := Empty_Vector;
Array_Width,
Array_Height : Natural := Natural'First;
begin
Get_File (File);
-- Get all values
while not End_Of_File (File) loop
Array_Height := Array_Height + 1;
declare
Str : constant String := Get_Line (File);
Value : Hegiht;
Last : Positive;
begin
if Array_Width = Natural'First then
Array_Width := Str'Length;
end if;
for Char of Str loop
Ada.Integer_Text_IO.Get (Char & "", Value, Last);
Values.Append (Value);
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
package Integer_Vectors is new Ada.Containers.Vectors (Natural, Natural);
use Integer_Vectors;
subtype Hegihtmap_Values is Natural range 0 .. 10;
subtype Hegiht is Hegihtmap_Values range 0 .. 9;
type Cave_Heightmap_Array is array (Natural range <>, Natural range <>) of Hegihtmap_Values;
type Location is record
Line : Natural;
Column : Natural;
end record;
subtype Adjacent_Index is Integer range -1 .. 1;
type Adjacent_Location is record
Line : Adjacent_Index;
Column : Adjacent_Index;
end record;
type Adjacent is (Top, Right, Bottom, Left);
type Adjacent_Array is array (Adjacent) of Adjacent_Location;
-- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.
-- @param Loc A 2 dimensional location
-- @returns Return the corresponding hash
-- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function
function Hash (Loc : Location) return Ada.Containers.Hash_Type is
(Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column));
function Is_Equal (Loc_1, Loc_2 : Location) return Boolean is
(Loc_1.Line = Loc_2.Line and Loc_1.Column = Loc_2.Column);
package Location_Sets is new Ada.Containers.Hashed_Sets (Element_Type => Location,
Hash => Hash,
Equivalent_Elements => Is_Equal,
"=" => Is_Equal);
Adjacents : constant Adjacent_Array := (Top => (-1, 0),
Right => (0, 1),
Bottom => (1, 0),
Left => (0, -1));
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Values : Vector := Empty_Vector;
Array_Width,
Array_Height : Natural := Natural'First;
begin
Get_File (File);
-- Get all values
while not End_Of_File (File) loop
Array_Height := Array_Height + 1;
declare